Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: pkg/polymer_expressions/test/parser_test.dart

Issue 141703024: Refactor of PolymerExpressions. Adds "as" expressions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 expectParse('a.a ? b.a : c.a', ternary(getter(ident('a'), 'a'), 156 expectParse('a.a ? b.a : c.a', ternary(getter(ident('a'), 'a'),
158 getter(ident('b'), 'a'), getter(ident('c'), 'a'))); 157 getter(ident('b'), 'a'), getter(ident('c'), 'a')));
159 expect(() => parse('a + 1 ? b + 1 :: c.d + 3'), throws); 158 expect(() => parse('a + 1 ? b + 1 :: c.d + 3'), throws);
160 }); 159 });
161 160
162 test('should parse a filter chain', () { 161 test('should parse a filter chain', () {
163 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), 162 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')),
164 '|', ident('c'))); 163 '|', ident('c')));
165 }); 164 });
166 165
167 test('should parse comprehension', () { 166 test('should parse "in" expression', () {
168 expectParse('a in b', inExpr(ident('a'), ident('b'))); 167 expectParse('a in b', inExpr(ident('a'), ident('b')));
169 expectParse('a in b.c', 168 expectParse('a in b.c',
170 inExpr(ident('a'), getter(ident('b'), 'c'))); 169 inExpr(ident('a'), getter(ident('b'), 'c')));
171 expectParse('a in b + c', 170 expectParse('a in b + c',
172 inExpr(ident('a'), binary(ident('b'), '+', ident('c')))); 171 inExpr(ident('a'), binary(ident('b'), '+', ident('c'))));
173 }); 172 });
174 173
175 test('should reject comprehension with non-assignable left expression', () { 174 test('should reject comprehension with non-assignable left expression', () {
176 expect(() => parse('a + 1 in b'), throwsException); 175 expect(() => parse('a + 1 in b'), throwsException);
177 }); 176 });
178 177
178 test('should parse "as" expressions', () {
179 expectParse('a as b', asExpr(ident('a'), ident('b')));
180 });
181
179 test('should reject keywords as identifiers', () { 182 test('should reject keywords as identifiers', () {
180 expect(() => parse('a.in'), throwsException); 183 expect(() => parse('a.in'), throws);
184 expect(() => parse('a.as'), throws);
185 // TODO: re-enable when 'this' is a keyword
186 // expect(() => parse('a.this'), throws);
181 }); 187 });
182 188
183 test('should parse map literals', () { 189 test('should parse map literals', () {
184 expectParse("{'a': 1}", 190 expectParse("{'a': 1}",
185 mapLiteral([mapLiteralEntry(literal('a'), literal(1))])); 191 mapLiteral([mapLiteralEntry(literal('a'), literal(1))]));
186 expectParse("{'a': 1, 'b': 2 + 3}", 192 expectParse("{'a': 1, 'b': 2 + 3}",
187 mapLiteral([ 193 mapLiteral([
188 mapLiteralEntry(literal('a'), literal(1)), 194 mapLiteralEntry(literal('a'), literal(1)),
189 mapLiteralEntry(literal('b'), 195 mapLiteralEntry(literal('b'),
190 binary(literal(2), '+', literal(3)))])); 196 binary(literal(2), '+', literal(3)))]));
(...skipping 13 matching lines...) Expand all
204 210
205 test('should parse list literals', () { 211 test('should parse list literals', () {
206 expectParse('[1, "a", b]', 212 expectParse('[1, "a", b]',
207 listLiteral([literal(1), literal('a'), ident('b')])); 213 listLiteral([literal(1), literal('a'), ident('b')]));
208 expectParse('[[1, 2], [3, 4]]', 214 expectParse('[[1, 2], [3, 4]]',
209 listLiteral([listLiteral([literal(1), literal(2)]), 215 listLiteral([listLiteral([literal(1), literal(2)]),
210 listLiteral([literal(3), literal(4)])])); 216 listLiteral([literal(3), literal(4)])]));
211 }); 217 });
212 }); 218 });
213 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698