| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 | 211 |
| 212 expectEval('a || b', true, null, {'a': null, 'b': true}); | 212 expectEval('a || b', true, null, {'a': null, 'b': true}); |
| 213 expectEval('a || b', true, null, {'a': true, 'b': null}); | 213 expectEval('a || b', true, null, {'a': true, 'b': null}); |
| 214 expectEval('a || b', false, null, {'a': null, 'b': false}); | 214 expectEval('a || b', false, null, {'a': null, 'b': false}); |
| 215 expectEval('a || b', false, null, {'a': false, 'b': null}); | 215 expectEval('a || b', false, null, {'a': false, 'b': null}); |
| 216 expectEval('a || b', false, null, {'a': null, 'b': null}); | 216 expectEval('a || b', false, null, {'a': null, 'b': null}); |
| 217 }); | 217 }); |
| 218 | 218 |
| 219 test('should evaluate an "in" expression', () { | 219 test('should evaluate an "in" expression', () { |
| 220 var scope = new Scope(variables: {'items': [1, 2, 3]}); | 220 var scope = new Scope(variables: {'items': [1, 2, 3]}); |
| 221 var comprehension = eval(parse('item in items'), scope); | 221 var childScopes = eval(parse('item in items'), scope); |
| 222 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | 222 expect(childScopes.length, 3); |
| 223 expect(childScopes[0].varName, 'item'); |
| 224 expect(childScopes[0].value, 1); |
| 225 expect(childScopes[1].varName, 'item'); |
| 226 expect(childScopes[1].value, 2); |
| 227 expect(childScopes[2].varName, 'item'); |
| 228 expect(childScopes[2].value, 3); |
| 223 }); | 229 }); |
| 224 | 230 |
| 225 test('should evaluate complex "in" expressions', () { | 231 test('should evaluate complex "in" expressions', () { |
| 226 var holder = new ListHolder([1, 2, 3]); | 232 var holder = new ListHolder([1, 2, 3]); |
| 227 var scope = new Scope(variables: {'holder': holder}); | 233 var scope = new Scope(variables: {'holder': holder}); |
| 228 var comprehension = eval(parse('item in holder.items'), scope); | 234 var childScopes = eval(parse('item in holder.items'), scope); |
| 229 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | 235 expect(childScopes.length, 3); |
| 236 expect(childScopes[0].varName, 'item'); |
| 237 expect(childScopes[0].value, 1); |
| 238 expect(childScopes[1].varName, 'item'); |
| 239 expect(childScopes[1].value, 2); |
| 240 expect(childScopes[2].varName, 'item'); |
| 241 expect(childScopes[2].value, 3); |
| 230 }); | 242 }); |
| 231 | 243 |
| 232 test('should handle null iterators in "in" expressions', () { | 244 test('should handle null iterators in "in" expressions', () { |
| 233 var scope = new Scope(variables: {'items': null}); | 245 var scope = new Scope(variables: {'items': null}); |
| 234 var comprehension = eval(parse('item in items'), scope); | 246 var childScopes = eval(parse('item in items'), scope); |
| 235 expect(comprehension, isNotNull); | 247 expect(childScopes.length, 0); |
| 236 expect(comprehension.iterable, []); | |
| 237 }); | 248 }); |
| 238 | 249 |
| 239 }); | 250 }); |
| 240 | 251 |
| 241 group('assign', () { | 252 group('assign', () { |
| 242 | 253 |
| 243 test('should assign a single identifier', () { | 254 test('should assign a single identifier', () { |
| 244 var foo = new Foo(name: 'a'); | 255 var foo = new Foo(name: 'a'); |
| 245 assign(parse('name'), 'b', new Scope(model: foo)); | 256 assign(parse('name'), 'b', new Scope(model: foo)); |
| 246 expect(foo.name, 'b'); | 257 expect(foo.name, 'b'); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 }, | 349 }, |
| 339 afterMatcher: '1' | 350 afterMatcher: '1' |
| 340 ); | 351 ); |
| 341 }); | 352 }); |
| 342 | 353 |
| 343 test('should observe an comprehension', () { | 354 test('should observe an comprehension', () { |
| 344 var items = new ObservableList(); | 355 var items = new ObservableList(); |
| 345 var foo = new Foo(name: 'foo'); | 356 var foo = new Foo(name: 'foo'); |
| 346 return expectObserve('item in items', | 357 return expectObserve('item in items', |
| 347 variables: {'items': items}, | 358 variables: {'items': items}, |
| 348 beforeMatcher: (c) => c.iterable.isEmpty, | 359 beforeMatcher: (c) => c.isEmpty, |
| 349 mutate: () { | 360 mutate: () { |
| 350 items.add(foo); | 361 items.add(foo); |
| 351 }, | 362 }, |
| 352 afterMatcher: (c) => c.iterable.contains(foo) | 363 afterMatcher: |
| 364 (c) => c.single.varName == 'item' && c.single.value == foo |
| 353 ); | 365 ); |
| 354 }); | 366 }); |
| 355 | 367 |
| 356 }); | 368 }); |
| 357 | 369 |
| 358 } | 370 } |
| 359 | 371 |
| 360 @reflectable | 372 @reflectable |
| 361 class Foo extends ChangeNotifier { | 373 class Foo extends ChangeNotifier { |
| 362 String _name; | 374 String _name; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 return Future.wait([future, new Future(() { | 441 return Future.wait([future, new Future(() { |
| 430 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 442 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
| 431 })]); | 443 })]); |
| 432 } | 444 } |
| 433 | 445 |
| 434 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 | 446 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 |
| 435 class WordElement extends Observable { | 447 class WordElement extends Observable { |
| 436 @observable List chars1 = 'abcdefg'.split(''); | 448 @observable List chars1 = 'abcdefg'.split(''); |
| 437 @reflectable List filteredList(List original) => [original[0], original[1]]; | 449 @reflectable List filteredList(List original) => [original[0], original[1]]; |
| 438 } | 450 } |
| OLD | NEW |