OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart test program for testing class 'StringBase' (currently VM specific). | 4 // Dart test program for testing class 'StringBase' (currently VM specific). |
5 // We use that flag to disable privacy. | |
6 // VMOptions=--expose_core_impl | |
7 | 5 |
8 #library("StringBaseTest.dart"); | 6 #library("StringBaseTest.dart"); |
9 #import("dart:coreimpl"); | 7 #import("dart:coreimpl"); |
10 | 8 |
11 | 9 |
12 class StringBaseTest { | 10 class StringBaseTest { |
13 | 11 |
14 StringBaseTest() {} | 12 StringBaseTest() {} |
15 | 13 |
16 toString() { | 14 toString() { |
17 return "StringBase Tester"; | 15 return "StringBase Tester"; |
18 } | 16 } |
19 static testSubstringMatches() { | 17 static testSubstringMatches() { |
20 Expect.equals(true, "Hello".substringMatches(0, "Hello")); | 18 Expect.equals(true, "Hello".substringMatches(0, "Hello")); |
21 Expect.equals(true, "Hello World".substringMatches(0, "Hello")); | 19 Expect.equals(true, "Hello World".substringMatches(0, "Hello")); |
22 Expect.equals(false, "My Hello World".substringMatches(0, "Hello")); | 20 Expect.equals(false, "My Hello World".substringMatches(0, "Hello")); |
23 Expect.equals(true, "My Hello World".substringMatches(6, "lo W")); | 21 Expect.equals(true, "My Hello World".substringMatches(6, "lo W")); |
24 Expect.equals(false, "Hello".substringMatches(0, "low")); | 22 Expect.equals(false, "Hello".substringMatches(0, "low")); |
25 } | 23 } |
26 | 24 |
27 static testInterpolation() { | 25 static testInterpolation() { |
28 Expect.equals("", StringBase._interpolate([])); | |
29 Expect.equals("Hello World", | |
30 StringBase._interpolate(["Hello", " ", "World"])); | |
31 Expect.equals("Hello StringBase Tester!", | |
32 StringBase._interpolate(["Hello ", new StringBaseTest(), "!"])); | |
33 | |
34 var answer = 40 + 2; | 26 var answer = 40 + 2; |
35 var s = "The answer is $answer."; | 27 var s = "The answer is $answer."; |
36 Expect.equals("The answer is 42.", s); | 28 Expect.equals("The answer is 42.", s); |
37 | 29 |
38 int numBottles = 99; | 30 int numBottles = 33; |
39 String wall = "wall"; | 31 String wall = "wall"; |
| 32 s = "${numBottles*3} bottles of beer on the $wall."; |
| 33 Expect.equals("99 bottles of beer on the wall.", s); |
40 } | 34 } |
41 | 35 |
42 static testCreation() { | 36 static testCreation() { |
43 String s = "Hello"; | 37 String s = "Hello"; |
44 List<int> a = new List(s.length); | 38 List<int> a = new List(s.length); |
45 List<int> ga = new List(); | 39 List<int> ga = new List(); |
46 bool exception_caught = false; | 40 bool exception_caught = false; |
47 for (int i = 0; i < a.length; i++) { | 41 for (int i = 0; i < a.length; i++) { |
48 a[i] = s.charCodeAt(i); | 42 a[i] = s.charCodeAt(i); |
49 ga.add(s.charCodeAt(i)); | 43 ga.add(s.charCodeAt(i)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 testSubstringMatches(); | 85 testSubstringMatches(); |
92 testInterpolation(); | 86 testInterpolation(); |
93 testCreation(); | 87 testCreation(); |
94 testSubstring(); | 88 testSubstring(); |
95 } | 89 } |
96 } | 90 } |
97 | 91 |
98 main() { | 92 main() { |
99 StringBaseTest.testMain(); | 93 StringBaseTest.testMain(); |
100 } | 94 } |
OLD | NEW |