OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 4 |
5 class StringEscapesTest { | 5 class StringEscapesTest { |
6 | 6 |
7 static testMain() { | 7 static testMain() { |
8 testDelimited(); | 8 testDelimited(); |
9 testFixed2(); | 9 testFixed2(); |
10 testFixed4(); | 10 testFixed4(); |
11 testEscapes(); | 11 testEscapes(); |
12 testLiteral(); | 12 testLiteral(); |
13 } | 13 } |
14 | 14 |
15 static testDelimited() { | 15 static testDelimited() { |
16 String str = "Foo\u{1}Bar\u{000001}Baz\u{D7FF}Boo"; | 16 String str = "Foo\u{1}Bar\u{000001}Baz\u{D7FF}Boo"; |
17 Expect.equals(15, str.length); | 17 Expect.equals(15, str.length); |
18 Expect.equals(1, str.charCodeAt(3)); | 18 Expect.equals(1, str.codeUnitAt(3)); |
19 Expect.equals(1, str.charCodeAt(7)); | 19 Expect.equals(1, str.codeUnitAt(7)); |
20 Expect.equals(0xD7FF, str.charCodeAt(11)); | 20 Expect.equals(0xD7FF, str.codeUnitAt(11)); |
21 Expect.equals('B'.charCodeAt(0), str.charCodeAt(12)); | 21 Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(12)); |
22 } | 22 } |
23 | 23 |
24 static testEscapes() { | 24 static testEscapes() { |
25 String str = "Foo\fBar\vBaz\bBoo"; | 25 String str = "Foo\fBar\vBaz\bBoo"; |
26 Expect.equals(15, str.length); | 26 Expect.equals(15, str.length); |
27 Expect.equals(12, str.charCodeAt(3)); | 27 Expect.equals(12, str.codeUnitAt(3)); |
28 Expect.equals('B'.charCodeAt(0), str.charCodeAt(4)); | 28 Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); |
29 Expect.equals(11, str.charCodeAt(7)); | 29 Expect.equals(11, str.codeUnitAt(7)); |
30 Expect.equals('z'.charCodeAt(0), str.charCodeAt(10)); | 30 Expect.equals('z'.codeUnitAt(0), str.codeUnitAt(10)); |
31 Expect.equals(8, str.charCodeAt(11)); | 31 Expect.equals(8, str.codeUnitAt(11)); |
32 Expect.equals('o'.charCodeAt(0), str.charCodeAt(14)); | 32 Expect.equals('o'.codeUnitAt(0), str.codeUnitAt(14)); |
33 str = "Abc\rDef\nGhi\tJkl"; | 33 str = "Abc\rDef\nGhi\tJkl"; |
34 Expect.equals(15, str.length); | 34 Expect.equals(15, str.length); |
35 Expect.equals(13, str.charCodeAt(3)); | 35 Expect.equals(13, str.codeUnitAt(3)); |
36 Expect.equals('D'.charCodeAt(0), str.charCodeAt(4)); | 36 Expect.equals('D'.codeUnitAt(0), str.codeUnitAt(4)); |
37 Expect.equals(10, str.charCodeAt(7)); | 37 Expect.equals(10, str.codeUnitAt(7)); |
38 Expect.equals('G'.charCodeAt(0), str.charCodeAt(8)); | 38 Expect.equals('G'.codeUnitAt(0), str.codeUnitAt(8)); |
39 Expect.equals(9, str.charCodeAt(11)); | 39 Expect.equals(9, str.codeUnitAt(11)); |
40 Expect.equals('J'.charCodeAt(0), str.charCodeAt(12)); | 40 Expect.equals('J'.codeUnitAt(0), str.codeUnitAt(12)); |
41 } | 41 } |
42 | 42 |
43 static testFixed2() { | 43 static testFixed2() { |
44 String str = "Foo\xFFBar"; | 44 String str = "Foo\xFFBar"; |
45 Expect.equals(7, str.length); | 45 Expect.equals(7, str.length); |
46 Expect.equals(255, str.charCodeAt(3)); | 46 Expect.equals(255, str.codeUnitAt(3)); |
47 Expect.equals('B'.charCodeAt(0), str.charCodeAt(4)); | 47 Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); |
48 } | 48 } |
49 | 49 |
50 static testFixed4() { | 50 static testFixed4() { |
51 String str = "Foo\u0001Bar"; | 51 String str = "Foo\u0001Bar"; |
52 Expect.equals(7, str.length); | 52 Expect.equals(7, str.length); |
53 Expect.equals(1, str.charCodeAt(3)); | 53 Expect.equals(1, str.codeUnitAt(3)); |
54 Expect.equals('B'.charCodeAt(0), str.charCodeAt(4)); | 54 Expect.equals('B'.codeUnitAt(0), str.codeUnitAt(4)); |
55 } | 55 } |
56 | 56 |
57 static testLiteral() { | 57 static testLiteral() { |
58 String str = "\a\c\d\e\g\h\i\j\k\l\$\{\}\""; | 58 String str = "\a\c\d\e\g\h\i\j\k\l\$\{\}\""; |
59 Expect.equals(r'acdeghijkl${}"', str); | 59 Expect.equals(r'acdeghijkl${}"', str); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 main() { | 63 main() { |
64 StringEscapesTest.testMain(); | 64 StringEscapesTest.testMain(); |
65 } | 65 } |
OLD | NEW |