| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 import 'mock_compiler.dart'; | 5 import 'mock_compiler.dart'; |
| 6 import '../../../sdk/lib/_internal/compiler/implementation/js/js.dart' as jsAst; | 6 import '../../../sdk/lib/_internal/compiler/implementation/js/js.dart' as jsAst; |
| 7 import '../../../sdk/lib/_internal/compiler/implementation/js/js.dart' show js; | 7 import '../../../sdk/lib/_internal/compiler/implementation/js/js.dart' show js; |
| 8 | 8 |
| 9 void testExpression(String expression, [String expect = ""]) { | 9 void testExpression(String expression, [String expect = ""]) { |
| 10 jsAst.Node node = js[expression]; | 10 jsAst.Node node = js(expression); |
| 11 MockCompiler compiler = new MockCompiler(); | 11 MockCompiler compiler = new MockCompiler(); |
| 12 String jsText = | 12 String jsText = |
| 13 jsAst.prettyPrint(node, | 13 jsAst.prettyPrint(node, |
| 14 compiler, | 14 compiler, |
| 15 allowVariableMinification: false).getText(); | 15 allowVariableMinification: false).getText(); |
| 16 if (expect == "") { | 16 if (expect == "") { |
| 17 Expect.stringEquals(expression, jsText); | 17 Expect.stringEquals(expression, jsText); |
| 18 } else { | 18 } else { |
| 19 Expect.stringEquals(expect, jsText); | 19 Expect.stringEquals(expect, jsText); |
| 20 } | 20 } |
| 21 } | 21 } |
| 22 | 22 |
| 23 void testError(String expression, [String expect = ""]) { | 23 void testError(String expression, [String expect = ""]) { |
| 24 bool doCheck(exception) { | 24 bool doCheck(exception) { |
| 25 Expect.isTrue(exception.toString().contains(expect)); | 25 Expect.isTrue(exception.toString().contains(expect)); |
| 26 return true; | 26 return true; |
| 27 } | 27 } |
| 28 Expect.throws(() => js[expression], doCheck); | 28 Expect.throws(() => js(expression), doCheck); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 | 32 |
| 33 void main() { | 33 void main() { |
| 34 // Asterisk indicates deviations from real JS. | 34 // Asterisk indicates deviations from real JS. |
| 35 // Simple var test. | 35 // Simple var test. |
| 36 testExpression('var a = ""'); | 36 testExpression('var a = ""'); |
| 37 // Parse and print will normalize whitespace. | 37 // Parse and print will normalize whitespace. |
| 38 testExpression(' var a = "" ', 'var a = ""'); | 38 testExpression(' var a = "" ', 'var a = ""'); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 testExpression("y = a == null ? b : a"); | 147 testExpression("y = a == null ? b : a"); |
| 148 testExpression("y = a == null ? b + c : a + c"); | 148 testExpression("y = a == null ? b + c : a + c"); |
| 149 testExpression("foo = a ? b : c ? d : e"); | 149 testExpression("foo = a ? b : c ? d : e"); |
| 150 testExpression("foo = a ? b ? c : d : e"); | 150 testExpression("foo = a ? b ? c : d : e"); |
| 151 testExpression("foo = (a = v) ? b = w : c = x ? d = y : e = z"); | 151 testExpression("foo = (a = v) ? b = w : c = x ? d = y : e = z"); |
| 152 testExpression("foo = (a = v) ? b = w ? c = x : d = y : e = z"); | 152 testExpression("foo = (a = v) ? b = w ? c = x : d = y : e = z"); |
| 153 // Stacked assignment. | 153 // Stacked assignment. |
| 154 testExpression("a = b = c"); | 154 testExpression("a = b = c"); |
| 155 testExpression("var a = b = c"); | 155 testExpression("var a = b = c"); |
| 156 } | 156 } |
| OLD | NEW |