| 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 // 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.charCodeAt(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(@'"', """\""""); | 23 Expect.equals(r'"', """\""""); |
| 24 Expect.equals(@"'", '''\''''); | 24 Expect.equals(r"'", '''\''''); |
| 25 Expect.equals(@'" "', """" \""""); | 25 Expect.equals(r'" "', """" \""""); |
| 26 Expect.equals(@"' '", '''' \''''); | 26 Expect.equals(r"' '", '''' \''''); |
| 27 Expect.equals(@'"" ', """"" """); | 27 Expect.equals(r'"" ', """"" """); |
| 28 Expect.equals(@"'' ", ''''' '''); | 28 Expect.equals(r"'' ", ''''' '''); |
| 29 } | 29 } |
| 30 | 30 |
| 31 testXEscapes() { | 31 testXEscapes() { |
| 32 var allBytes = | 32 var allBytes = |
| 33 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" | 33 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" |
| 34 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" | 34 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f" |
| 35 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" | 35 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f" |
| 36 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" | 36 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f" |
| 37 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" | 37 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f" |
| 38 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" | 38 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, @""" "' """); | 111 Expect.equals(bothQuotes, r""" "' """); |
| 112 Expect.equals(bothQuotes, @''' "' '''); | 112 Expect.equals(bothQuotes, r''' "' '''); |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 testRawStrings() { | 116 testRawStrings() { |
| 117 String raw1 = @'\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.charCodeAt(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 } |
| OLD | NEW |