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

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

Issue 23458017: Add null literals to polymer expressions (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
« no previous file with comments | « pkg/polymer_expressions/lib/parser.dart ('k') | pkg/polymer_expressions/test/parser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 eval_test; 5 library eval_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:polymer_expressions/eval.dart'; 9 import 'package:polymer_expressions/eval.dart';
10 import 'package:polymer_expressions/filter.dart'; 10 import 'package:polymer_expressions/filter.dart';
(...skipping 29 matching lines...) Expand all
40 test('should return a literal string', () { 40 test('should return a literal string', () {
41 expectEval('"hello"', "hello"); 41 expectEval('"hello"', "hello");
42 expectEval("'hello'", "hello"); 42 expectEval("'hello'", "hello");
43 }); 43 });
44 44
45 test('should return a literal boolean', () { 45 test('should return a literal boolean', () {
46 expectEval('true', true); 46 expectEval('true', true);
47 expectEval('false', false); 47 expectEval('false', false);
48 }); 48 });
49 49
50 test('should return a literal null', () {
51 expectEval('null', null);
52 });
53
50 test('should return a literal map', () { 54 test('should return a literal map', () {
51 expectEval('{"a": 1}', equals(new Map.from({'a': 1}))); 55 expectEval('{"a": 1}', equals(new Map.from({'a': 1})));
52 expectEval('{"a": 1}', containsPair('a', 1)); 56 expectEval('{"a": 1}', containsPair('a', 1));
53 }); 57 });
54 58
55 test('should call methods on a literal map', () { 59 test('should call methods on a literal map', () {
56 expectEval('{"a": 1}.length', 1); 60 expectEval('{"a": 1}.length', 1);
57 }); 61 });
58 62
59 test('should evaluate unary operators', () { 63 test('should evaluate unary operators', () {
60 expectEval('+a', 2, null, {'a': 2}); 64 expectEval('+a', 2, null, {'a': 2});
61 expectEval('-a', -2, null, {'a': 2}); 65 expectEval('-a', -2, null, {'a': 2});
62 expectEval('!a', false, null, {'a': true}); 66 expectEval('!a', false, null, {'a': true});
63 }); 67 });
64 68
65 test('should evaluate binary operators', () { 69 test('should evaluate binary operators', () {
66 expectEval('1 + 2', 3); 70 expectEval('1 + 2', 3);
67 expectEval('2 - 1', 1); 71 expectEval('2 - 1', 1);
68 expectEval('4 / 2', 2); 72 expectEval('4 / 2', 2);
69 expectEval('2 * 3', 6); 73 expectEval('2 * 3', 6);
70 74
71 expectEval('1 == 1', true); 75 expectEval('1 == 1', true);
72 expectEval('1 == 2', false); 76 expectEval('1 == 2', false);
77 expectEval('1 == null', false);
Chris Bracken 2013/09/03 21:55:39 != test for the truly paranoid?
73 expectEval('1 != 1', false); 78 expectEval('1 != 1', false);
74 expectEval('1 != 2', true); 79 expectEval('1 != 2', true);
75 80
76 expectEval('1 > 1', false); 81 expectEval('1 > 1', false);
77 expectEval('1 > 2', false); 82 expectEval('1 > 2', false);
78 expectEval('2 > 1', true); 83 expectEval('2 > 1', true);
79 expectEval('1 >= 1', true); 84 expectEval('1 >= 1', true);
80 expectEval('1 >= 2', false); 85 expectEval('1 >= 2', false);
81 expectEval('2 >= 1', true); 86 expectEval('2 >= 1', true);
82 expectEval('1 < 1', false); 87 expectEval('1 < 1', false);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 test('should return null if null is invoked', () { 160 test('should return null if null is invoked', () {
156 expectEval('a()', null, null, {'a': null}); 161 expectEval('a()', null, null, {'a': null});
157 }); 162 });
158 163
159 test('should return null if an operand is null', () { 164 test('should return null if an operand is null', () {
160 expectEval('a + b', null, null, {'a': null, 'b': null}); 165 expectEval('a + b', null, null, {'a': null, 'b': null});
161 expectEval('+a', null, null, {'a': null}); 166 expectEval('+a', null, null, {'a': null});
162 }); 167 });
163 168
164 test('should treat null as false', () { 169 test('should treat null as false', () {
170 expectEval('!null', true, null);
171 expectEval('true && null', false, null);
Jennifer Messerly 2013/09/03 21:47:24 ... you don't want 3-valued boolean logic here? ;)
justinfagnani 2013/09/03 21:54:36 don't tempt me!
172 expectEval('null || false', false, null);
173
165 expectEval('!a', true, null, {'a': null}); 174 expectEval('!a', true, null, {'a': null});
166 175
167 expectEval('a && b', false, null, {'a': null, 'b': true}); 176 expectEval('a && b', false, null, {'a': null, 'b': true});
168 expectEval('a && b', false, null, {'a': true, 'b': null}); 177 expectEval('a && b', false, null, {'a': true, 'b': null});
169 expectEval('a && b', false, null, {'a': null, 'b': false}); 178 expectEval('a && b', false, null, {'a': null, 'b': false});
170 expectEval('a && b', false, null, {'a': false, 'b': null}); 179 expectEval('a && b', false, null, {'a': false, 'b': null});
171 expectEval('a && b', false, null, {'a': null, 'b': null}); 180 expectEval('a && b', false, null, {'a': null, 'b': null});
172 181
173 expectEval('a || b', true, null, {'a': null, 'b': true}); 182 expectEval('a || b', true, null, {'a': null, 'b': true});
174 expectEval('a || b', true, null, {'a': true, 'b': null}); 183 expectEval('a || b', true, null, {'a': true, 'b': null});
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 expect(value, afterMatcher); 378 expect(value, afterMatcher);
370 expect(observer.currentValue, afterMatcher); 379 expect(observer.currentValue, afterMatcher);
371 passed = true; 380 passed = true;
372 }); 381 });
373 mutate(); 382 mutate();
374 // fail if we don't receive an update by the next event loop 383 // fail if we don't receive an update by the next event loop
375 return Future.wait([future, new Future(() { 384 return Future.wait([future, new Future(() {
376 expect(passed, true, reason: "Didn't receive a change notification on $s"); 385 expect(passed, true, reason: "Didn't receive a change notification on $s");
377 })]); 386 })]);
378 } 387 }
OLDNEW
« no previous file with comments | « pkg/polymer_expressions/lib/parser.dart ('k') | pkg/polymer_expressions/test/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698