| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 index(ident('c'), ident('d')))); | 152 index(ident('c'), ident('d')))); |
| 153 }); | 153 }); |
| 154 | 154 |
| 155 test('should parse ternary operators', () { | 155 test('should parse ternary operators', () { |
| 156 expectParse('a ? b : c', ternary(ident('a'), ident('b'), ident('c'))); | 156 expectParse('a ? b : c', ternary(ident('a'), ident('b'), ident('c'))); |
| 157 expectParse('a.a ? b.a : c.a', ternary(getter(ident('a'), 'a'), | 157 expectParse('a.a ? b.a : c.a', ternary(getter(ident('a'), 'a'), |
| 158 getter(ident('b'), 'a'), getter(ident('c'), 'a'))); | 158 getter(ident('b'), 'a'), getter(ident('c'), 'a'))); |
| 159 expect(() => parse('a + 1 ? b + 1 :: c.d + 3'), throws); | 159 expect(() => parse('a + 1 ? b + 1 :: c.d + 3'), throws); |
| 160 }); | 160 }); |
| 161 | 161 |
| 162 test('ternary operators have lowest associativity', () { |
| 163 expectParse('a == b ? c + d : e - f', ternary( |
| 164 binary(ident('a'), '==', ident('b')), |
| 165 binary(ident('c'), '+', ident('d')), |
| 166 binary(ident('e'), '-', ident('f')))); |
| 167 |
| 168 expectParse('a.x == b.y ? c + d : e - f', ternary( |
| 169 binary(getter(ident('a'), 'x'), '==', getter(ident('b'), 'y')), |
| 170 binary(ident('c'), '+', ident('d')), |
| 171 binary(ident('e'), '-', ident('f')))); |
| 172 |
| 173 expectParse('a.x == b.y ? c + d : e - f', ternary( |
| 174 binary(getter(ident('a'), 'x'), '==', getter(ident('b'), 'y')), |
| 175 binary(ident('c'), '+', ident('d')), |
| 176 binary(ident('e'), '-', ident('f')))); |
| 177 }); |
| 178 |
| 162 test('should parse a filter chain', () { | 179 test('should parse a filter chain', () { |
| 163 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), | 180 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), |
| 164 '|', ident('c'))); | 181 '|', ident('c'))); |
| 165 }); | 182 }); |
| 166 | 183 |
| 167 test('should parse comprehension', () { | 184 test('should parse comprehension', () { |
| 168 expectParse('a in b', inExpr(ident('a'), ident('b'))); | 185 expectParse('a in b', inExpr(ident('a'), ident('b'))); |
| 169 expectParse('a in b.c', | 186 expectParse('a in b.c', |
| 170 inExpr(ident('a'), getter(ident('b'), 'c'))); | 187 inExpr(ident('a'), getter(ident('b'), 'c'))); |
| 171 expectParse('a in b + c', | 188 expectParse('a in b + c', |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 221 |
| 205 test('should parse list literals', () { | 222 test('should parse list literals', () { |
| 206 expectParse('[1, "a", b]', | 223 expectParse('[1, "a", b]', |
| 207 listLiteral([literal(1), literal('a'), ident('b')])); | 224 listLiteral([literal(1), literal('a'), ident('b')])); |
| 208 expectParse('[[1, 2], [3, 4]]', | 225 expectParse('[[1, 2], [3, 4]]', |
| 209 listLiteral([listLiteral([literal(1), literal(2)]), | 226 listLiteral([listLiteral([literal(1), literal(2)]), |
| 210 listLiteral([literal(3), literal(4)])])); | 227 listLiteral([literal(3), literal(4)])])); |
| 211 }); | 228 }); |
| 212 }); | 229 }); |
| 213 } | 230 } |
| OLD | NEW |