| 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 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 Loading... |
| 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); |
| 73 expectEval('1 != 1', false); | 78 expectEval('1 != 1', false); |
| 74 expectEval('1 != 2', true); | 79 expectEval('1 != 2', true); |
| 80 expectEval('1 != null', true); |
| 75 | 81 |
| 76 expectEval('1 > 1', false); | 82 expectEval('1 > 1', false); |
| 77 expectEval('1 > 2', false); | 83 expectEval('1 > 2', false); |
| 78 expectEval('2 > 1', true); | 84 expectEval('2 > 1', true); |
| 79 expectEval('1 >= 1', true); | 85 expectEval('1 >= 1', true); |
| 80 expectEval('1 >= 2', false); | 86 expectEval('1 >= 2', false); |
| 81 expectEval('2 >= 1', true); | 87 expectEval('2 >= 1', true); |
| 82 expectEval('1 < 1', false); | 88 expectEval('1 < 1', false); |
| 83 expectEval('1 < 2', true); | 89 expectEval('1 < 2', true); |
| 84 expectEval('2 < 1', false); | 90 expectEval('2 < 1', false); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 test('should return null if null is invoked', () { | 161 test('should return null if null is invoked', () { |
| 156 expectEval('a()', null, null, {'a': null}); | 162 expectEval('a()', null, null, {'a': null}); |
| 157 }); | 163 }); |
| 158 | 164 |
| 159 test('should return null if an operand is null', () { | 165 test('should return null if an operand is null', () { |
| 160 expectEval('a + b', null, null, {'a': null, 'b': null}); | 166 expectEval('a + b', null, null, {'a': null, 'b': null}); |
| 161 expectEval('+a', null, null, {'a': null}); | 167 expectEval('+a', null, null, {'a': null}); |
| 162 }); | 168 }); |
| 163 | 169 |
| 164 test('should treat null as false', () { | 170 test('should treat null as false', () { |
| 171 expectEval('!null', true); |
| 172 expectEval('true && null', false); |
| 173 expectEval('null || false', false); |
| 174 |
| 165 expectEval('!a', true, null, {'a': null}); | 175 expectEval('!a', true, null, {'a': null}); |
| 166 | 176 |
| 167 expectEval('a && b', false, null, {'a': null, 'b': true}); | 177 expectEval('a && b', false, null, {'a': null, 'b': true}); |
| 168 expectEval('a && b', false, null, {'a': true, 'b': null}); | 178 expectEval('a && b', false, null, {'a': true, 'b': null}); |
| 169 expectEval('a && b', false, null, {'a': null, 'b': false}); | 179 expectEval('a && b', false, null, {'a': null, 'b': false}); |
| 170 expectEval('a && b', false, null, {'a': false, 'b': null}); | 180 expectEval('a && b', false, null, {'a': false, 'b': null}); |
| 171 expectEval('a && b', false, null, {'a': null, 'b': null}); | 181 expectEval('a && b', false, null, {'a': null, 'b': null}); |
| 172 | 182 |
| 173 expectEval('a || b', true, null, {'a': null, 'b': true}); | 183 expectEval('a || b', true, null, {'a': null, 'b': true}); |
| 174 expectEval('a || b', true, null, {'a': true, 'b': null}); | 184 expectEval('a || b', true, null, {'a': true, 'b': null}); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 expect(value, afterMatcher); | 379 expect(value, afterMatcher); |
| 370 expect(observer.currentValue, afterMatcher); | 380 expect(observer.currentValue, afterMatcher); |
| 371 passed = true; | 381 passed = true; |
| 372 }); | 382 }); |
| 373 mutate(); | 383 mutate(); |
| 374 // fail if we don't receive an update by the next event loop | 384 // fail if we don't receive an update by the next event loop |
| 375 return Future.wait([future, new Future(() { | 385 return Future.wait([future, new Future(() { |
| 376 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 386 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
| 377 })]); | 387 })]); |
| 378 } | 388 } |
| OLD | NEW |