| 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 |  | 
| 5 // Test that string escapes work correctly. |  | 
| 6 |  | 
| 7 testSingleCharacterEscapes() { |  | 
| 8   List/*<String>*/ examples = [ |  | 
| 9     "\b\f\n\r\t\v", |  | 
| 10     '\b\f\n\r\t\v', |  | 
| 11     """\b\f\n\r\t\v""", |  | 
| 12     '''\b\f\n\r\t\v''', |  | 
| 13   ]; |  | 
| 14   List values = [8, 12, 10, 13, 9, 11]; |  | 
| 15   for (String s in examples) { |  | 
| 16     Expect.equals(6, s.length); |  | 
| 17     for (int i = 0; i < 6; i++) { |  | 
| 18       Expect.equals(values[i], s.charCodeAt(i)); |  | 
| 19     } |  | 
| 20   } |  | 
| 21 |  | 
| 22   // An escaped quote isn't part of a multiline end quote. |  | 
| 23   Expect.equals(@'"', """\""""); |  | 
| 24   Expect.equals(@"'", '''\''''); |  | 
| 25   Expect.equals(@'" "', """" \""""); |  | 
| 26   Expect.equals(@"' '", '''' \''''); |  | 
| 27   Expect.equals(@'"" ', """"" """); |  | 
| 28   Expect.equals(@"'' ", ''''' '''); |  | 
| 29 } |  | 
| 30 |  | 
| 31 testXEscapes() { |  | 
| 32   var allBytes = |  | 
| 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" + |  | 
| 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" + |  | 
| 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" + |  | 
| 39       "\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f" + |  | 
| 40       "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f" + |  | 
| 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" + |  | 
| 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" + |  | 
| 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" + |  | 
| 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"; |  | 
| 49   Expect.equals(256, allBytes.length); |  | 
| 50   for (int i = 0; i < 256; i++) { |  | 
| 51     Expect.equals(i, allBytes.charCodeAt(i)); |  | 
| 52   } |  | 
| 53 } |  | 
| 54 |  | 
| 55 testUEscapes() { |  | 
| 56   List/*String*/ examples = |  | 
| 57     ["\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff" + |  | 
| 58      "\u0100\u1000\ud7ff\ue000\uffff", |  | 
| 59      '\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff' + |  | 
| 60      '\u0100\u1000\ud7ff\ue000\uffff', |  | 
| 61      """\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff""" + |  | 
| 62      """\u0100\u1000\ud7ff\ue000\uffff""", |  | 
| 63      '''\u0000\u0001\u0022\u0027\u005c\u007f\u0080\u00ff''' + |  | 
| 64      '''\u0100\u1000\ud7ff\ue000\uffff''']; |  | 
| 65   List/*<int>*/ values = [0, 1, 0x22, 0x27, 0x5c, 0x7f, 0x80, 0xff, |  | 
| 66                           0x100, 0x1000, 0xd7ff, 0xe000, 0xffff]; |  | 
| 67   for (String s in examples) { |  | 
| 68     Expect.equals(values.length, s.length); |  | 
| 69     for (int i = 0; i < values.length; i++) { |  | 
| 70       Expect.equals(values[i], s.charCodeAt(i)); |  | 
| 71     } |  | 
| 72   } |  | 
| 73   // No characters above 0xffff until Leg supports that. |  | 
| 74   var long = |  | 
| 75       "\u{0}\u{00}\u{000}\u{0000}\u{00000}\u{000000}" + |  | 
| 76       "\u{1}\u{01}\u{001}\u{00001}" + |  | 
| 77       "\u{ffff}\u{0ffff}\u{00ffff}"; |  | 
| 78   var longValues = [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0xffff, 0xffff, 0xffff]; |  | 
| 79   Expect.equals(longValues.length, long.length); |  | 
| 80   for (int i = 0; i < longValues.length; i++) { |  | 
| 81     Expect.equals(longValues[i], long.charCodeAt(i)); |  | 
| 82   } |  | 
| 83 } |  | 
| 84 |  | 
| 85 testIdentityEscapes() { |  | 
| 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). |  | 
| 88   var asciiLiterals = |  | 
| 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\[\\\]" + |  | 
| 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\{\|\}\~\"; |  | 
| 93 |  | 
| 94   Expect.equals(128 - 32, asciiLiterals.length); |  | 
| 95   for (int i = 32; i < 128; i++) { |  | 
| 96     int code = asciiLiterals.charCodeAt(i - 32); |  | 
| 97     if (code != 0) { |  | 
| 98       Expect.equals(i, code); |  | 
| 99     } |  | 
| 100   } |  | 
| 101 } |  | 
| 102 |  | 
| 103 |  | 
| 104 testQuotes() { |  | 
| 105   // The string [ "' ]. |  | 
| 106   String bothQuotes = ' "' "' "; |  | 
| 107   Expect.equals(bothQuotes, " \"' "); |  | 
| 108   Expect.equals(bothQuotes, ' "\' '); |  | 
| 109   Expect.equals(bothQuotes, """ "' """); |  | 
| 110   Expect.equals(bothQuotes, ''' "' '''); |  | 
| 111   Expect.equals(bothQuotes, @""" "' """); |  | 
| 112   Expect.equals(bothQuotes, @''' "' '''); |  | 
| 113 } |  | 
| 114 |  | 
| 115 |  | 
| 116 testRawStrings() { |  | 
| 117   String raw1 = @'\x00'; |  | 
| 118   Expect.equals(4, raw1.length); |  | 
| 119   Expect.equals(0x5c, raw1.charCodeAt(0)); |  | 
| 120 } |  | 
| 121 |  | 
| 122 main() { |  | 
| 123   // Test \x??. |  | 
| 124   testXEscapes(); |  | 
| 125   // Test \u???? and \u{?+}. |  | 
| 126   testUEscapes(); |  | 
| 127   // Test \b, \f, \n, \r, \t, \v. |  | 
| 128   testSingleCharacterEscapes(); |  | 
| 129   // Test all other single character (identity) escaeps. |  | 
| 130   testIdentityEscapes(); |  | 
| 131   // Test that quotes are handled correctly. |  | 
| 132   testQuotes(); |  | 
| 133   // Test that raw strings are raw. |  | 
| 134   testRawStrings(); |  | 
| 135 } |  | 
| OLD | NEW | 
|---|