OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 // Dart test program for testing class 'StringBase' (currently VM specific). | |
5 | |
6 library string_base_test; | |
7 | |
8 import "package:expect/expect.dart"; | |
9 | |
10 class StringBaseTest { | |
11 StringBaseTest() {} | |
12 | |
13 toString() { | |
14 return "StringBase Tester"; | |
15 } | |
16 | |
17 static testInterpolation() { | |
18 var answer = 40 + 2; | |
19 var s = "The answer is $answer."; | |
20 Expect.equals("The answer is 42.", s); | |
21 | |
22 int numBottles = 33; | |
23 String wall = "wall"; | |
24 s = "${numBottles*3} bottles of beer on the $wall."; | |
25 Expect.equals("99 bottles of beer on the wall.", s); | |
26 } | |
27 | |
28 static testCreation() { | |
29 String s = "Hello"; | |
30 List<int> a = new List(s.length); | |
31 List<int> ga = new List(); | |
32 bool exception_caught = false; | |
33 for (int i = 0; i < a.length; i++) { | |
34 a[i] = s.codeUnitAt(i); | |
35 ga.add(s.codeUnitAt(i)); | |
36 } | |
37 try { | |
38 String s4 = new String.fromCharCodes([0.0]); | |
39 } on ArgumentError catch (ex) { | |
40 exception_caught = true; | |
41 } on TypeError catch (ex) { | |
42 exception_caught = true; | |
43 } | |
44 Expect.equals(true, exception_caught); | |
45 exception_caught = false; | |
46 try { | |
47 String s4 = new String.fromCharCodes([-1]); | |
48 } on ArgumentError catch (ex) { | |
49 exception_caught = true; | |
50 } | |
51 Expect.equals(true, exception_caught); | |
52 } | |
53 | |
54 static testSubstring() { | |
55 String s = "Hello World"; | |
56 Expect.equals("World", s.substring(6, s.length)); | |
57 Expect.equals("", s.substring(8, 8)); | |
58 bool exception_caught = false; | |
59 try { | |
60 s.substring(5, 12); | |
61 } on RangeError catch (ex) { | |
62 exception_caught = true; | |
63 } | |
64 Expect.equals(true, exception_caught); | |
65 exception_caught = false; | |
66 try { | |
67 s.substring(5, 4); | |
68 } on RangeError catch (ex) { | |
69 exception_caught = true; | |
70 } | |
71 Expect.equals(true, exception_caught); | |
72 } | |
73 | |
74 static void testMain() { | |
75 testInterpolation(); | |
76 testCreation(); | |
77 testSubstring(); | |
78 } | |
79 } | |
80 | |
81 main() { | |
82 StringBaseTest.testMain(); | |
83 } | |
OLD | NEW |