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 of operators. | 5 // Tests of operators. |
6 | 6 |
7 library operators_tests; | 7 library operators_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("main() { return true ? 42 : 'foo'; }"), | 12 const TestEntry("main() { return true ? 42 : 'foo'; }"), |
13 const TestEntry(""" | 13 const TestEntry(""" |
14 var x = 1; | 14 var x = 1; |
15 foo() => ++x > 10; | 15 foo() => ++x > 10; |
16 main() { | 16 main() { |
17 print(foo() ? "hello world" : "bad bad"); | 17 print(foo() ? "hello world" : "bad bad"); |
18 }""",""" | 18 }""",r""" |
19 function() { | 19 function() { |
20 P.print(V.foo() ? "hello world" : "bad bad"); | 20 var v0 = $.x + 1; |
21 }"""), | 21 $.x = v0; |
22 const TestEntry(""" | 22 v0 = v0 > 10 ? "hello world" : "bad bad"; |
23 var x = 1; | 23 if (typeof dartPrint == "function") |
24 foo() => ++x > 10; | 24 dartPrint(v0); |
25 main() { | 25 else if (typeof console == "object" && typeof console.log != "undefined") |
26 print(foo() ? "hello world" : "bad bad"); | 26 console.log(v0); |
27 }""",""" | 27 else if (!(typeof window == "object")) { |
28 function() { | 28 if (!(typeof print == "function")) |
29 P.print(V.foo() ? "hello world" : "bad bad"); | 29 throw "Unable to print message: " + String(v0); |
| 30 print(v0); |
| 31 } |
30 }"""), | 32 }"""), |
31 const TestEntry(""" | 33 const TestEntry(""" |
32 var x = 1; | 34 var x = 1; |
33 get foo => ++x > 10; | 35 get foo => ++x > 10; |
34 main() { | 36 main() { |
35 print(foo ? "hello world" : "bad bad"); | 37 print(foo ? "hello world" : "bad bad"); |
36 }""",""" | 38 }""",r""" |
37 function() { | 39 function() { |
38 P.print(V.foo() ? "hello world" : "bad bad"); | 40 var v0 = $.x + 1; |
| 41 $.x = v0; |
| 42 v0 = v0 > 10 ? "hello world" : "bad bad"; |
| 43 if (typeof dartPrint == "function") |
| 44 dartPrint(v0); |
| 45 else if (typeof console == "object" && typeof console.log != "undefined") |
| 46 console.log(v0); |
| 47 else if (!(typeof window == "object")) { |
| 48 if (!(typeof print == "function")) |
| 49 throw "Unable to print message: " + String(v0); |
| 50 print(v0); |
| 51 } |
39 }"""), | 52 }"""), |
40 const TestEntry(""" | 53 const TestEntry(""" |
41 var x = 1; | 54 var x = 1; |
42 get foo => ++x > 10; | 55 get foo => ++x > 10; |
43 main() { print(foo && foo); } | 56 main() { print(foo && foo); } |
44 """, """ | 57 """, r""" |
45 function() { | 58 function() { |
46 P.print(V.foo() ? !!V.foo() : false); | 59 var v0 = $.x + 1; |
| 60 $.x = v0; |
| 61 if (v0 > 10) { |
| 62 $.x = v0 = $.x + 1; |
| 63 v0 = v0 > 10; |
| 64 } else |
| 65 v0 = false; |
| 66 v0 = H.S(v0); |
| 67 if (typeof dartPrint == "function") |
| 68 dartPrint(v0); |
| 69 else if (typeof console == "object" && typeof console.log != "undefined") |
| 70 console.log(v0); |
| 71 else if (!(typeof window == "object")) { |
| 72 if (!(typeof print == "function")) |
| 73 throw "Unable to print message: " + String(v0); |
| 74 print(v0); |
| 75 } |
47 }"""), | 76 }"""), |
48 const TestEntry(""" | 77 const TestEntry(""" |
49 var x = 1; | 78 var x = 1; |
50 get foo => ++x > 10; | 79 get foo => ++x > 10; |
51 main() { print(foo || foo); } | 80 main() { print(foo || foo); } |
52 """,""" | 81 """,r""" |
53 function() { | 82 function() { |
54 P.print(V.foo() ? true : !!V.foo()); | 83 var v0 = $.x + 1; |
| 84 $.x = v0; |
| 85 if (v0 > 10) |
| 86 v0 = true; |
| 87 else { |
| 88 $.x = v0 = $.x + 1; |
| 89 v0 = v0 > 10; |
| 90 } |
| 91 v0 = H.S(v0); |
| 92 if (typeof dartPrint == "function") |
| 93 dartPrint(v0); |
| 94 else if (typeof console == "object" && typeof console.log != "undefined") |
| 95 console.log(v0); |
| 96 else if (!(typeof window == "object")) { |
| 97 if (!(typeof print == "function")) |
| 98 throw "Unable to print message: " + String(v0); |
| 99 print(v0); |
| 100 } |
55 }"""), | 101 }"""), |
56 const TestEntry(""" | 102 const TestEntry(""" |
57 get foo => foo; | 103 get foo => foo; |
58 main() { print(foo || foo); } | 104 main() { print(foo || foo); } |
59 """,""" | 105 """,""" |
60 function() { | 106 function() { |
61 V.foo(); | 107 V.foo(); |
62 }"""), | 108 }"""), |
63 | 109 |
64 // Needs interceptor calling convention | 110 // Needs interceptor calling convention |
(...skipping 12 matching lines...) Expand all Loading... |
77 //} | 123 //} |
78 //"""), | 124 //"""), |
79 | 125 |
80 const TestEntry(""" | 126 const TestEntry(""" |
81 main() { | 127 main() { |
82 var list = [1, 2, 3]; | 128 var list = [1, 2, 3]; |
83 list[1] = 6; | 129 list[1] = 6; |
84 print(list); | 130 print(list); |
85 }""", r""" | 131 }""", r""" |
86 function() { | 132 function() { |
87 var list = [1, 2, 3]; | 133 var list = [1, 2, 3], res, v0; |
88 list[1] = 6; | 134 list[1] = 6; |
89 P.print(list); | 135 if (!(typeof (res = C.JSArray_methods.toString$0(list)) === "string")) |
| 136 throw H.wrapException(H.argumentErrorValue(list)); |
| 137 v0 = res; |
| 138 if (typeof dartPrint == "function") |
| 139 dartPrint(v0); |
| 140 else if (typeof console == "object" && typeof console.log != "undefined") |
| 141 console.log(v0); |
| 142 else if (!(typeof window == "object")) { |
| 143 if (!(typeof print == "function")) |
| 144 throw "Unable to print message: " + String(v0); |
| 145 print(v0); |
| 146 } |
90 }"""), | 147 }"""), |
91 ]; | 148 ]; |
92 | 149 |
93 void main() { | 150 void main() { |
94 runTests(tests); | 151 runTests(tests); |
95 } | 152 } |
OLD | NEW |