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 | |
224 test('should evaluate complex "in" expressions', () { | |
225 var holder = new ListHolder([1, 2, 3]); | |
226 var scope = new Scope(variables: {'holder': holder}); | |
227 var comprehension = eval(parse('item in holder.items'), scope); | |
228 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | |
229 }); | |
230 | |
231 test('should handle null iterators in "in" expressions', () { | |
232 var scope = new Scope(variables: {'items': null}); | |
233 var comprehension = eval(parse('item in items'), scope); | |
234 expect(comprehension, isNotNull); | |
235 expect(comprehension.iterable, []); | |
236 }); | |
237 | |
238 }); | 221 }); |
239 | 222 |
240 group('assign', () { | 223 group('assign', () { |
241 | 224 |
242 test('should assign a single identifier', () { | 225 test('should assign a single identifier', () { |
243 var foo = new Foo(name: 'a'); | 226 var foo = new Foo(name: 'a'); |
244 assign(parse('name'), 'b', new Scope(model: foo)); | 227 assign(parse('name'), 'b', new Scope(model: foo)); |
245 expect(foo.name, 'b'); | 228 expect(foo.name, 'b'); |
246 }); | 229 }); |
247 | 230 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 return expectObserve('foo["one"]', | 315 return expectObserve('foo["one"]', |
333 variables: {'foo': foo}, | 316 variables: {'foo': foo}, |
334 beforeMatcher: 'one', | 317 beforeMatcher: 'one', |
335 mutate: () { | 318 mutate: () { |
336 foo['one'] = '1'; | 319 foo['one'] = '1'; |
337 }, | 320 }, |
338 afterMatcher: '1' | 321 afterMatcher: '1' |
339 ); | 322 ); |
340 }); | 323 }); |
341 | 324 |
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 }); | 325 }); |
356 | 326 |
357 } | 327 } |
358 | 328 |
359 @reflectable | 329 @reflectable |
360 class Foo extends ChangeNotifier { | 330 class Foo extends ChangeNotifier { |
361 String _name; | 331 String _name; |
362 String get name => _name; | 332 String get name => _name; |
363 void set name(String n) { | 333 void set name(String n) { |
364 _name = notifyPropertyChange(#name, _name, n); | 334 _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(() { | 398 return Future.wait([future, new Future(() { |
429 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 399 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
430 })]); | 400 })]); |
431 } | 401 } |
432 | 402 |
433 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 | 403 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 |
434 class WordElement extends Observable { | 404 class WordElement extends Observable { |
435 @observable List chars1 = 'abcdefg'.split(''); | 405 @observable List chars1 = 'abcdefg'.split(''); |
436 @reflectable List filteredList(List original) => [original[0], original[1]]; | 406 @reflectable List filteredList(List original) => [original[0], original[1]]; |
437 } | 407 } |
OLD | NEW |