| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Tests for basic functionality. | |
| 6 | |
| 7 library basic_tests; | |
| 8 | |
| 9 import 'js_backend_cps_ir.dart'; | |
| 10 | |
| 11 const List<TestEntry> tests = const [ | |
| 12 const TestEntry(r""" | |
| 13 main() { | |
| 14 var e = 1; | |
| 15 var l = [1, 2, 3]; | |
| 16 var m = {'s': 1}; | |
| 17 | |
| 18 print('(' ')'); | |
| 19 print('(${true})'); | |
| 20 print('(${1})'); | |
| 21 print('(${[1, 2, 3]})'); | |
| 22 print('(${{'s': 1}})'); | |
| 23 print('($e)'); | |
| 24 print('($l)'); | |
| 25 print('($m)'); | |
| 26 }""",r""" | |
| 27 function() { | |
| 28 var l = [1, 2, 3], m = P.LinkedHashMap_LinkedHashMap$_literal(["s", 1]), v0, v
1; | |
| 29 P.print("()"); | |
| 30 P.print("(true)"); | |
| 31 P.print("(1)"); | |
| 32 if (!(typeof (v0 = P.IterableBase_iterableToFullString(v1 = [1, 2, 3], "[", "]
")) === "string")) | |
| 33 throw H.wrapException(H.argumentErrorValue(v1)); | |
| 34 P.print("(" + v0 + ")"); | |
| 35 if (!(typeof (v0 = P.Maps_mapToString(v1 = P.LinkedHashMap_LinkedHashMap$_lite
ral(["s", 1]))) === "string")) | |
| 36 throw H.wrapException(H.argumentErrorValue(v1)); | |
| 37 P.print("(" + v0 + ")"); | |
| 38 P.print("(1)"); | |
| 39 if (!(typeof (v1 = P.IterableBase_iterableToFullString(l, "[", "]")) === "stri
ng")) | |
| 40 throw H.wrapException(H.argumentErrorValue(l)); | |
| 41 P.print("(" + v1 + ")"); | |
| 42 if (!(typeof (v1 = P.Maps_mapToString(m)) === "string")) | |
| 43 throw H.wrapException(H.argumentErrorValue(m)); | |
| 44 P.print("(" + v1 + ")"); | |
| 45 }"""), | |
| 46 const TestEntry(""" | |
| 47 foo(a, [b = "b"]) { print(b); return b; } | |
| 48 bar(a, {b: "b", c: "c"}) { print(c); return c; } | |
| 49 main() { | |
| 50 foo(0); | |
| 51 foo(1, 2); | |
| 52 bar(3); | |
| 53 bar(4, b: 5); | |
| 54 bar(6, c: 7); | |
| 55 bar(8, b: 9, c: 10); | |
| 56 } | |
| 57 """, | |
| 58 """ | |
| 59 function() { | |
| 60 P.print("b"); | |
| 61 P.print(2); | |
| 62 P.print("c"); | |
| 63 P.print("c"); | |
| 64 P.print(7); | |
| 65 P.print(10); | |
| 66 }"""), | |
| 67 const TestEntry( | |
| 68 """ | |
| 69 foo(a) { | |
| 70 print(a); | |
| 71 return a; | |
| 72 } | |
| 73 main() { | |
| 74 var a = 10; | |
| 75 var b = 1; | |
| 76 var t; | |
| 77 t = a; | |
| 78 a = b; | |
| 79 b = t; | |
| 80 print(a); | |
| 81 print(b); | |
| 82 print(b); | |
| 83 print(foo(a)); | |
| 84 } | |
| 85 """, | |
| 86 """ | |
| 87 function() { | |
| 88 P.print(1); | |
| 89 P.print(10); | |
| 90 P.print(10); | |
| 91 P.print(1); | |
| 92 P.print(1); | |
| 93 }"""), | |
| 94 const TestEntry( | |
| 95 """ | |
| 96 foo() { print(42); return 42; } | |
| 97 main() { return foo(); } | |
| 98 """, | |
| 99 """ | |
| 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; | |
| 112 }"""), | |
| 113 const TestEntry("main() {}"), | |
| 114 const TestEntry("main() { return 42; }"), | |
| 115 const TestEntry("main() { return; }", """ | |
| 116 function() { | |
| 117 }"""), | |
| 118 // Constructor invocation | |
| 119 const TestEntry(""" | |
| 120 main() { | |
| 121 print(new Set()); | |
| 122 print(new Set.from([1, 2, 3])); | |
| 123 }""", r""" | |
| 124 function() { | |
| 125 P.print(P._LinkedHashSet$(null)); | |
| 126 P.print(P.LinkedHashSet_LinkedHashSet$from([1, 2, 3], null)); | |
| 127 }"""), | |
| 128 // Call synthetic constructor. | |
| 129 const TestEntry(""" | |
| 130 class C {} | |
| 131 main() { | |
| 132 print(new C()); | |
| 133 }"""), | |
| 134 // Method invocation | |
| 135 const TestEntry(""" | |
| 136 main() { | |
| 137 print(new DateTime.now().isBefore(new DateTime.now())); | |
| 138 }""", r""" | |
| 139 function() { | |
| 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 } | |
| 150 }"""), | |
| 151 // Static calls | |
| 152 const TestEntry(""" | |
| 153 foo() { print(42); } | |
| 154 main() { foo(); } | |
| 155 """, r""" | |
| 156 function() { | |
| 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 } | |
| 167 }"""), | |
| 168 // Static getters | |
| 169 const TestEntry(""" | |
| 170 var foo = 42; | |
| 171 main() { print(foo); } | |
| 172 """, r""" | |
| 173 function() { | |
| 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 } | |
| 184 }"""), | |
| 185 const TestEntry(""" | |
| 186 get foo { print(42); } | |
| 187 main() { foo; } | |
| 188 """, r""" | |
| 189 function() { | |
| 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 } | |
| 200 }"""), | |
| 201 // Static setters | |
| 202 const TestEntry(""" | |
| 203 var foo = 0; | |
| 204 main() { print(foo = 42); } | |
| 205 """, r""" | |
| 206 function() { | |
| 207 var v0; | |
| 208 $.foo = 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 } | |
| 219 }"""), | |
| 220 const TestEntry(""" | |
| 221 set foo(x) { print(x); } | |
| 222 main() { foo = 42; } | |
| 223 """, r""" | |
| 224 function() { | |
| 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 } | |
| 235 }"""), | |
| 236 // Assert | |
| 237 const TestEntry(""" | |
| 238 foo() { print('X'); } | |
| 239 main() { | |
| 240 assert(true); | |
| 241 assert(false); | |
| 242 assert(foo()); | |
| 243 print('Done'); | |
| 244 }""", r""" | |
| 245 function() { | |
| 246 P.print("Done"); | |
| 247 }""") | |
| 248 ]; | |
| 249 | |
| 250 | |
| 251 void main() { | |
| 252 runTests(tests); | |
| 253 } | |
| OLD | NEW |