Chromium Code Reviews| 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'package:expect/expect.dart'; | 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 import 'mock_compiler.dart'; | 8 import 'mock_compiler.dart'; |
| 9 import 'package:compiler/src/js/js.dart' as jsAst; | 9 import 'package:compiler/src/js/js.dart' as jsAst; |
| 10 import 'package:compiler/src/js/js.dart' show js; | 10 import 'package:compiler/src/js/js.dart' show js; |
| 11 | 11 |
| 12 Future testExpression(String expression, [String expect = ""]) { | 12 Future testExpression(String expression, [String expect = ""]) { |
| 13 print("About to parse $expression"); | |
|
floitsch
2014/12/01 13:03:29
Remove debug prints.
sigurdm
2014/12/02 09:27:31
Done.
| |
| 13 jsAst.Node node = js(expression); | 14 jsAst.Node node = js(expression); |
| 15 print(""); | |
| 14 return MockCompiler.create((MockCompiler compiler) { | 16 return MockCompiler.create((MockCompiler compiler) { |
| 15 String jsText = | 17 String jsText = |
| 16 jsAst.prettyPrint(node, | 18 jsAst.prettyPrint(node, |
| 17 compiler, | 19 compiler, |
| 18 allowVariableMinification: false).getText(); | 20 allowVariableMinification: false).getText(); |
| 21 print("got '$jsText'"); | |
| 19 if (expect == "") { | 22 if (expect == "") { |
| 20 Expect.stringEquals(expression, jsText); | 23 Expect.stringEquals(expression, jsText); |
| 21 } else { | 24 } else { |
| 22 Expect.stringEquals(expect, jsText); | 25 Expect.stringEquals(expect, jsText); |
| 23 } | 26 } |
| 24 }); | 27 }); |
| 25 } | 28 } |
| 26 | 29 |
| 27 Future testError(String expression, [String expect = ""]) { | 30 Future testError(String expression, [String expect = ""]) { |
| 28 return new Future.sync(() { | 31 return new Future.sync(() { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 testError("x++ ++ 42"), | 170 testError("x++ ++ 42"), |
| 168 // Shift operators. | 171 // Shift operators. |
| 169 testExpression("x << 5"), | 172 testExpression("x << 5"), |
| 170 testExpression("x << y + 1"), | 173 testExpression("x << y + 1"), |
| 171 testExpression("x <<= y + 1"), | 174 testExpression("x <<= y + 1"), |
| 172 // Array initializers. | 175 // Array initializers. |
| 173 testExpression("x = ['foo', 'bar', x[4]]"), | 176 testExpression("x = ['foo', 'bar', x[4]]"), |
| 174 testExpression("[]"), | 177 testExpression("[]"), |
| 175 testError("[42 42]"), | 178 testError("[42 42]"), |
| 176 testExpression('beebop([1, 2, 3])'), | 179 testExpression('beebop([1, 2, 3])'), |
| 177 // *We can't parse array literals with holes in them. | 180 // Array literals with holes in them. |
| 178 testError("[1,, 2]"), | 181 testExpression("[1,, 2]"), |
| 179 testError("[1,]"), | 182 testExpression("[1,]", "[1]"), |
| 180 testError("[,]"), | 183 testExpression("[1,,]", "[1,,]"), |
| 181 testError("[, 42]"), | 184 testExpression("[,]"), |
| 185 testExpression("[,,]"), | |
| 186 testExpression("[, 42]"), | |
| 182 // Ternary operator. | 187 // Ternary operator. |
| 183 testExpression("x = a ? b : c"), | 188 testExpression("x = a ? b : c"), |
| 184 testExpression("y = a == null ? b : a"), | 189 testExpression("y = a == null ? b : a"), |
| 185 testExpression("y = a == null ? b + c : a + c"), | 190 testExpression("y = a == null ? b + c : a + c"), |
| 186 testExpression("foo = a ? b : c ? d : e"), | 191 testExpression("foo = a ? b : c ? d : e"), |
| 187 testExpression("foo = a ? b ? c : d : e"), | 192 testExpression("foo = a ? b ? c : d : e"), |
| 188 testExpression("foo = (a = v) ? b = w : c = x ? d = y : e = z"), | 193 testExpression("foo = (a = v) ? b = w : c = x ? d = y : e = z"), |
| 189 testExpression("foo = (a = v) ? b = w ? c = x : d = y : e = z"), | 194 testExpression("foo = (a = v) ? b = w ? c = x : d = y : e = z"), |
| 190 // Stacked assignment. | 195 // Stacked assignment. |
| 191 testExpression("a = b = c"), | 196 testExpression("a = b = c"), |
| 192 testExpression("var a = b = c"), | 197 testExpression("var a = b = c"), |
| 193 ])); | 198 ])); |
| 194 } | 199 } |
| OLD | NEW |