| 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 mirrors to cause all mirrors to be retained by dart2js. | 9 // Import mirrors to cause all mirrors to be retained by dart2js. |
| 10 // The tests reflect on LinkedHashMap.length and String.length. | 10 // The tests reflect on LinkedHashMap.length and String.length. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 expectEval('a && b', false, null, {'a': false, 'b': null}); | 208 expectEval('a && b', false, null, {'a': false, 'b': null}); |
| 209 expectEval('a && b', false, null, {'a': null, 'b': null}); | 209 expectEval('a && b', false, null, {'a': null, 'b': null}); |
| 210 | 210 |
| 211 expectEval('a || b', true, null, {'a': null, 'b': true}); | 211 expectEval('a || b', true, null, {'a': null, 'b': true}); |
| 212 expectEval('a || b', true, null, {'a': true, 'b': null}); | 212 expectEval('a || b', true, null, {'a': true, 'b': null}); |
| 213 expectEval('a || b', false, null, {'a': null, 'b': false}); | 213 expectEval('a || b', false, null, {'a': null, 'b': false}); |
| 214 expectEval('a || b', false, null, {'a': false, 'b': null}); | 214 expectEval('a || b', false, null, {'a': false, 'b': null}); |
| 215 expectEval('a || b', false, null, {'a': null, 'b': null}); | 215 expectEval('a || b', false, null, {'a': null, 'b': null}); |
| 216 }); | 216 }); |
| 217 | 217 |
| 218 test('should evaluate an "in" expression', () { | 218 test('should not evaluate "in" expressions', () { |
| 219 var scope = new Scope(variables: {'items': [1, 2, 3]}); | 219 expect(() => eval(parse('item in items'), null), throws); |
| 220 var comprehension = eval(parse('item in items'), scope); | |
| 221 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | |
| 222 }); | 220 }); |
| 223 | 221 |
| 224 test('should evaluate complex "in" expressions', () { | 222 // test('should evaluate complex "in" expressions', () { |
| 225 var holder = new ListHolder([1, 2, 3]); | 223 // var holder = new ListHolder([1, 2, 3]); |
| 226 var scope = new Scope(variables: {'holder': holder}); | 224 // var scope = new Scope(variables: {'holder': holder}); |
| 227 var comprehension = eval(parse('item in holder.items'), scope); | 225 // var comprehension = eval(parse('item in holder.items'), scope); |
| 228 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | 226 // expect(comprehension.iterable, orderedEquals([1, 2, 3])); |
| 229 }); | 227 // }); |
| 230 | 228 // |
| 231 test('should handle null iterators in "in" expressions', () { | 229 // test('should handle null iterators in "in" expressions', () { |
| 232 var scope = new Scope(variables: {'items': null}); | 230 // var scope = new Scope(variables: {'items': null}); |
| 233 var comprehension = eval(parse('item in items'), scope); | 231 // var comprehension = eval(parse('item in items'), scope); |
| 234 expect(comprehension, isNotNull); | 232 // expect(comprehension, isNotNull); |
| 235 expect(comprehension.iterable, []); | 233 // expect(comprehension.iterable, []); |
| 236 }); | 234 // }); |
| 237 | 235 |
| 238 }); | 236 }); |
| 239 | 237 |
| 240 group('assign', () { | 238 group('assign', () { |
| 241 | 239 |
| 242 test('should assign a single identifier', () { | 240 test('should assign a single identifier', () { |
| 243 var foo = new Foo(name: 'a'); | 241 var foo = new Foo(name: 'a'); |
| 244 assign(parse('name'), 'b', new Scope(model: foo)); | 242 assign(parse('name'), 'b', new Scope(model: foo)); |
| 245 expect(foo.name, 'b'); | 243 expect(foo.name, 'b'); |
| 246 }); | 244 }); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 return expectObserve('foo["one"]', | 330 return expectObserve('foo["one"]', |
| 333 variables: {'foo': foo}, | 331 variables: {'foo': foo}, |
| 334 beforeMatcher: 'one', | 332 beforeMatcher: 'one', |
| 335 mutate: () { | 333 mutate: () { |
| 336 foo['one'] = '1'; | 334 foo['one'] = '1'; |
| 337 }, | 335 }, |
| 338 afterMatcher: '1' | 336 afterMatcher: '1' |
| 339 ); | 337 ); |
| 340 }); | 338 }); |
| 341 | 339 |
| 342 test('should observe an comprehension', () { | |
| 343 var items = new ObservableList(); | |
| 344 var foo = new Foo(name: 'foo'); | |
| 345 return expectObserve('item in items', | |
| 346 variables: {'items': items}, | |
| 347 beforeMatcher: (c) => c.iterable.isEmpty, | |
| 348 mutate: () { | |
| 349 items.add(foo); | |
| 350 }, | |
| 351 afterMatcher: (c) => c.iterable.contains(foo) | |
| 352 ); | |
| 353 }); | |
| 354 | |
| 355 }); | 340 }); |
| 356 | 341 |
| 357 } | 342 } |
| 358 | 343 |
| 359 @reflectable | 344 @reflectable |
| 360 class Foo extends ChangeNotifier { | 345 class Foo extends ChangeNotifier { |
| 361 String _name; | 346 String _name; |
| 362 String get name => _name; | 347 String get name => _name; |
| 363 void set name(String n) { | 348 void set name(String n) { |
| 364 _name = notifyPropertyChange(#name, _name, n); | 349 _name = notifyPropertyChange(#name, _name, n); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 return Future.wait([future, new Future(() { | 413 return Future.wait([future, new Future(() { |
| 429 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 414 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
| 430 })]); | 415 })]); |
| 431 } | 416 } |
| 432 | 417 |
| 433 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 | 418 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 |
| 434 class WordElement extends Observable { | 419 class WordElement extends Observable { |
| 435 @observable List chars1 = 'abcdefg'.split(''); | 420 @observable List chars1 = 'abcdefg'.split(''); |
| 436 @reflectable List filteredList(List original) => [original[0], original[1]]; | 421 @reflectable List filteredList(List original) => [original[0], original[1]]; |
| 437 } | 422 } |
| OLD | NEW |