| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, 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 of interceptors. | |
| 6 | |
| 7 library constructor_test; | |
| 8 | |
| 9 import 'js_backend_cps_ir.dart'; | |
| 10 | |
| 11 const List<TestEntry> tests = const [ | |
| 12 const TestEntry(""" | |
| 13 class Base { | |
| 14 var x; | |
| 15 Base(this.x); | |
| 16 } | |
| 17 class Sub extends Base { | |
| 18 var y; | |
| 19 Sub(x, this.y) : super(x); | |
| 20 } | |
| 21 main() { | |
| 22 print(new Sub(1, 2).x); | |
| 23 }""", | |
| 24 r""" | |
| 25 function() { | |
| 26 var v0 = H.S(1); | |
| 27 if (typeof dartPrint == "function") | |
| 28 dartPrint(v0); | |
| 29 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 30 console.log(v0); | |
| 31 else if (!(typeof window == "object")) { | |
| 32 if (!(typeof print == "function")) | |
| 33 throw "Unable to print message: " + String(v0); | |
| 34 print(v0); | |
| 35 } | |
| 36 }"""), | |
| 37 | |
| 38 const TestEntry(""" | |
| 39 class Base { | |
| 40 var x; | |
| 41 Base(this.x); | |
| 42 } | |
| 43 class Sub extends Base { | |
| 44 var y; | |
| 45 Sub(x, this.y) : super(x) { | |
| 46 print(x); | |
| 47 } | |
| 48 } | |
| 49 main() { | |
| 50 print(new Sub(1, 2).x); | |
| 51 }""", | |
| 52 r""" | |
| 53 function() { | |
| 54 P.print(1); | |
| 55 P.print(1); | |
| 56 }"""), | |
| 57 | |
| 58 const TestEntry(""" | |
| 59 class Base0 { | |
| 60 Base0() { | |
| 61 print('Base0'); | |
| 62 } | |
| 63 } | |
| 64 class Base extends Base0 { | |
| 65 var x; | |
| 66 Base(this.x); | |
| 67 } | |
| 68 class Sub extends Base { | |
| 69 var y; | |
| 70 Sub(x, this.y) : super(x) { | |
| 71 print(x); | |
| 72 } | |
| 73 } | |
| 74 main() { | |
| 75 print(new Sub(1, 2).x); | |
| 76 }""", | |
| 77 r""" | |
| 78 function() { | |
| 79 P.print("Base0"); | |
| 80 P.print(1); | |
| 81 P.print(1); | |
| 82 }"""), | |
| 83 | |
| 84 const TestEntry(""" | |
| 85 class Base0 { | |
| 86 Base0() { | |
| 87 print('Base0'); | |
| 88 } | |
| 89 } | |
| 90 class Base extends Base0 { | |
| 91 var x; | |
| 92 Base(x1) : x = (() => ++x1) { | |
| 93 print(x1); // use boxed x1 | |
| 94 } | |
| 95 } | |
| 96 class Sub extends Base { | |
| 97 var y; | |
| 98 Sub(x, this.y) : super(x) { | |
| 99 print(x); | |
| 100 } | |
| 101 } | |
| 102 main() { | |
| 103 print(new Sub(1, 2).x); | |
| 104 }""", | |
| 105 r""" | |
| 106 function() { | |
| 107 var _box_0 = {}; | |
| 108 _box_0.x1 = 1; | |
| 109 P.print("Base0"); | |
| 110 P.print(_box_0.x1); | |
| 111 P.print(1); | |
| 112 P.print(new V.Base_closure(_box_0)); | |
| 113 }"""), | |
| 114 | |
| 115 const TestEntry(""" | |
| 116 foo(x) { | |
| 117 print(x); | |
| 118 } | |
| 119 class Base { | |
| 120 var x1 = foo('x1'); | |
| 121 var x2; | |
| 122 var x3 = foo('x3'); | |
| 123 Base() : x2 = foo('x2'); | |
| 124 } | |
| 125 class Sub extends Base { | |
| 126 var y1 = foo('y1'); | |
| 127 var y2; | |
| 128 var y3; | |
| 129 Sub() : y2 = foo('y2'), super(), y3 = foo('y3'); | |
| 130 } | |
| 131 main() { | |
| 132 new Sub(); | |
| 133 } | |
| 134 """, | |
| 135 r""" | |
| 136 function() { | |
| 137 V.foo("y1"); | |
| 138 V.foo("y2"); | |
| 139 V.foo("x1"); | |
| 140 V.foo("x3"); | |
| 141 V.foo("x2"); | |
| 142 V.foo("y3"); | |
| 143 }"""), | |
| 144 | |
| 145 | |
| 146 const TestEntry(""" | |
| 147 class Bar { | |
| 148 Bar(x, {y, z: 'z', w: '_', q}) { | |
| 149 print(x); | |
| 150 print(y); | |
| 151 print(z); | |
| 152 print(w); | |
| 153 print(q); | |
| 154 } | |
| 155 } | |
| 156 class Foo extends Bar { | |
| 157 Foo() : super('x', y: 'y', w: 'w'); | |
| 158 } | |
| 159 main() { | |
| 160 new Foo(); | |
| 161 } | |
| 162 """, | |
| 163 r""" | |
| 164 function() { | |
| 165 P.print("x"); | |
| 166 P.print("y"); | |
| 167 P.print("z"); | |
| 168 P.print("w"); | |
| 169 P.print(null); | |
| 170 }"""), | |
| 171 const TestEntry(r""" | |
| 172 class C<T> { | |
| 173 foo() => T; | |
| 174 } | |
| 175 main() { | |
| 176 print(new C<int>().foo()); | |
| 177 }""", r""" | |
| 178 function() { | |
| 179 var v0 = H.S(H.createRuntimeType(H.runtimeTypeToString(H.getTypeArgumentByInde
x(V.C$(P.$int), 0)))); | |
| 180 if (typeof dartPrint == "function") | |
| 181 dartPrint(v0); | |
| 182 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 183 console.log(v0); | |
| 184 else if (!(typeof window == "object")) { | |
| 185 if (!(typeof print == "function")) | |
| 186 throw "Unable to print message: " + String(v0); | |
| 187 print(v0); | |
| 188 } | |
| 189 }"""), | |
| 190 const TestEntry(r""" | |
| 191 class C<T> { | |
| 192 foo() => C; | |
| 193 } | |
| 194 main() { | |
| 195 print(new C<int>().foo()); | |
| 196 }""", r""" | |
| 197 function() { | |
| 198 var v0; | |
| 199 V.C$(); | |
| 200 v0 = H.S(C.Type_C_cdS); | |
| 201 if (typeof dartPrint == "function") | |
| 202 dartPrint(v0); | |
| 203 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 204 console.log(v0); | |
| 205 else if (!(typeof window == "object")) { | |
| 206 if (!(typeof print == "function")) | |
| 207 throw "Unable to print message: " + String(v0); | |
| 208 print(v0); | |
| 209 } | |
| 210 }"""), | |
| 211 const TestEntry.forMethod('generative_constructor(C#)', r""" | |
| 212 class C<T> { | |
| 213 C() { print(T); } | |
| 214 foo() => print(T); | |
| 215 } | |
| 216 main() { | |
| 217 new C<int>(); | |
| 218 }""", r""" | |
| 219 function($T) { | |
| 220 var v0 = H.setRuntimeTypeInfo(new V.C(), [$T]); | |
| 221 v0.C$0(); | |
| 222 return v0; | |
| 223 }"""), | |
| 224 const TestEntry.forMethod('generative_constructor(C#)', r""" | |
| 225 class C<T> { | |
| 226 var x; | |
| 227 C() : x = new D<T>(); | |
| 228 } | |
| 229 class D<T> { | |
| 230 foo() => T; | |
| 231 } | |
| 232 main() { | |
| 233 print(new C<int>().x.foo()); | |
| 234 }""", r""" | |
| 235 function($T) { | |
| 236 return H.setRuntimeTypeInfo(new V.C(V.D$($T)), [$T]); | |
| 237 }"""), | |
| 238 | |
| 239 | |
| 240 const TestEntry(r""" | |
| 241 class A { | |
| 242 var x; | |
| 243 A() : this.b(1); | |
| 244 A.b(this.x); | |
| 245 } | |
| 246 main() { | |
| 247 print(new A().x); | |
| 248 }""", r""" | |
| 249 function() { | |
| 250 var v0 = H.S(1); | |
| 251 if (typeof dartPrint == "function") | |
| 252 dartPrint(v0); | |
| 253 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 254 console.log(v0); | |
| 255 else if (!(typeof window == "object")) { | |
| 256 if (!(typeof print == "function")) | |
| 257 throw "Unable to print message: " + String(v0); | |
| 258 print(v0); | |
| 259 } | |
| 260 }"""), | |
| 261 | |
| 262 | |
| 263 const TestEntry(r""" | |
| 264 class Foo { | |
| 265 factory Foo.make(x) { | |
| 266 print('Foo'); | |
| 267 return new Foo.create(x); | |
| 268 } | |
| 269 var x; | |
| 270 Foo.create(this.x); | |
| 271 } | |
| 272 main() { | |
| 273 print(new Foo.make(5)); | |
| 274 }""", r""" | |
| 275 function() { | |
| 276 P.print("Foo"); | |
| 277 P.print(new V.Foo(5)); | |
| 278 }"""), | |
| 279 const TestEntry(r""" | |
| 280 class Foo { | |
| 281 factory Foo.make(x) = Foo.create; | |
| 282 var x; | |
| 283 Foo.create(this.x); | |
| 284 } | |
| 285 main() { | |
| 286 print(new Foo.make(5)); | |
| 287 }""", r""" | |
| 288 function() { | |
| 289 var v0 = new V.Foo(5), v1 = "Instance of '" + H.Primitives_objectTypeName(v0)
+ "'"; | |
| 290 if (!(typeof v1 === "string")) | |
| 291 throw H.wrapException(H.argumentErrorValue(v0)); | |
| 292 v0 = v1; | |
| 293 if (typeof dartPrint == "function") | |
| 294 dartPrint(v0); | |
| 295 else if (typeof console == "object" && typeof console.log != "undefined") | |
| 296 console.log(v0); | |
| 297 else if (!(typeof window == "object")) { | |
| 298 if (!(typeof print == "function")) | |
| 299 throw "Unable to print message: " + String(v0); | |
| 300 print(v0); | |
| 301 } | |
| 302 }"""), | |
| 303 const TestEntry(r""" | |
| 304 class A { | |
| 305 factory A(x) = B<int>; | |
| 306 get typevar; | |
| 307 } | |
| 308 class B<T> implements A { | |
| 309 var x; | |
| 310 B(this.x); | |
| 311 | |
| 312 get typevar => T; | |
| 313 } | |
| 314 main() { | |
| 315 new A(5).typevar; | |
| 316 }""", r""" | |
| 317 function() { | |
| 318 V.B$(5, P.$int); | |
| 319 }"""), | |
| 320 ]; | |
| 321 | |
| 322 void main() { | |
| 323 runTests(tests); | |
| 324 } | |
| OLD | NEW |