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

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

Issue 74543003: Split out Index AST node from Invoke (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Split out Getter too Created 7 years, 1 month 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 test('should give multiply higher associativity than plus 2', () { 74 test('should give multiply higher associativity than plus 2', () {
75 expectParse('a * b + c', 75 expectParse('a * b + c',
76 binary( 76 binary(
77 binary(ident('a'), '*', ident('b')), 77 binary(ident('a'), '*', ident('b')),
78 '+', 78 '+',
79 ident('c'))); 79 ident('c')));
80 }); 80 });
81 81
82 test('should parse a dot operator', () { 82 test('should parse a dot operator', () {
83 expectParse('a.b', invoke(ident('a'), 'b')); 83 expectParse('a.b', getter(ident('a'), 'b'));
84 }); 84 });
85 85
86 test('should parse chained dot operators', () { 86 test('should parse chained dot operators', () {
87 expectParse('a.b.c', invoke(invoke(ident('a'), 'b'), 'c')); 87 expectParse('a.b.c', getter(getter(ident('a'), 'b'), 'c'));
88 }); 88 });
89 89
90 test('should give dot high associativity', () { 90 test('should give dot high associativity', () {
91 expectParse('a * b.c', binary(ident('a'), '*', invoke(ident('b'), 'c'))); 91 expectParse('a * b.c', binary(ident('a'), '*', getter(ident('b'), 'c')));
92 }); 92 });
93 93
94 test('should parse a function with no arguments', () { 94 test('should parse a function with no arguments', () {
95 expectParse('a()', invoke(ident('a'), null, [])); 95 expectParse('a()', invoke(ident('a'), null, []));
96 }); 96 });
97 97
98 test('should parse a single function argument', () { 98 test('should parse a single function argument', () {
99 expectParse('a(b)', invoke(ident('a'), null, [ident('b')])); 99 expectParse('a(b)', invoke(ident('a'), null, [ident('b')]));
100 }); 100 });
101 101
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 }); 139 });
140 140
141 test('should parse parenthesized expression', () { 141 test('should parse parenthesized expression', () {
142 expectParse('(a)', paren(ident('a'))); 142 expectParse('(a)', paren(ident('a')));
143 expectParse('(( 3 * ((1 + 2)) ))', paren(paren( 143 expectParse('(( 3 * ((1 + 2)) ))', paren(paren(
144 binary(literal(3), '*', paren(paren( 144 binary(literal(3), '*', paren(paren(
145 binary(literal(1), '+', literal(2)))))))); 145 binary(literal(1), '+', literal(2))))))));
146 }); 146 });
147 147
148 test('should parse an index operator', () { 148 test('should parse an index operator', () {
149 expectParse('a[b]', invoke(ident('a'), '[]', [ident('b')])); 149 expectParse('a[b]', index(ident('a'), ident('b')));
150 expectParse('a.b[c]', invoke(invoke(ident('a'), 'b', null), 150 expectParse('a.b[c]', index(getter(ident('a'), 'b'), ident('c')));
151 '[]', [ident('c')]));
152 }); 151 });
153 152
154 test('should parse chained index operators', () { 153 test('should parse chained index operators', () {
155 expectParse('a[][]', invoke(invoke(ident('a'), '[]', []), '[]', [])); 154 expectParse('a[][]', index(index(ident('a'), null), null));
156 }); 155 });
157 156
158 test('should parse multiple index operators', () { 157 test('should parse multiple index operators', () {
159 expectParse('a[b] + c[d]', binary( 158 expectParse('a[b] + c[d]', binary(
160 invoke(ident('a'), '[]', [ident('b')]), 159 index(ident('a'), ident('b')),
161 '+', 160 '+',
162 invoke(ident('c'), '[]', [ident('d')]))); 161 index(ident('c'), ident('d'))));
163 }); 162 });
164 163
165 test('should parse a filter chain', () { 164 test('should parse a filter chain', () {
166 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')), 165 expectParse('a | b | c', binary(binary(ident('a'), '|', ident('b')),
167 '|', ident('c'))); 166 '|', ident('c')));
168 }); 167 });
169 168
170 test('should parse comprehension', () { 169 test('should parse comprehension', () {
171 expectParse('a in b', inExpr(ident('a'), ident('b'))); 170 expectParse('a in b', inExpr(ident('a'), ident('b')));
172 expectParse('a in b.c', 171 expectParse('a in b.c',
173 inExpr(ident('a'), invoke(ident('b'), 'c', null))); 172 inExpr(ident('a'), getter(ident('b'), 'c')));
174 expectParse('a in b + c', 173 expectParse('a in b + c',
175 inExpr(ident('a'), binary(ident('b'), '+', ident('c')))); 174 inExpr(ident('a'), binary(ident('b'), '+', ident('c'))));
176 }); 175 });
177 176
178 test('should reject comprehension with non-assignable left expression', () { 177 test('should reject comprehension with non-assignable left expression', () {
179 expect(() => parse('a + 1 in b'), throwsException); 178 expect(() => parse('a + 1 in b'), throwsException);
180 }); 179 });
181 180
182 test('should reject keywords as identifiers', () { 181 test('should reject keywords as identifiers', () {
183 expect(() => parse('a.in'), throwsException); 182 expect(() => parse('a.in'), throwsException);
(...skipping 10 matching lines...) Expand all
194 expectParse("{'a': foo()}", 193 expectParse("{'a': foo()}",
195 mapLiteral([mapLiteralEntry( 194 mapLiteral([mapLiteralEntry(
196 literal('a'), invoke(ident('foo'), null, []))])); 195 literal('a'), invoke(ident('foo'), null, []))]));
197 expectParse("{'a': foo('a')}", 196 expectParse("{'a': foo('a')}",
198 mapLiteral([mapLiteralEntry( 197 mapLiteral([mapLiteralEntry(
199 literal('a'), invoke(ident('foo'), null, [literal('a')]))])); 198 literal('a'), invoke(ident('foo'), null, [literal('a')]))]));
200 }); 199 });
201 200
202 test('should parse map literals with method calls', () { 201 test('should parse map literals with method calls', () {
203 expectParse("{'a': 1}.length", 202 expectParse("{'a': 1}.length",
204 invoke(mapLiteral([mapLiteralEntry(literal('a'), literal(1))]), 203 getter(mapLiteral([mapLiteralEntry(literal('a'), literal(1))]),
205 'length')); 204 'length'));
206 }); 205 });
207 }); 206 });
208 } 207 }
OLDNEW
« pkg/polymer_expressions/lib/eval.dart ('K') | « pkg/polymer_expressions/lib/visitor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698