| OLD | NEW |
| 1 import 'package:dev_compiler/src/js_ast/js_ast.dart'; | 1 import 'package:dev_compiler/src/js_ast/js_ast.dart'; |
| 2 import 'package:test/test.dart'; | 2 import 'package:test/test.dart'; |
| 3 | 3 |
| 4 final _prenumberedPlaceholders = new RegExp(r'#\d+'); | 4 final _prenumberedPlaceholders = new RegExp(r'#\d+'); |
| 5 | 5 |
| 6 _parser(String src) => | 6 _parser(String src) => |
| 7 new MiniJsParser(src.replaceAll(_prenumberedPlaceholders, '#')); | 7 new MiniJsParser(src.replaceAll(_prenumberedPlaceholders, '#')); |
| 8 | 8 |
| 9 _check(Node node, String expected) => | 9 _check(Node node, String expected) => |
| 10 expect(node.toString(), 'js_ast `$expected`'); | 10 expect(node.toString(), 'js_ast `$expected`'); |
| 11 | 11 |
| 12 _checkStatement(String src) => | 12 _checkStatement(String src) => _check(_parser(src).parseStatement(), src); |
| 13 _check(_parser(src).parseStatement(), src); | |
| 14 | 13 |
| 15 _checkExpression(String src) => | 14 _checkExpression(String src) => _check(_parser(src).parseExpression(), src); |
| 16 _check(_parser(src).parseExpression(), src); | |
| 17 | 15 |
| 18 main() { | 16 main() { |
| 19 group('MiniJsParser', () { | 17 group('MiniJsParser', () { |
| 20 // TODO(ochafik): Add more coverage. | 18 // TODO(ochafik): Add more coverage. |
| 21 test('parses classes with complex members', () { | 19 test('parses classes with complex members', () { |
| 22 _checkExpression( | 20 _checkExpression('class Foo {\n' |
| 23 'class Foo {\n' | |
| 24 ' [foo](...args) {}\n' | 21 ' [foo](...args) {}\n' |
| 25 ' [#0](x) {}\n' | 22 ' [#0](x) {}\n' |
| 26 ' static [foo](...args) {}\n' | 23 ' static [foo](...args) {}\n' |
| 27 ' static [#1](x) {}\n' | 24 ' static [#1](x) {}\n' |
| 28 ' get [foo]() {}\n' | 25 ' get [foo]() {}\n' |
| 29 ' get [#2]() {}\n' | 26 ' get [#2]() {}\n' |
| 30 ' static get [foo]() {}\n' | 27 ' static get [foo]() {}\n' |
| 31 ' static get [#3]() {}\n' | 28 ' static get [#3]() {}\n' |
| 32 ' set [foo](v) {}\n' | 29 ' set [foo](v) {}\n' |
| 33 ' set [#4](v) {}\n' | 30 ' set [#4](v) {}\n' |
| 34 ' static set [foo](v) {}\n' | 31 ' static set [foo](v) {}\n' |
| 35 ' static set [#5](v) {}\n' | 32 ' static set [#5](v) {}\n' |
| 36 '}'); | 33 '}'); |
| 37 }); | 34 }); |
| 38 test('parses statements', () { | 35 test('parses statements', () { |
| 39 _checkStatement('for (let i = 0; i < 10; i++) {\n}\n'); | 36 _checkStatement('for (let i = 0; i < 10; i++) {\n}\n'); |
| 40 _checkStatement('for (let i = 0, j = 1; i < 10; i++) {\n}\n'); | 37 _checkStatement('for (let i = 0, j = 1; i < 10; i++) {\n}\n'); |
| 41 _checkStatement('var [x, y = []] = list;\n'); | 38 _checkStatement('var [x, y = []] = list;\n'); |
| 42 _checkStatement('var {x, y = {x: y}} = obj;\n'); | 39 _checkStatement('var {x, y = {x: y}} = obj;\n'); |
| 43 }); | 40 }); |
| 44 }); | 41 }); |
| 45 } | 42 } |
| OLD | NEW |