OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Tests for basic functionality. | 5 // Tests for basic functionality. |
6 | 6 |
7 library basic_tests; | 7 library basic_tests; |
8 | 8 |
9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
10 | 10 |
11 const List<TestEntry> tests = const [ | 11 const List<TestEntry> tests = const [ |
12 const TestEntry(r""" | 12 const TestEntry(r""" |
13 main() { | 13 main() { |
14 var e = 1; | 14 var e = 1; |
15 var l = [1, 2, 3]; | 15 var l = [1, 2, 3]; |
16 var m = {'s': 1}; | 16 var m = {'s': 1}; |
17 | 17 |
18 print('(' ')'); | 18 print('(' ')'); |
19 print('(${true})'); | 19 print('(${true})'); |
20 print('(${1})'); | 20 print('(${1})'); |
21 print('(${[1, 2, 3]})'); | 21 print('(${[1, 2, 3]})'); |
22 print('(${{'s': 1}})'); | 22 print('(${{'s': 1}})'); |
23 print('($e)'); | 23 print('($e)'); |
24 print('($l)'); | 24 print('($l)'); |
25 print('($m)'); | 25 print('($m)'); |
26 }""",r""" | 26 }""",r""" |
27 function() { | 27 function() { |
28 var l = [1, 2, 3], m = P.LinkedHashMap_LinkedHashMap$_literal(["s", 1]); | 28 var l = [1, 2, 3], m = P.LinkedHashMap_LinkedHashMap$_literal(["s", 1]), value
_ = C.JSArray_methods, res, v0, v1; |
29 P.print("()"); | 29 P.print("()"); |
30 P.print("(true)"); | 30 P.print("(true)"); |
31 P.print("(1)"); | 31 P.print("(1)"); |
32 P.print("(" + H.S([1, 2, 3]) + ")"); | 32 if (!(typeof (res = value_.toString$0(v0 = [1, 2, 3])) === "string")) |
33 P.print("(" + H.S(P.LinkedHashMap_LinkedHashMap$_literal(["s", 1])) + ")"); | 33 throw H.wrapException(H.argumentErrorValue(v0)); |
| 34 P.print("(" + res + ")"); |
| 35 if (!(typeof (v1 = P.Maps_mapToString(v0 = P.LinkedHashMap_LinkedHashMap$_lite
ral(["s", 1]))) === "string")) |
| 36 throw H.wrapException(H.argumentErrorValue(v0)); |
| 37 P.print("(" + v1 + ")"); |
34 P.print("(1)"); | 38 P.print("(1)"); |
35 P.print("(" + H.S(l) + ")"); | 39 if (!(typeof (res = value_.toString$0(l)) === "string")) |
36 P.print("(" + H.S(m) + ")"); | 40 throw H.wrapException(H.argumentErrorValue(l)); |
| 41 P.print("(" + res + ")"); |
| 42 if (!(typeof (v0 = P.Maps_mapToString(m)) === "string")) |
| 43 throw H.wrapException(H.argumentErrorValue(m)); |
| 44 P.print("(" + v0 + ")"); |
37 }"""), | 45 }"""), |
38 const TestEntry(""" | 46 const TestEntry(""" |
39 foo(a, [b = "b"]) { print(b); return b; } | 47 foo(a, [b = "b"]) { print(b); return b; } |
40 bar(a, {b: "b", c: "c"}) { print(c); return c; } | 48 bar(a, {b: "b", c: "c"}) { print(c); return c; } |
41 main() { | 49 main() { |
42 foo(0); | 50 foo(0); |
43 foo(1, 2); | 51 foo(1, 2); |
44 bar(3); | 52 bar(3); |
45 bar(4, b: 5); | 53 bar(4, b: 5); |
46 bar(6, c: 7); | 54 bar(6, c: 7); |
47 bar(8, b: 9, c: 10); | 55 bar(8, b: 9, c: 10); |
48 } | 56 } |
49 """, | 57 """, |
50 """ | 58 """ |
51 function() { | 59 function() { |
52 V.foo(0, "b"); | 60 P.print("b"); |
53 V.foo(1, 2); | 61 P.print(2); |
54 V.bar(3, "b", "c"); | 62 P.print("c"); |
55 V.bar(4, 5, "c"); | 63 P.print("c"); |
56 V.bar(6, "b", 7); | 64 P.print(7); |
57 V.bar(8, 9, 10); | 65 P.print(10); |
58 }"""), | 66 }"""), |
59 const TestEntry( | 67 const TestEntry( |
60 """ | 68 """ |
61 foo(a) { | 69 foo(a) { |
62 print(a); | 70 print(a); |
63 return a; | 71 return a; |
64 } | 72 } |
65 main() { | 73 main() { |
66 var a = 10; | 74 var a = 10; |
67 var b = 1; | 75 var b = 1; |
68 var t; | 76 var t; |
69 t = a; | 77 t = a; |
70 a = b; | 78 a = b; |
71 b = t; | 79 b = t; |
72 print(a); | 80 print(a); |
73 print(b); | 81 print(b); |
74 print(b); | 82 print(b); |
75 print(foo(a)); | 83 print(foo(a)); |
76 } | 84 } |
77 """, | 85 """, |
78 """ | 86 """ |
79 function() { | 87 function() { |
80 P.print(1); | 88 P.print(1); |
81 P.print(10); | 89 P.print(10); |
82 P.print(10); | 90 P.print(10); |
83 P.print(V.foo(1)); | 91 P.print(1); |
| 92 P.print(1); |
84 }"""), | 93 }"""), |
85 const TestEntry( | 94 const TestEntry( |
86 """ | 95 """ |
87 foo() { print(42); return 42; } | 96 foo() { print(42); return 42; } |
88 main() { return foo(); } | 97 main() { return foo(); } |
89 """, | 98 """, |
90 """function() { | 99 """ |
91 return V.foo(); | 100 function() { |
| 101 var v0 = H.S(42); |
| 102 if (typeof dartPrint == "function") |
| 103 dartPrint(v0); |
| 104 else if (typeof console == "object" && typeof console.log != "undefined") |
| 105 console.log(v0); |
| 106 else if (!(typeof window == "object")) { |
| 107 if (!(typeof print == "function")) |
| 108 throw "Unable to print message: " + String(v0); |
| 109 print(v0); |
| 110 } |
| 111 return 42; |
92 }"""), | 112 }"""), |
93 const TestEntry("main() {}"), | 113 const TestEntry("main() {}"), |
94 const TestEntry("main() { return 42; }"), | 114 const TestEntry("main() { return 42; }"), |
95 const TestEntry("main() { return; }", """ | 115 const TestEntry("main() { return; }", """ |
96 function() { | 116 function() { |
97 }"""), | 117 }"""), |
98 // Constructor invocation | 118 // Constructor invocation |
99 const TestEntry(""" | 119 const TestEntry(""" |
100 main() { | 120 main() { |
101 print(new Set()); | 121 print(new Set()); |
102 print(new Set.from([1, 2, 3])); | 122 print(new Set.from([1, 2, 3])); |
103 }""", r""" | 123 }""", r""" |
104 function() { | 124 function() { |
105 P.print(P.LinkedHashSet_LinkedHashSet(null, null, null, null)); | 125 P.print(P._LinkedHashSet$(null)); |
106 P.print(P.LinkedHashSet_LinkedHashSet$from([1, 2, 3], null)); | 126 P.print(P.LinkedHashSet_LinkedHashSet$from([1, 2, 3], null)); |
107 }"""), | 127 }"""), |
108 // Call synthetic constructor. | 128 // Call synthetic constructor. |
109 const TestEntry(""" | 129 const TestEntry(""" |
110 class C {} | 130 class C {} |
111 main() { | 131 main() { |
112 print(new C()); | 132 print(new C()); |
113 }"""), | 133 }"""), |
114 // Method invocation | 134 // Method invocation |
115 const TestEntry(""" | 135 const TestEntry(""" |
116 main() { | 136 main() { |
117 print(new DateTime.now().isBefore(new DateTime.now())); | 137 print(new DateTime.now().isBefore(new DateTime.now())); |
118 }""", r""" | 138 }""", r""" |
119 function() { | 139 function() { |
120 P.print(P.DateTime$now().isBefore$1(P.DateTime$now())); | 140 var v0 = H.S(Date.now() < Date.now()); |
| 141 if (typeof dartPrint == "function") |
| 142 dartPrint(v0); |
| 143 else if (typeof console == "object" && typeof console.log != "undefined") |
| 144 console.log(v0); |
| 145 else if (!(typeof window == "object")) { |
| 146 if (!(typeof print == "function")) |
| 147 throw "Unable to print message: " + String(v0); |
| 148 print(v0); |
| 149 } |
121 }"""), | 150 }"""), |
122 // Static calls | 151 // Static calls |
123 const TestEntry(""" | 152 const TestEntry(""" |
124 foo() { print(42); } | 153 foo() { print(42); } |
125 main() { foo(); } | 154 main() { foo(); } |
126 """, r""" | 155 """, r""" |
127 function() { | 156 function() { |
128 V.foo(); | 157 var v0 = H.S(42); |
| 158 if (typeof dartPrint == "function") |
| 159 dartPrint(v0); |
| 160 else if (typeof console == "object" && typeof console.log != "undefined") |
| 161 console.log(v0); |
| 162 else if (!(typeof window == "object")) { |
| 163 if (!(typeof print == "function")) |
| 164 throw "Unable to print message: " + String(v0); |
| 165 print(v0); |
| 166 } |
129 }"""), | 167 }"""), |
130 // Static getters | 168 // Static getters |
131 const TestEntry(""" | 169 const TestEntry(""" |
132 var foo = 42; | 170 var foo = 42; |
133 main() { print(foo); } | 171 main() { print(foo); } |
134 """, r""" | 172 """, r""" |
135 function() { | 173 function() { |
136 P.print($.foo); | 174 var v0 = H.S($.foo); |
| 175 if (typeof dartPrint == "function") |
| 176 dartPrint(v0); |
| 177 else if (typeof console == "object" && typeof console.log != "undefined") |
| 178 console.log(v0); |
| 179 else if (!(typeof window == "object")) { |
| 180 if (!(typeof print == "function")) |
| 181 throw "Unable to print message: " + String(v0); |
| 182 print(v0); |
| 183 } |
137 }"""), | 184 }"""), |
138 const TestEntry(""" | 185 const TestEntry(""" |
139 get foo { print(42); } | 186 get foo { print(42); } |
140 main() { foo; } | 187 main() { foo; } |
141 """, r""" | 188 """, r""" |
142 function() { | 189 function() { |
143 V.foo(); | 190 var v0 = H.S(42); |
| 191 if (typeof dartPrint == "function") |
| 192 dartPrint(v0); |
| 193 else if (typeof console == "object" && typeof console.log != "undefined") |
| 194 console.log(v0); |
| 195 else if (!(typeof window == "object")) { |
| 196 if (!(typeof print == "function")) |
| 197 throw "Unable to print message: " + String(v0); |
| 198 print(v0); |
| 199 } |
144 }"""), | 200 }"""), |
145 // Static setters | 201 // Static setters |
146 const TestEntry(""" | 202 const TestEntry(""" |
147 var foo = 0; | 203 var foo = 0; |
148 main() { print(foo = 42); } | 204 main() { print(foo = 42); } |
149 """, r""" | 205 """, r""" |
150 function() { | 206 function() { |
| 207 var v0; |
151 $.foo = 42; | 208 $.foo = 42; |
152 P.print(42); | 209 v0 = H.S(42); |
| 210 if (typeof dartPrint == "function") |
| 211 dartPrint(v0); |
| 212 else if (typeof console == "object" && typeof console.log != "undefined") |
| 213 console.log(v0); |
| 214 else if (!(typeof window == "object")) { |
| 215 if (!(typeof print == "function")) |
| 216 throw "Unable to print message: " + String(v0); |
| 217 print(v0); |
| 218 } |
153 }"""), | 219 }"""), |
154 const TestEntry(""" | 220 const TestEntry(""" |
155 set foo(x) { print(x); } | 221 set foo(x) { print(x); } |
156 main() { foo = 42; } | 222 main() { foo = 42; } |
157 """, r""" | 223 """, r""" |
158 function() { | 224 function() { |
159 V.foo(42); | 225 var v0 = H.S(42); |
| 226 if (typeof dartPrint == "function") |
| 227 dartPrint(v0); |
| 228 else if (typeof console == "object" && typeof console.log != "undefined") |
| 229 console.log(v0); |
| 230 else if (!(typeof window == "object")) { |
| 231 if (!(typeof print == "function")) |
| 232 throw "Unable to print message: " + String(v0); |
| 233 print(v0); |
| 234 } |
160 }"""), | 235 }"""), |
161 // Assert | 236 // Assert |
162 const TestEntry(""" | 237 const TestEntry(""" |
163 foo() { print('X'); } | 238 foo() { print('X'); } |
164 main() { | 239 main() { |
165 assert(true); | 240 assert(true); |
166 assert(false); | 241 assert(false); |
167 assert(foo()); | 242 assert(foo()); |
168 print('Done'); | 243 print('Done'); |
169 }""", r""" | 244 }""", r""" |
170 function() { | 245 function() { |
171 P.print("Done"); | 246 P.print("Done"); |
172 }""") | 247 }""") |
173 ]; | 248 ]; |
174 | 249 |
175 | 250 |
176 void main() { | 251 void main() { |
177 runTests(tests); | 252 runTests(tests); |
178 } | 253 } |
OLD | NEW |