| 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 | 212 |
| 213 test('should evaluate an "in" expression', () { | 213 test('should evaluate an "in" expression', () { |
| 214 var scope = new Scope(variables: {'items': [1, 2, 3]}); | 214 var scope = new Scope(variables: {'items': [1, 2, 3]}); |
| 215 var comprehension = eval(parse('item in items'), scope); | 215 var comprehension = eval(parse('item in items'), scope); |
| 216 expect(comprehension.iterable, orderedEquals([1, 2, 3])); | 216 expect(comprehension.iterable, orderedEquals([1, 2, 3])); |
| 217 }); | 217 }); |
| 218 | 218 |
| 219 test('should evaluate complex "in" expressions', () { |
| 220 var holder = new ListHolder([1, 2, 3]); |
| 221 var scope = new Scope(variables: {'holder': holder}); |
| 222 var comprehension = eval(parse('item in holder.items'), scope); |
| 223 expect(comprehension.iterable, orderedEquals([1, 2, 3])); |
| 224 }); |
| 225 |
| 219 test('should handle null iterators in "in" expressions', () { | 226 test('should handle null iterators in "in" expressions', () { |
| 220 var scope = new Scope(variables: {'items': null}); | 227 var scope = new Scope(variables: {'items': null}); |
| 221 var comprehension = eval(parse('item in items'), scope); | 228 var comprehension = eval(parse('item in items'), scope); |
| 222 expect(comprehension, isNotNull); | 229 expect(comprehension, isNotNull); |
| 223 expect(comprehension.iterable, []); | 230 expect(comprehension.iterable, []); |
| 224 }); | 231 }); |
| 225 | 232 |
| 226 }); | 233 }); |
| 227 | 234 |
| 228 group('assign', () { | 235 group('assign', () { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 361 |
| 355 int age; | 362 int age; |
| 356 Foo child; | 363 Foo child; |
| 357 List<int> items; | 364 List<int> items; |
| 358 | 365 |
| 359 Foo({name, this.age, this.child, this.items}) : _name = name; | 366 Foo({name, this.age, this.child, this.items}) : _name = name; |
| 360 | 367 |
| 361 int x() => age * age; | 368 int x() => age * age; |
| 362 } | 369 } |
| 363 | 370 |
| 371 @reflectable |
| 372 class ListHolder { |
| 373 List items; |
| 374 ListHolder(this.items); |
| 375 } |
| 376 |
| 364 parseInt([int radix = 10]) => new IntToString(radix: radix); | 377 parseInt([int radix = 10]) => new IntToString(radix: radix); |
| 365 | 378 |
| 366 class IntToString extends Transformer<int, String> { | 379 class IntToString extends Transformer<int, String> { |
| 367 final int radix; | 380 final int radix; |
| 368 IntToString({this.radix: 10}); | 381 IntToString({this.radix: 10}); |
| 369 int forward(String s) => int.parse(s, radix: radix); | 382 int forward(String s) => int.parse(s, radix: radix); |
| 370 String reverse(int i) => '$i'; | 383 String reverse(int i) => '$i'; |
| 371 } | 384 } |
| 372 | 385 |
| 373 add(int i) => new Add(i); | 386 add(int i) => new Add(i); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 return Future.wait([future, new Future(() { | 423 return Future.wait([future, new Future(() { |
| 411 expect(passed, true, reason: "Didn't receive a change notification on $s"); | 424 expect(passed, true, reason: "Didn't receive a change notification on $s"); |
| 412 })]); | 425 })]); |
| 413 } | 426 } |
| 414 | 427 |
| 415 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 | 428 // Regression test from https://code.google.com/p/dart/issues/detail?id=13459 |
| 416 class WordElement extends Observable { | 429 class WordElement extends Observable { |
| 417 @observable List chars1 = 'abcdefg'.split(''); | 430 @observable List chars1 = 'abcdefg'.split(''); |
| 418 @reflectable List filteredList(List original) => [original[0], original[1]]; | 431 @reflectable List filteredList(List original) => [original[0], original[1]]; |
| 419 } | 432 } |
| OLD | NEW |