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

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

Issue 131623004: Ternary operator support for polymer_expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 tokenizer_test; 5 library tokenizer_test;
6 6
7 import 'package:polymer_expressions/tokenizer.dart'; 7 import 'package:polymer_expressions/tokenizer.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 main() { 10 main() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 t(IDENTIFIER_TOKEN, 'b')]); 51 t(IDENTIFIER_TOKEN, 'b')]);
52 }); 52 });
53 53
54 test('should tokenize a logical and operator', () { 54 test('should tokenize a logical and operator', () {
55 expectTokens('a && b', [ 55 expectTokens('a && b', [
56 t(IDENTIFIER_TOKEN, 'a'), 56 t(IDENTIFIER_TOKEN, 'a'),
57 t(OPERATOR_TOKEN, '&&'), 57 t(OPERATOR_TOKEN, '&&'),
58 t(IDENTIFIER_TOKEN, 'b')]); 58 t(IDENTIFIER_TOKEN, 'b')]);
59 }); 59 });
60 60
61 test('should tokenize a ternary operator', () {
62 expectTokens('a ? b : c', [
63 t(IDENTIFIER_TOKEN, 'a'),
64 t(OPERATOR_TOKEN, '?'),
65 t(IDENTIFIER_TOKEN, 'b'),
66 t(COLON_TOKEN, ':'),
67 t(IDENTIFIER_TOKEN, 'c')]);
68 });
69
61 test('should tokenize an iterate expression with "in" keyword', () { 70 test('should tokenize an iterate expression with "in" keyword', () {
62 expectTokens('item in items', [ 71 expectTokens('item in items', [
63 t(IDENTIFIER_TOKEN, 'item'), 72 t(IDENTIFIER_TOKEN, 'item'),
64 t(KEYWORD_TOKEN, 'in'), 73 t(KEYWORD_TOKEN, 'in'),
65 t(IDENTIFIER_TOKEN, 'items')]); 74 t(IDENTIFIER_TOKEN, 'items')]);
66 }); 75 });
67 76
68 test('should tokenize keywords', () { 77 test('should tokenize keywords', () {
69 expectTokens('in', [t(KEYWORD_TOKEN, 'in')]); 78 expectTokens('in', [t(KEYWORD_TOKEN, 'in')]);
70 expectTokens('this', [t(KEYWORD_TOKEN, 'this')]); 79 expectTokens('this', [t(KEYWORD_TOKEN, 'this')]);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 class MatcherList extends Matcher { 155 class MatcherList extends Matcher {
147 final List<Matcher> matchers; 156 final List<Matcher> matchers;
148 157
149 MatcherList(this.matchers); 158 MatcherList(this.matchers);
150 159
151 bool matches(List o, Map matchState) { 160 bool matches(List o, Map matchState) {
152 if (o.length != matchers.length) return false; 161 if (o.length != matchers.length) return false;
153 for (int i = 0; i < o.length; i++) { 162 for (int i = 0; i < o.length; i++) {
154 var state = new Map(); 163 var state = new Map();
155 if (!matchers[i].matches(o[i], state)) { 164 if (!matchers[i].matches(o[i], state)) {
156 matchState = { 165 matchState.addAll({
157 'index': i, 166 'index': i,
158 'value': o[i], 167 'value': o[i],
159 'state': state, 168 'state': state,
160 }; 169 });
161 return false; 170 return false;
162 } 171 }
163 } 172 }
164 return true; 173 return true;
165 } 174 }
166 175
167 Description describe(Description d) { 176 Description describe(Description d) {
168 d.add('matches all: '); 177 d.add('matches all: ');
169 matchers.forEach((m) => m.describe(d)); 178 matchers.forEach((m) => m.describe(d));
170 } 179 }
(...skipping 10 matching lines...) Expand all
181 } else { 190 } else {
182 if (item.length != matchers.length) { 191 if (item.length != matchers.length) {
183 mismatchDescription.add('wrong lengths'); 192 mismatchDescription.add('wrong lengths');
184 } else { 193 } else {
185 mismatchDescription.add('was ').addDescriptionOf(item); 194 mismatchDescription.add('was ').addDescriptionOf(item);
186 } 195 }
187 } 196 }
188 } 197 }
189 198
190 } 199 }
OLDNEW
« pkg/polymer_expressions/test/eval_test.dart ('K') | « pkg/polymer_expressions/test/parser_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698