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 comprehension = eval(parse('item in items'), scope); | |
222 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | |
223 }); | |
224 | |
225 test('should evaluate complex "in" expressions', () { | |
226 var holder = new ListHolder([1, 2, 3]); | |
227 var scope = new Scope(variables: {'holder': holder}); | |
228 var comprehension = eval(parse('item in holder.items'), scope); | |
229 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | |
230 }); | |
231 | |
232 test('should handle null iterators in "in" expressions', () { | |
233 var scope = new Scope(variables: {'items': null}); | |
234 var comprehension = eval(parse('item in items'), scope); | |
235 expect(comprehension, isNotNull); | |
236 expect(comprehension.iterable, []); | |
237 }); | 221 }); |
238 | 222 |
239 }); | 223 }); |
240 | 224 |
241 group('assign', () { | 225 group('assign', () { |
242 | 226 |
243 test('should assign a single identifier', () { | 227 test('should assign a single identifier', () { |
244 var foo = new Foo(name: 'a'); | 228 var foo = new Foo(name: 'a'); |
245 assign(parse('name'), 'b', new Scope(model: foo)); | 229 assign(parse('name'), 'b', new Scope(model: foo)); |
246 expect(foo.name, 'b'); | 230 expect(foo.name, 'b'); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 return expectObserve('foo["one"]', | 317 return expectObserve('foo["one"]', |
334 variables: {'foo': foo}, | 318 variables: {'foo': foo}, |
335 beforeMatcher: 'one', | 319 beforeMatcher: 'one', |
336 mutate: () { | 320 mutate: () { |
337 foo['one'] = '1'; | 321 foo['one'] = '1'; |
338 }, | 322 }, |
339 afterMatcher: '1' | 323 afterMatcher: '1' |
340 ); | 324 ); |
341 }); | 325 }); |
342 | 326 |
343 test('should observe an comprehension', () { | |
344 var items = new ObservableList(); | |
345 var foo = new Foo(name: 'foo'); | |
346 return expectObserve('item in items', | |
347 variables: {'items': items}, | |
348 beforeMatcher: (c) => c.iterable.isEmpty, | |
349 mutate: () { | |
350 items.add(foo); | |
351 }, | |
352 afterMatcher: (c) => c.iterable.contains(foo) | |
353 ); | |
354 }); | |
355 | |
356 }); | 327 }); |
357 | 328 |
358 } | 329 } |
359 | 330 |
360 @reflectable | 331 @reflectable |
361 class Foo extends ChangeNotifier { | 332 class Foo extends ChangeNotifier { |
362 String _name; | 333 String _name; |
363 String get name => _name; | 334 String get name => _name; |
364 void set name(String n) { | 335 void set name(String n) { |
365 _name = notifyPropertyChange(#name, _name, n); | 336 _name = notifyPropertyChange(#name, _name, n); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 return Future.wait([future, new Future(() { | 400 return Future.wait([future, new Future(() { |
430 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"); |
431 })]); | 402 })]); |
432 } | 403 } |
433 | 404 |
434 // 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 |
435 class WordElement extends Observable { | 406 class WordElement extends Observable { |
436 @observable List chars1 = 'abcdefg'.split(''); | 407 @observable List chars1 = 'abcdefg'.split(''); |
437 @reflectable List filteredList(List original) => [original[0], original[1]]; | 408 @reflectable List filteredList(List original) => [original[0], original[1]]; |
438 } | 409 } |
OLD | NEW |