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

Unified Diff: tests/language_strong/tearoff_dynamic_test.dart

Issue 2962263002: fix #30030, fix #27327 - fix tearoffs and various Object member bugs (Closed)
Patch Set: fix Created 3 years, 5 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/runtime_type_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language_strong/tearoff_dynamic_test.dart
diff --git a/tests/language_strong/tearoff_dynamic_test.dart b/tests/language_strong/tearoff_dynamic_test.dart
index e23c22fc493d09ab14e32bdac5903831391748b6..cfb0ec507bf67dac69fd327c7f6b1ba5ee01b920 100644
--- a/tests/language_strong/tearoff_dynamic_test.dart
+++ b/tests/language_strong/tearoff_dynamic_test.dart
@@ -1,29 +1,168 @@
-// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
-class Foo {
- dynamic method(int x) {}
- dynamic method2(int x) {}
+class C {
+ dynamic f(int x) => x + 1;
+ dynamic g(int x) => x + 2;
}
-main() {
- Foo foo = new Foo();
+class D extends C {
+ f(int x) => x + 41;
+ get superF => super.f;
+ get superG => super.g;
+}
+
+tearoffEquals(f1, f2) {
+ Expect.equals(f1, f2);
+ Expect.equals(f1.hashCode, f2.hashCode);
+}
+
+tearoffNotEquals(f1, f2) {
+ Expect.notEquals(f1, f2);
+ Expect.notEquals(f1.hashCode, f2.hashCode);
+}
+
+testDynamic() {
+ C c = new C();
+
+ dynamic f1 = c.f;
+ Expect.throws(() => f1(2.5));
+ Expect.equals(f1(41), 42);
- dynamic dynamicMethod1 = foo.method;
- Expect.throws(() => dynamicMethod1(2.5));
+ dynamic f2 = (c as dynamic).f;
+ Expect.throws(() => f2(2.5));
+ Expect.equals(f2(41), 42);
- dynamic dynamicMethod2 = (foo as dynamic).method;
- Expect.throws(() => dynamicMethod2(2.5));
+ tearoffEquals(f1, f1);
+ tearoffEquals(f1, f2);
+ tearoffEquals(f1, c.f);
+ tearoffEquals(c.g, (c as dynamic).g);
- Expect.equals(dynamicMethod1, dynamicMethod1);
- Expect.equals(dynamicMethod1, dynamicMethod2);
- Expect.equals(dynamicMethod1, foo.method);
- Expect.equals(foo.method2, (foo as dynamic).method2);
+ tearoffNotEquals(f1, new C().f);
+ tearoffNotEquals(f1, (new C() as dynamic).f);
+ tearoffNotEquals(f1, c.g);
+ tearoffNotEquals(f1, (c as dynamic).g);
+}
+
+testSuper() {
+ D d = new D();
+ dynamic superF1 = d.superF;
+ dynamic superF2 = (d as dynamic).superF;
+
+ Expect.throws(() => superF1(2.5));
+ Expect.throws(() => superF2(2.5));
+ Expect.equals(superF1(41), 42);
+ Expect.equals(superF2(41), 42);
+
+ tearoffEquals(superF1, superF1);
+ tearoffEquals(superF1, superF2);
+ tearoffEquals(superF1, d.superF);
+ tearoffEquals(d.f, (d as dynamic).f);
+
+ tearoffNotEquals(superF1, d.f);
+ tearoffNotEquals(superF1, (d as dynamic).f);
+ tearoffNotEquals(superF1, new D().superF);
+ tearoffNotEquals(superF1, (new D() as dynamic).superF);
+ tearoffNotEquals(superF1, d.superG);
+ tearoffNotEquals(superF1, (d as dynamic).superG);
+
+ tearoffEquals(d.superG, (d as dynamic).superG);
+ tearoffEquals(d.g, d.superG);
+}
- Expect.notEquals(dynamicMethod1, new Foo().method);
- Expect.notEquals(dynamicMethod1, (new Foo() as dynamic).method);
- Expect.notEquals(dynamicMethod1, foo.method2);
- Expect.notEquals(dynamicMethod1, (foo as dynamic).method2);
+class S {
+ final int id;
+ S(this.id);
+ toString() => 'S#$id';
+}
+
+testToString() {
+ testType<T>(T c) {
+ dynamic d = c;
+ Object o = c;
+ tearoffEquals(c.toString, d.toString);
+ tearoffEquals(c.toString, o.toString);
+
+ var expected = c.toString();
+ dynamic f = d.toString;
+ tearoffEquals(f(), expected);
+ f = o.toString;
+ tearoffEquals(f(), expected);
+ var g = c.toString;
+ tearoffEquals(g(), expected);
+ }
+
+ testType(new C());
+ testType(new D());
+ testType(new S(1));
+ testType(new S(2));
+ testType(new Object());
+ testType(null);
+ testType(Object); // Type
+ testType(C); // Type
+ testType(42);
+ testType('hi');
+ testType(true);
+ testType([1, 2, 3]);
+ testType({'a': 'b'});
+ testType((x) => x + 1);
+ testType(testType);
+}
+
+class N {
+ noSuchMethod(i) => i;
+}
+
+testNoSuchMethod() {
+ // Create an invocation.
+ Invocation i = (new N() as dynamic).foo(1, bar: 2);
+ tearoffEquals(i.memberName, #foo);
+
+ testType<T>(T c) {
+ dynamic d = c;
+ Object o = c;
+ tearoffEquals(c.noSuchMethod, d.noSuchMethod);
+ tearoffEquals(c.noSuchMethod, o.noSuchMethod);
+
+ var expected;
+ try {
+ c.noSuchMethod(i);
+ } on NoSuchMethodError catch (error) {
+ var nsm = '$error';
+ Expect.isTrue(nsm.startsWith("NoSuchMethodError: "));
+ Expect.isTrue(nsm.contains("'foo'"));
+ expected = (e) => e is NoSuchMethodError && '$e' == nsm;
+ }
+ dynamic f = d.noSuchMethod;
+ Expect.throws(() => f(i), expected);
+ f = o.noSuchMethod;
+ Expect.throws(() => f(i), expected);
+ var g = c.noSuchMethod;
+ Expect.throws(() => g(i), expected);
+ }
+
+ testType(new C());
+ testType(new D());
+ testType(new S(1));
+ testType(new S(2));
+ testType(new Object());
+ testType(null);
+ testType(Object); // Type
+ testType(C); // Type
+ testType(42);
+ testType('hi');
+ testType(true);
+ testType([1, 2, 3]);
+ testType({'a': 'b'});
+ testType((x) => x + 1);
+ testType(testType);
+}
+
+main() {
+ testDynamic();
+ testSuper();
+ testToString();
+ testNoSuchMethod();
}
« no previous file with comments | « tests/language_strong/runtime_type_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698