Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: tests/compiler/dart2js_extra/string_escape_test.dart

Issue 12282038: Remove deprecated string features. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Test that string escapes work correctly. 5 // Test that string escapes work correctly.
6 6
7 testSingleCharacterEscapes() { 7 testSingleCharacterEscapes() {
8 List/*<String>*/ examples = [ 8 List/*<String>*/ examples = [
9 "\b\f\n\r\t\v", 9 "\b\f\n\r\t\v",
10 '\b\f\n\r\t\v', 10 '\b\f\n\r\t\v',
11 """\b\f\n\r\t\v""", 11 """\b\f\n\r\t\v""",
12 '''\b\f\n\r\t\v''', 12 '''\b\f\n\r\t\v''',
13 ]; 13 ];
14 List values = [8, 12, 10, 13, 9, 11]; 14 List values = [8, 12, 10, 13, 9, 11];
15 for (String s in examples) { 15 for (String s in examples) {
16 Expect.equals(6, s.length); 16 Expect.equals(6, s.length);
17 for (int i = 0; i < 6; i++) { 17 for (int i = 0; i < 6; i++) {
18 Expect.equals(values[i], s.charCodeAt(i)); 18 Expect.equals(values[i], s.codeUnitAt(i));
19 } 19 }
20 } 20 }
21 21
22 // An escaped quote isn't part of a multiline end quote. 22 // An escaped quote isn't part of a multiline end quote.
23 Expect.equals(r'"', """\""""); 23 Expect.equals(r'"', """\"""");
24 Expect.equals(r"'", '''\''''); 24 Expect.equals(r"'", '''\'''');
25 Expect.equals(r'" "', """" \""""); 25 Expect.equals(r'" "', """" \"""");
26 Expect.equals(r"' '", '''' \''''); 26 Expect.equals(r"' '", '''' \'''');
27 Expect.equals(r'"" ', """"" """); 27 Expect.equals(r'"" ', """"" """);
28 Expect.equals(r"'' ", ''''' '''); 28 Expect.equals(r"'' ", ''''' ''');
(...skipping 12 matching lines...) Expand all
41 "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" 41 "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
42 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" 42 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
43 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" 43 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
44 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" 44 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
45 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" 45 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
46 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf" 46 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
47 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef" 47 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
48 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"; 48 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
49 Expect.equals(256, allBytes.length); 49 Expect.equals(256, allBytes.length);
50 for (int i = 0; i < 256; i++) { 50 for (int i = 0; i < 256; i++) {
51 Expect.equals(i, allBytes.charCodeAt(i)); 51 Expect.equals(i, allBytes.codeUnitAt(i));
52 } 52 }
53 } 53 }
54 54
55 testUEscapes() { 55 testUEscapes() {
56 List/*String*/ examples = 56 List/*String*/ examples =
57 ["\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff" 57 ["\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff"
58 "\u0100\u1000\ud7ff\ue000\uffff", 58 "\u0100\u1000\ud7ff\ue000\uffff",
59 '\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff' 59 '\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff'
60 '\u0100\u1000\ud7ff\ue000\uffff', 60 '\u0100\u1000\ud7ff\ue000\uffff',
61 """\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff""" 61 """\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff"""
62 """\u0100\u1000\ud7ff\ue000\uffff""", 62 """\u0100\u1000\ud7ff\ue000\uffff""",
63 '''\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff''' 63 '''\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff'''
64 '''\u0100\u1000\ud7ff\ue000\uffff''']; 64 '''\u0100\u1000\ud7ff\ue000\uffff'''];
65 List/*<int>*/ values = [0, 1, 0x22, 0x27, 0x5c, 0x7f, 0x80, 0xff, 65 List/*<int>*/ values = [0, 1, 0x22, 0x27, 0x5c, 0x7f, 0x80, 0xff,
66 0x100, 0x1000, 0xd7ff, 0xe000, 0xffff]; 66 0x100, 0x1000, 0xd7ff, 0xe000, 0xffff];
67 for (String s in examples) { 67 for (String s in examples) {
68 Expect.equals(values.length, s.length); 68 Expect.equals(values.length, s.length);
69 for (int i = 0; i < values.length; i++) { 69 for (int i = 0; i < values.length; i++) {
70 Expect.equals(values[i], s.charCodeAt(i)); 70 Expect.equals(values[i], s.codeUnitAt(i));
71 } 71 }
72 } 72 }
73 // No characters above 0xffff until Leg supports that. 73 // No characters above 0xffff until Leg supports that.
74 var long = 74 var long =
75 "\u{0}\u{00}\u{000}\u{0000}\u{00000}\u{000000}" 75 "\u{0}\u{00}\u{000}\u{0000}\u{00000}\u{000000}"
76 "\u{1}\u{01}\u{001}\u{00001}" 76 "\u{1}\u{01}\u{001}\u{00001}"
77 "\u{ffff}\u{0ffff}\u{00ffff}"; 77 "\u{ffff}\u{0ffff}\u{00ffff}";
78 var longValues = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0xffff, 0xffff, 0xffff]; 78 var longValues = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0xffff, 0xffff, 0xffff];
79 Expect.equals(longValues.length, long.length); 79 Expect.equals(longValues.length, long.length);
80 for (int i = 0; i < longValues.length; i++) { 80 for (int i = 0; i < longValues.length; i++) {
81 Expect.equals(longValues[i], long.charCodeAt(i)); 81 Expect.equals(longValues[i], long.codeUnitAt(i));
82 } 82 }
83 } 83 }
84 84
85 testIdentityEscapes() { 85 testIdentityEscapes() {
86 // All non-control ASCII characters escaped, except those with special 86 // All non-control ASCII characters escaped, except those with special
87 // meaning: b, f, n, r, t, u, v, and x (replaced by \x00). 87 // meaning: b, f, n, r, t, u, v, and x (replaced by \x00).
88 var asciiLiterals = 88 var asciiLiterals =
89 "\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8\9\:\;\<\=\>" 89 "\ \!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\0\1\2\3\4\5\6\7\8\9\:\;\<\=\>"
90 "\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z\[\\\]" 90 "\?\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z\[\\\]"
91 "\^\_\`\a\x00\c\d\e\x00\g\h\i\j\k\l\m\x00\o\p\q\x00\s\x00\x00\x00" 91 "\^\_\`\a\x00\c\d\e\x00\g\h\i\j\k\l\m\x00\o\p\q\x00\s\x00\x00\x00"
92 "\w\x00\y\z\{\|\}\~\"; 92 "\w\x00\y\z\{\|\}\~\";
93 93
94 Expect.equals(128 - 32, asciiLiterals.length); 94 Expect.equals(128 - 32, asciiLiterals.length);
95 for (int i = 32; i < 128; i++) { 95 for (int i = 32; i < 128; i++) {
96 int code = asciiLiterals.charCodeAt(i - 32); 96 int code = asciiLiterals.codeUnitAt(i - 32);
97 if (code != 0) { 97 if (code != 0) {
98 Expect.equals(i, code); 98 Expect.equals(i, code);
99 } 99 }
100 } 100 }
101 } 101 }
102 102
103 103
104 testQuotes() { 104 testQuotes() {
105 // The string [ "' ]. 105 // The string [ "' ].
106 String bothQuotes = ' "' "' "; 106 String bothQuotes = ' "' "' ";
107 Expect.equals(bothQuotes, " \"' "); 107 Expect.equals(bothQuotes, " \"' ");
108 Expect.equals(bothQuotes, ' "\' '); 108 Expect.equals(bothQuotes, ' "\' ');
109 Expect.equals(bothQuotes, """ "' """); 109 Expect.equals(bothQuotes, """ "' """);
110 Expect.equals(bothQuotes, ''' "' '''); 110 Expect.equals(bothQuotes, ''' "' ''');
111 Expect.equals(bothQuotes, r""" "' """); 111 Expect.equals(bothQuotes, r""" "' """);
112 Expect.equals(bothQuotes, r''' "' '''); 112 Expect.equals(bothQuotes, r''' "' ''');
113 } 113 }
114 114
115 115
116 testRawStrings() { 116 testRawStrings() {
117 String raw1 = r'\x00'; 117 String raw1 = r'\x00';
118 Expect.equals(4, raw1.length); 118 Expect.equals(4, raw1.length);
119 Expect.equals(0x5c, raw1.charCodeAt(0)); 119 Expect.equals(0x5c, raw1.codeUnitAt(0));
120 } 120 }
121 121
122 main() { 122 main() {
123 // Test \x??. 123 // Test \x??.
124 testXEscapes(); 124 testXEscapes();
125 // Test \u???? and \u{?+}. 125 // Test \u???? and \u{?+}.
126 testUEscapes(); 126 testUEscapes();
127 // Test \b, \f, \n, \r, \t, \v. 127 // Test \b, \f, \n, \r, \t, \v.
128 testSingleCharacterEscapes(); 128 testSingleCharacterEscapes();
129 // Test all other single character (identity) escaeps. 129 // Test all other single character (identity) escaeps.
130 testIdentityEscapes(); 130 testIdentityEscapes();
131 // Test that quotes are handled correctly. 131 // Test that quotes are handled correctly.
132 testQuotes(); 132 testQuotes();
133 // Test that raw strings are raw. 133 // Test that raw strings are raw.
134 testRawStrings(); 134 testRawStrings();
135 } 135 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js_extra/bailout_test.dart ('k') | tests/corelib/collection_to_string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698