Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1243)

Unified Diff: tests/lib_strong/collection/list_test.dart

Issue 2623053004: Fix noSuchMethod handling of methods that are also extension methods. Fix noSuchMethod handling of … (Closed)
Patch Set: Fix noSuchMethod handling of methods that are also extension methods. Fix noSuchMethod handling of … Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/language_strong/cast2_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a2ce1417f84230ca16058dba3de33690d7e78e1b 100644
--- a/tests/lib_strong/collection/list_test.dart
+++ b/tests/lib_strong/collection/list_test.dart
@@ -16,23 +16,138 @@ 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 null;
+ }
+ 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 null;
+ }
+ return super.noSuchMethod(invocation);
+ }
+}
+
+// Class that behaves like a list but does not implement List.
+class MyIndexableNoSuchMethod<E> {
+ List<E> _list;
+
+ MyIndexableNoSuchMethod(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 null;
+ }
+ return super.noSuchMethod(invocation);
+ }
+ if (invocation.memberName == new Symbol("prototype")) {
+ return 42;
+ }
+
+ 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 null;
+ }
+ return super.noSuchMethod(invocation);
+ }
+}
+
void testRetainWhere() {
List<int> list = <int>[1, 2, 3];
list.retainWhere((x) => x % 2 == 0);
Expect.equals(1, list.length);
Expect.equals(2, list.first);
+ Expect.equals(2, list[0]);
list = new MyList<int>([1, 2, 3]);
list.retainWhere((x) => x % 2 == 0);
Expect.equals(1, list.length);
Expect.equals(2, list.first);
+ Expect.equals(2, list[0]);
+
+ list = new MyNoSuchMethodList<int>([1, 2, 3]);
+ list.retainWhere((x) => x % 2 == 0);
+ Expect.equals(1, list.length);
+ Expect.equals(2, list.first);
+ Expect.equals(2, list[0]);
+
+ // 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);
+ Expect.equals(2, l[0]);
+ }
+
+ {
+ var l = new MyNoSuchMethodList<int>([1, 2, 3]);
+ l.retainWhere((x) => x % 2 == 0);
+ Expect.equals(1, l.length);
+ Expect.equals(2, l.first);
+ Expect.equals(2, l[0]);
+ }
+
+ // Equivalent tests where the type of the List is not known.
+ {
+ dynamic l = new MyList<int>([1, 2, 3]);
+ l.retainWhere((x) => x % 2 == 0);
+ Expect.equals(1, l.length);
+ Expect.equals(2, l.first);
+ Expect.equals(2, l[0]);
+ }
+
+ {
+ dynamic l = new MyNoSuchMethodList<int>([1, 2, 3]);
+ l.retainWhere((x) => x % 2 == 0);
+ Expect.equals(1, l.length);
+ Expect.equals(2, l.first);
+ Expect.equals(2, l[0]);
+ }
+
+ {
+ dynamic indexable = new MyIndexableNoSuchMethod<int>([1,2,3]);
+ Expect.equals(3, indexable.length);
+ Expect.equals(1, indexable[0]);
+ Expect.equals(3, indexable[2]);
+ indexable.length = 2;
+ Expect.equals(2, indexable.length);
+ Expect.equals(42, indexable.prototype);
+ }
}
void main() {
« no previous file with comments | « tests/language_strong/cast2_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698