| Index: tests/lib_strong/collection/list_test.dart
|
| diff --git a/tests/lib_strong/collection/list_test.dart b/tests/lib_strong/collection/list_test.dart
|
| index 76cd515a92deef17a0305a257a0b7e934d2ee856..4085328988e5cabc36f5540b32773c1483fd25bf 100644
|
| --- a/tests/lib_strong/collection/list_test.dart
|
| +++ b/tests/lib_strong/collection/list_test.dart
|
| @@ -16,13 +16,43 @@ class MyList<E> extends Object with ListMixin<E> implements List<E> {
|
| _list.length = x;
|
| }
|
|
|
| - E operator[](int idx) => _list[idx];
|
| + E operator [](int idx) => _list[idx];
|
|
|
| - void operator[]=(int idx, E value) {
|
| + void operator []=(int idx, E value) {
|
| _list[idx] = value;
|
| }
|
| }
|
|
|
| +class MyNoSuchMethodList<E> extends Object
|
| + with ListMixin<E>
|
| + implements List<E> {
|
| + List<E> _list;
|
| +
|
| + MyNoSuchMethodList(List<E> this._list);
|
| +
|
| + noSuchMethod(Invocation invocation) {
|
| + if (invocation.memberName == #length) {
|
| + if (invocation.isGetter) return _list.length;
|
| + if (invocation.isSetter) {
|
| + _list.length = invocation.positionalArguments.first;
|
| + return;
|
| + }
|
| + return super.noSuchMethod(invocation);
|
| + }
|
| + if (invocation.memberName == new Symbol("[]") &&
|
| + invocation.positionalArguments.length == 1) {
|
| + return _list[invocation.positionalArguments.first];
|
| + }
|
| + if (invocation.memberName == new Symbol("[]=") &&
|
| + invocation.positionalArguments.length == 2) {
|
| + _list[invocation.positionalArguments.first] =
|
| + invocation.positionalArguments[1];
|
| + return;
|
| + }
|
| + return super.noSuchMethod(invocation);
|
| + }
|
| +}
|
| +
|
| void testRetainWhere() {
|
| List<int> list = <int>[1, 2, 3];
|
| list.retainWhere((x) => x % 2 == 0);
|
| @@ -33,6 +63,26 @@ void testRetainWhere() {
|
| list.retainWhere((x) => x % 2 == 0);
|
| Expect.equals(1, list.length);
|
| Expect.equals(2, list.first);
|
| +
|
| + list = new MyNoSuchMethodList<int>([1, 2, 3]);
|
| + list.retainWhere((x) => x % 2 == 0);
|
| + Expect.equals(1, list.length);
|
| + Expect.equals(2, list.first);
|
| +
|
| + // Equivalent tests where the type of the List is known statically.
|
| + {
|
| + var l = new MyList<int>([1, 2, 3]);
|
| + l.retainWhere((x) => x % 2 == 0);
|
| + Expect.equals(1, l.length);
|
| + Expect.equals(2, l.first);
|
| + }
|
| +
|
| + {
|
| + var l = new MyNoSuchMethodList<int>([1, 2, 3]);
|
| + l.retainWhere((x) => x % 2 == 0);
|
| + Expect.equals(1, l.length);
|
| + Expect.equals(2, l.first);
|
| + }
|
| }
|
|
|
| void main() {
|
|
|