| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library parser_test; | 5 library parser_test; |
| 6 | 6 |
| 7 import 'package:polymer_expressions/parser.dart'; | 7 import 'package:polymer_expressions/parser.dart'; |
| 8 import 'package:polymer_expressions/expression.dart'; | 8 import 'package:polymer_expressions/expression.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 }); | 45 }); |
| 46 | 46 |
| 47 test('should parse a positive double literal', () { | 47 test('should parse a positive double literal', () { |
| 48 expectParse('+1.23', literal(1.23)); | 48 expectParse('+1.23', literal(1.23)); |
| 49 }); | 49 }); |
| 50 | 50 |
| 51 test('should parse a negative double literal', () { | 51 test('should parse a negative double literal', () { |
| 52 expectParse('-1.23', literal(-1.23)); | 52 expectParse('-1.23', literal(-1.23)); |
| 53 }); | 53 }); |
| 54 | 54 |
| 55 test('should parse a plus operator with literals', () { | |
| 56 expectParse('1 + 2', binary(literal(1), '+', literal(2))); | |
| 57 }); | |
| 58 | |
| 59 test('should parse binary operators', () { | 55 test('should parse binary operators', () { |
| 60 expectParse('a && b', binary(ident('a'), '&&', ident('b'))); | 56 var operators = ['+', '-', '*', '/', '%', '^', '==', '!=', '>', '<', |
| 61 expectParse('1 && 2', binary(literal(1), '&&', literal(2))); | 57 '>=', '<=', '||', '&&', '&']; |
| 62 expectParse('false && true', binary(literal(false), '&&', literal(true))); | 58 for (var op in operators) { |
| 63 expectParse('false || true', binary(literal(false), '||', literal(true))); | 59 expectParse('a $op b', binary(ident('a'), op, ident('b'))); |
| 60 expectParse('1 $op 2', binary(literal(1), op, literal(2))); |
| 61 expectParse('this $op null', binary(ident('this'), op, literal(null))); |
| 62 } |
| 64 }); | 63 }); |
| 65 | 64 |
| 66 test('should give multiply higher associativity than plus', () { | 65 test('should give multiply higher associativity than plus', () { |
| 67 expectParse('a + b * c', | 66 expectParse('a + b * c', |
| 68 binary( | 67 binary( |
| 69 ident('a'), | 68 ident('a'), |
| 70 '+', | 69 '+', |
| 71 binary(ident('b'), '*', ident('c')))); | 70 binary(ident('b'), '*', ident('c')))); |
| 72 }); | 71 }); |
| 73 | 72 |
| 74 test('should give multiply higher associativity than plus 2', () { | |
| 75 expectParse('a * b + c', | |
| 76 binary( | |
| 77 binary(ident('a'), '*', ident('b')), | |
| 78 '+', | |
| 79 ident('c'))); | |
| 80 }); | |
| 81 | |
| 82 test('should parse a dot operator', () { | 73 test('should parse a dot operator', () { |
| 83 expectParse('a.b', getter(ident('a'), 'b')); | 74 expectParse('a.b', getter(ident('a'), 'b')); |
| 84 }); | 75 }); |
| 85 | 76 |
| 86 test('should parse chained dot operators', () { | 77 test('should parse chained dot operators', () { |
| 87 expectParse('a.b.c', getter(getter(ident('a'), 'b'), 'c')); | 78 expectParse('a.b.c', getter(getter(ident('a'), 'b'), 'c')); |
| 88 }); | 79 }); |
| 89 | 80 |
| 90 test('should give dot high associativity', () { | 81 test('should give dot high associativity', () { |
| 91 expectParse('a * b.c', binary(ident('a'), '*', getter(ident('b'), 'c'))); | 82 expectParse('a * b.c', binary(ident('a'), '*', getter(ident('b'), 'c'))); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 204 |
| 214 test('should parse list literals', () { | 205 test('should parse list literals', () { |
| 215 expectParse('[1, "a", b]', | 206 expectParse('[1, "a", b]', |
| 216 listLiteral([literal(1), literal('a'), ident('b')])); | 207 listLiteral([literal(1), literal('a'), ident('b')])); |
| 217 expectParse('[[1, 2], [3, 4]]', | 208 expectParse('[[1, 2], [3, 4]]', |
| 218 listLiteral([listLiteral([literal(1), literal(2)]), | 209 listLiteral([listLiteral([literal(1), literal(2)]), |
| 219 listLiteral([literal(3), literal(4)])])); | 210 listLiteral([literal(3), literal(4)])])); |
| 220 }); | 211 }); |
| 221 }); | 212 }); |
| 222 } | 213 } |
| OLD | NEW |