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 // Note: This test relies on LF line endings in the source file. | 5 // Note: This test relies on LF line endings in the source file. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 main() { | 9 main() { |
10 { | 10 { |
11 // Generates identical compile time constants. | 11 // Generates identical compile time constants. |
12 var s1 = "abcdefgh"; | 12 var s1 = "abcdefgh"; |
13 var s2 = "abcd" "efgh"; | 13 var s2 = "abcd" "efgh"; |
14 var s3 = "ab" "cd" "ef" "gh"; | 14 var s3 = "ab" "cd" "ef" "gh"; |
15 var s4 = "a" "b" "c" "d" "e" "f" "g" "h"; | 15 var s4 = "a" "b" "c" "d" "e" "f" "g" "h"; |
16 var s5 = "a" 'b' r"c" r'd' """e""" '''f''' r"""g""" r'''h'''; | 16 var s5 = "a" 'b' r"c" r'd' """e""" '''f''' r"""g""" r'''h'''; |
17 Expect.isTrue(identical(s1, s2)); | 17 Expect.isTrue(identical(s1, s2)); |
18 Expect.isTrue(identical(s1, s3)); | 18 Expect.isTrue(identical(s1, s3)); |
19 Expect.isTrue(identical(s1, s4)); | 19 Expect.isTrue(identical(s1, s4)); |
20 Expect.isTrue(identical(s1, s5)); | 20 Expect.isTrue(identical(s1, s5)); |
21 } | 21 } |
22 { | 22 { |
23 // Separating whitespace isn't necessary for the tokenizer. | 23 // Separating whitespace isn't necessary for the tokenizer. |
24 var s1 = "abcdefgh"; | 24 var s1 = "abcdefgh"; |
25 var s2 = "abcd""efgh"; | 25 var s2 = "abcd" "efgh"; |
26 var s3 = "ab""cd""ef""gh"; | 26 var s3 = "ab" "cd" "ef" "gh"; |
27 var s4 = "a""b""c""d""e""f""g""h"; | 27 var s4 = "a" "b" "c" "d" "e" "f" "g" "h"; |
28 var s5 = "a"'b'r"c"r'd'"""e"""'''f'''r"""g"""r'''h'''; | 28 var s5 = "a" 'b' r"c" r'd' """e""" '''f''' r"""g""" r'''h'''; |
29 Expect.isTrue(identical(s1, s2)); | 29 Expect.isTrue(identical(s1, s2)); |
30 Expect.isTrue(identical(s1, s3)); | 30 Expect.isTrue(identical(s1, s3)); |
31 Expect.isTrue(identical(s1, s4)); | 31 Expect.isTrue(identical(s1, s4)); |
32 Expect.isTrue(identical(s1, s5)); | 32 Expect.isTrue(identical(s1, s5)); |
33 // "a""""""b""" should be tokenized as "a" """""b""", aka. "a" '""b'. | 33 // "a""""""b""" should be tokenized as "a" """""b""", aka. "a" '""b'. |
34 Expect.isTrue(identical('a""b', "a""""""b""")); | 34 Expect.isTrue(identical('a""b', "a" """""b""")); |
35 // """a""""""""b""" is 'a' '""b'. | 35 // """a""""""""b""" is 'a' '""b'. |
36 Expect.isTrue(identical('a""b', """a""""""""b""")); | 36 Expect.isTrue(identical('a""b', """a""" """""b""")); |
37 // Raw strings. | 37 // Raw strings. |
38 Expect.isTrue(identical('ab', "a"r"b")); | 38 Expect.isTrue(identical('ab', "a" r"b")); |
39 Expect.isTrue(identical('ab', r"a""b")); | 39 Expect.isTrue(identical('ab', r"a" "b")); |
40 Expect.isTrue(identical('ab', r"a"r"b")); | 40 Expect.isTrue(identical('ab', r"a" r"b")); |
41 } | 41 } |
42 | 42 |
43 // Newlines are just whitespace. | 43 // Newlines are just whitespace. |
44 var ms1 = "abc" | 44 var ms1 = "abc" |
45 "def" | 45 "def" |
46 "ghi" | 46 "ghi" |
47 "jkl"; | 47 "jkl"; |
48 Expect.isTrue(identical("abcdefghijkl", ms1)); | 48 Expect.isTrue(identical("abcdefghijkl", ms1)); |
49 | 49 |
50 // Works with multiline strings too. | 50 // Works with multiline strings too. |
51 var ms2 = """abc | 51 var ms2 = """abc |
52 def""" | 52 def""" |
53 """ | 53 """ |
54 ghi | 54 ghi |
55 jkl | 55 jkl |
56 """; | 56 """; |
57 Expect.isTrue(identical("abc\n def ghi\n jkl\n ", ms2), "Multiline: $ms2")
; | 57 Expect.isTrue( |
| 58 identical("abc\n def ghi\n jkl\n ", ms2), "Multiline: $ms2"); |
58 | 59 |
59 // Binds stronger than property access (it's considered one literal). | 60 // Binds stronger than property access (it's considered one literal). |
60 Expect.equals(5, "ab" "cde".length, "Associativity"); | 61 Expect.equals(5, "ab" "cde".length, "Associativity"); |
61 | 62 |
62 // Check that interpolations are handled correctly. | 63 // Check that interpolations are handled correctly. |
63 { | 64 { |
64 var x = "foo"; | 65 var x = "foo"; |
65 var y = 42; | 66 var y = 42; |
66 var z = true; | 67 var z = true; |
67 String e1 = "$x$y$z"; | 68 String e1 = "$x$y$z"; |
(...skipping 28 matching lines...) Expand all Loading... |
96 Expect.equals("$x--$y", "$x" "-" "-" "" "$y"); | 97 Expect.equals("$x--$y", "$x" "-" "-" "" "$y"); |
97 Expect.equals("$x--$y", "$x" "-" "" "-" "$y"); | 98 Expect.equals("$x--$y", "$x" "-" "" "-" "$y"); |
98 Expect.equals("$x--$y", "$x" "" "-" "-" "$y"); | 99 Expect.equals("$x--$y", "$x" "" "-" "-" "$y"); |
99 | 100 |
100 Expect.equals("$x---$y", "$x" "-" "-" "-" "$y"); | 101 Expect.equals("$x---$y", "$x" "-" "-" "-" "$y"); |
101 Expect.equals("$x---", "$x" "-" "-" "-"); | 102 Expect.equals("$x---", "$x" "-" "-" "-"); |
102 Expect.equals("---$y", "-" "-" "-" "$y"); | 103 Expect.equals("---$y", "-" "-" "-" "$y"); |
103 | 104 |
104 Expect.equals("$x-$y-$z", "${'$x' '-' '$y'}" "-" "$z"); | 105 Expect.equals("$x-$y-$z", "${'$x' '-' '$y'}" "-" "$z"); |
105 | 106 |
106 Expect.equals(r"-foo-42-true-", | 107 Expect.equals( |
107 r"-" "$x" r"""-""" """$y""" r'-' '$z' r'''-''', "j"); | 108 r"-foo-42-true-", r"-" "$x" r"""-""" """$y""" r'-' '$z' r'''-''', "j"); |
108 Expect.equals(r"-$x-42-true-", | 109 Expect.equals( |
109 r"-" r"$x" r"""-""" """$y""" r'-' '$z' r'''-''', "k"); | 110 r"-$x-42-true-", r"-" r"$x" r"""-""" """$y""" r'-' '$z' r'''-''', "k"); |
110 Expect.equals(r"-foo-$y-true-", | 111 Expect.equals( |
111 r"-" "$x" r"""-""" r"""$y""" r'-' '$z' r'''-''', "l"); | 112 r"-foo-$y-true-", r"-" "$x" r"""-""" r"""$y""" r'-' '$z' r'''-''', "l"); |
112 Expect.equals(r"-foo-42-$z-", | 113 Expect.equals( |
113 r"-" "$x" r"""-""" """$y""" r'-' r'$z' r'''-''', "m"); | 114 r"-foo-42-$z-", r"-" "$x" r"""-""" """$y""" r'-' r'$z' r'''-''', "m"); |
114 } | 115 } |
115 } | 116 } |
OLD | NEW |