| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 expectEval('a && b', false, null, {'a': false, 'b': null}); | 209 expectEval('a && b', false, null, {'a': false, 'b': null}); |
| 210 expectEval('a && b', false, null, {'a': null, 'b': null}); | 210 expectEval('a && b', false, null, {'a': null, 'b': null}); |
| 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 not evaluate "in" expressions', () { |
| 220 var scope = new Scope(variables: {'items': [1, 2, 3]}); | 220 expect(() => eval(parse('item in items'), null), throws); |
| 221 var childScopes = eval(parse('item in items'), scope); | |
| 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); | |
| 229 }); | |
| 230 | |
| 231 test('should evaluate complex "in" expressions', () { | |
| 232 var holder = new ListHolder([1, 2, 3]); | |
| 233 var scope = new Scope(variables: {'holder': holder}); | |
| 234 var childScopes = eval(parse('item in holder.items'), scope); | |
| 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); | |
| 242 }); | |
| 243 | |
| 244 test('should handle null iterators in "in" expressions', () { | |
| 245 var scope = new Scope(variables: {'items': null}); | |
| 246 var childScopes = eval(parse('item in items'), scope); | |
| 247 expect(childScopes.length, 0); | |
| 248 }); | 221 }); |
| 249 | 222 |
| 250 }); | 223 }); |
| 251 | 224 |
| 252 group('assign', () { | 225 group('assign', () { |
| 253 | 226 |
| 254 test('should assign a single identifier', () { | 227 test('should assign a single identifier', () { |
| 255 var foo = new Foo(name: 'a'); | 228 var foo = new Foo(name: 'a'); |
| 256 assign(parse('name'), 'b', new Scope(model: foo)); | 229 assign(parse('name'), 'b', new Scope(model: foo)); |
| 257 expect(foo.name, 'b'); | 230 expect(foo.name, 'b'); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 return expectObserve('foo["one"]', | 317 return expectObserve('foo["one"]', |
| 345 variables: {'foo': foo}, | 318 variables: {'foo': foo}, |
| 346 beforeMatcher: 'one', | 319 beforeMatcher: 'one', |
| 347 mutate: () { | 320 mutate: () { |
| 348 foo['one'] = '1'; | 321 foo['one'] = '1'; |
| 349 }, | 322 }, |
| 350 afterMatcher: '1' | 323 afterMatcher: '1' |
| 351 ); | 324 ); |
| 352 }); | 325 }); |
| 353 | 326 |
| 354 test('should observe an comprehension', () { | |
| 355 var items = new ObservableList(); | |
| 356 var foo = new Foo(name: 'foo'); | |
| 357 return expectObserve('item in items', | |
| 358 variables: {'items': items}, | |
| 359 beforeMatcher: (c) => c.isEmpty, | |
| 360 mutate: () { | |
| 361 items.add(foo); | |
| 362 }, | |
| 363 afterMatcher: | |
| 364 (c) => c.single.varName == 'item' && c.single.value == foo | |
| 365 ); | |
| 366 }); | |
| 367 | |
| 368 }); | 327 }); |
| 369 | 328 |
| 370 } | 329 } |
| 371 | 330 |
| 372 @reflectable | 331 @reflectable |
| 373 class Foo extends ChangeNotifier { | 332 class Foo extends ChangeNotifier { |
| 374 String _name; | 333 String _name; |
| 375 String get name => _name; | 334 String get name => _name; |
| 376 void set name(String n) { | 335 void set name(String n) { |
| 377 _name = notifyPropertyChange(#name, _name, n); | 336 _name = notifyPropertyChange(#name, _name, n); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 return Future.wait([future, new Future(() { | 400 return Future.wait([future, new Future(() { |
| 442 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 401 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
| 443 })]); | 402 })]); |
| 444 } | 403 } |
| 445 | 404 |
| 446 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 | 405 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 |
| 447 class WordElement extends Observable { | 406 class WordElement extends Observable { |
| 448 @observable List chars1 = 'abcdefg'.split(''); | 407 @observable List chars1 = 'abcdefg'.split(''); |
| 449 @reflectable List filteredList(List original) => [original[0], original[1]]; | 408 @reflectable List filteredList(List original) => [original[0], original[1]]; |
| 450 } | 409 } |
| OLD | NEW |