| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 '>=', '<=', '||', '&&', '&']; | 57 '>=', '<=', '||', '&&', '&']; |
| 58 for (var op in operators) { | 58 for (var op in operators) { |
| 59 expectParse('a $op b', binary(ident('a'), op, ident('b'))); | 59 expectParse('a $op b', binary(ident('a'), op, ident('b'))); |
| 60 expectParse('1 $op 2', binary(literal(1), op, literal(2))); | 60 expectParse('1 $op 2', binary(literal(1), op, literal(2))); |
| 61 expectParse('this $op null', binary(ident('this'), op, literal(null))); | 61 expectParse('this $op null', binary(ident('this'), op, literal(null))); |
| 62 } | 62 } |
| 63 }); | 63 }); |
| 64 | 64 |
| 65 test('should give multiply higher associativity than plus', () { | 65 test('should give multiply higher associativity than plus', () { |
| 66 expectParse('a + b * c', | 66 expectParse('a + b * c', |
| 67 binary( | 67 binary(ident('a'), '+', binary(ident('b'), '*', ident('c')))); |
| 68 ident('a'), | 68 expectParse('a * b + c', |
| 69 '+', | 69 binary(binary(ident('a'), '*', ident('b')), '+', ident('c'))); |
| 70 binary(ident('b'), '*', ident('c')))); | |
| 71 }); | 70 }); |
| 72 | 71 |
| 73 test('should parse a dot operator', () { | 72 test('should parse a dot operator', () { |
| 74 expectParse('a.b', getter(ident('a'), 'b')); | 73 expectParse('a.b', getter(ident('a'), 'b')); |
| 75 }); | 74 }); |
| 76 | 75 |
| 77 test('should parse chained dot operators', () { | 76 test('should parse chained dot operators', () { |
| 78 expectParse('a.b.c', getter(getter(ident('a'), 'b'), 'c')); | 77 expectParse('a.b.c', getter(getter(ident('a'), 'b'), 'c')); |
| 79 }); | 78 }); |
| 80 | 79 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 binary(getter(ident('a'), 'x'), '==', getter(ident('b'), 'y')), | 173 binary(getter(ident('a'), 'x'), '==', getter(ident('b'), 'y')), |
| 175 binary(ident('c'), '+', ident('d')), | 174 binary(ident('c'), '+', ident('d')), |
| 176 binary(ident('e'), '-', ident('f')))); | 175 binary(ident('e'), '-', ident('f')))); |
| 177 }); | 176 }); |
| 178 | 177 |
| 179 test('should parse a filter chain', () { | 178 test('should parse a filter chain', () { |
| 180 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), | 179 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), |
| 181 '|', ident('c'))); | 180 '|', ident('c'))); |
| 182 }); | 181 }); |
| 183 | 182 |
| 184 test('should parse comprehension', () { | 183 test('should parse "in" expression', () { |
| 185 expectParse('a in b', inExpr(ident('a'), ident('b'))); | 184 expectParse('a in b', inExpr(ident('a'), ident('b'))); |
| 186 expectParse('a in b.c', | 185 expectParse('a in b.c', |
| 187 inExpr(ident('a'), getter(ident('b'), 'c'))); | 186 inExpr(ident('a'), getter(ident('b'), 'c'))); |
| 188 expectParse('a in b + c', | 187 expectParse('a in b + c', |
| 189 inExpr(ident('a'), binary(ident('b'), '+', ident('c')))); | 188 inExpr(ident('a'), binary(ident('b'), '+', ident('c')))); |
| 190 }); | 189 }); |
| 191 | 190 |
| 192 test('should reject comprehension with non-assignable left expression', () { | 191 test('should reject comprehension with non-assignable left expression', () { |
| 193 expect(() => parse('a + 1 in b'), throwsException); | 192 expect(() => parse('a + 1 in b'), throwsException); |
| 194 }); | 193 }); |
| 195 | 194 |
| 196 test('should reject keywords as identifiers', () { | 195 test('should parse "as" expressions', () { |
| 197 expect(() => parse('a.in'), throwsException); | 196 expectParse('a as b', asExpr(ident('a'), ident('b'))); |
| 197 }); |
| 198 |
| 199 skip_test('should reject keywords as identifiers', () { |
| 200 expect(() => parse('a.in'), throws); |
| 201 expect(() => parse('a.as'), throws); |
| 202 // TODO: re-enable when 'this' is a keyword |
| 203 // expect(() => parse('a.this'), throws); |
| 198 }); | 204 }); |
| 199 | 205 |
| 200 test('should parse map literals', () { | 206 test('should parse map literals', () { |
| 201 expectParse("{'a': 1}", | 207 expectParse("{'a': 1}", |
| 202 mapLiteral([mapLiteralEntry(literal('a'), literal(1))])); | 208 mapLiteral([mapLiteralEntry(literal('a'), literal(1))])); |
| 203 expectParse("{'a': 1, 'b': 2 + 3}", | 209 expectParse("{'a': 1, 'b': 2 + 3}", |
| 204 mapLiteral([ | 210 mapLiteral([ |
| 205 mapLiteralEntry(literal('a'), literal(1)), | 211 mapLiteralEntry(literal('a'), literal(1)), |
| 206 mapLiteralEntry(literal('b'), | 212 mapLiteralEntry(literal('b'), |
| 207 binary(literal(2), '+', literal(3)))])); | 213 binary(literal(2), '+', literal(3)))])); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 221 | 227 |
| 222 test('should parse list literals', () { | 228 test('should parse list literals', () { |
| 223 expectParse('[1, "a", b]', | 229 expectParse('[1, "a", b]', |
| 224 listLiteral([literal(1), literal('a'), ident('b')])); | 230 listLiteral([literal(1), literal('a'), ident('b')])); |
| 225 expectParse('[[1, 2], [3, 4]]', | 231 expectParse('[[1, 2], [3, 4]]', |
| 226 listLiteral([listLiteral([literal(1), literal(2)]), | 232 listLiteral([listLiteral([literal(1), literal(2)]), |
| 227 listLiteral([literal(3), literal(4)])])); | 233 listLiteral([literal(3), literal(4)])])); |
| 228 }); | 234 }); |
| 229 }); | 235 }); |
| 230 } | 236 } |
| OLD | NEW |