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

Unified Diff: dart/tests/lib/mirrors/mixin_test.dart

Issue 22692002: Implement reflecting on mixin applications. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor bug fixes during testing. Created 7 years, 4 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 | « dart/tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/tests/lib/mirrors/mixin_test.dart
diff --git a/dart/tests/lib/mirrors/mixin_test.dart b/dart/tests/lib/mirrors/mixin_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..86ca0c8d357691968289314f909222a514334db9
--- /dev/null
+++ b/dart/tests/lib/mirrors/mixin_test.dart
@@ -0,0 +1,267 @@
+// Copyright (c) 2013, 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.
+
+// TODO(ahe): This test is sligthly broken but provides temporary test coverage
+// for dart2js. See http://dartbug.com/12464.
+
+library test.mixin_test;
+
+@MirrorsUsed(targets: 'test.mixin_test, test.model, Object', override: '*')
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+import 'model.dart';
+import 'stringify.dart';
+
+class Mixin {
+ int i;
+ m() {}
+}
+
+class Mixin2 {
+ int i2;
+ m2() {}
+}
+
+typedef MixinApplication = C with Mixin;
+typedef MixinApplicationA = C with Mixin, Mixin2;
+
+typedef UnusedMixinApplication = C with Mixin;
+
+class Subclass extends C with Mixin {
+ f() {}
+}
+
+class Subclass2 extends MixinApplication {
+ g() {}
+}
+
+class SubclassA extends C with Mixin, Mixin2 {
+ fa() {}
+}
+
+class Subclass2A extends MixinApplicationA {
+ ga() {}
+}
+
+checkClass(Type type, List<String> expectedSuperclasses) {
+ int i = 0;
+ for (var cls = reflectClass(type); cls != null; cls = cls.superclass) {
+ expect(expectedSuperclasses[i++], cls);
+ }
+ Expect.equals(i, expectedSuperclasses.length, '$type');
+}
+
+expectSame(ClassMirror a, ClassMirror b) {
+ Expect.equals(a, b);
+ expect(stringify(a), b);
+ expect(stringify(b), a);
+}
+
+testMixin() {
+ checkClass(Mixin, [
+ 'Class(s(Mixin) in s(test.mixin_test), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+ expect(
+ '{Mixin: Method(s(Mixin) in s(Mixin), constructor),'
+ ' i: Variable(s(i) in s(Mixin)),'
+ ' m: Method(s(m) in s(Mixin))}',
+ reflectClass(Mixin).members);
+}
+
+testMixin2() {
+ checkClass(Mixin2, [
+ 'Class(s(Mixin2) in s(test.mixin_test), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+ expect(
+ '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),'
+ ' i2: Variable(s(i2) in s(Mixin2)),'
+ ' m2: Method(s(m2) in s(Mixin2))}',
+ reflectClass(Mixin2).members);
+}
+
+testMixinApplication() {
+ checkClass(MixinApplication, [
+ 'Class(s(MixinApplication) in s(test.mixin_test), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{MixinApplication: Method(s(MixinApplication) in s(MixinApplication),'
+ ' constructor),'
+ ' i: Variable(s(i) in s(MixinApplication)),'
+ ' m: Method(s(m) in s(MixinApplication))}',
+ reflectClass(MixinApplication).members);
+
+ expectSame(reflectClass(C), reflectClass(MixinApplication).superclass);
+}
+
+testMixinApplicationA() {
+ checkClass(MixinApplicationA, [
+ 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)',
+ 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{MixinApplicationA: Method(s(MixinApplicationA) in s(MixinApplicationA),'
+ ' constructor),'
+ ' i2: Variable(s(i2) in s(MixinApplicationA)),'
+ ' m2: Method(s(m2) in s(MixinApplicationA))}',
+ reflectClass(MixinApplicationA).members);
+
+ expect(
+ // TODO(ahe): The owner should probably be the mixin application.
+ '{Mixin: Method(s(Mixin) in s(Mixin), constructor),'
+ ' i: Variable(s(i) in s(Mixin)),'
+ ' m: Method(s(m) in s(Mixin))}',
+ reflectClass(MixinApplicationA).superclass.members);
+
+ expectSame(
+ reflectClass(C),
+ reflectClass(MixinApplicationA).superclass.superclass);
+}
+
+testUnusedMixinApplication() {
+ checkClass(UnusedMixinApplication, [
+ 'Class(s(UnusedMixinApplication) in s(test.mixin_test), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{UnusedMixinApplication: Method(s(UnusedMixinApplication)'
+ ' in s(UnusedMixinApplication), constructor),'
+ ' i: Variable(s(i) in s(UnusedMixinApplication)),'
+ ' m: Method(s(m) in s(UnusedMixinApplication))}',
+ reflectClass(UnusedMixinApplication).members);
+
+ expectSame(reflectClass(C), reflectClass(UnusedMixinApplication).superclass);
+}
+
+testSubclass() {
+ checkClass(Subclass, [
+ 'Class(s(Subclass) in s(test.mixin_test), top-level)',
+ 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{Subclass: Method(s(Subclass) in s(Subclass), constructor),'
+ ' f: Method(s(f) in s(Subclass))}',
+ reflectClass(Subclass).members);
+
+ expect(
+ // TODO(ahe): The owner should probably be the mixin application.
+ '{Mixin: Method(s(Mixin) in s(Mixin), constructor),'
+ ' i: Variable(s(i) in s(Mixin)),'
+ ' m: Method(s(m) in s(Mixin))}',
+ reflectClass(Subclass).superclass.members);
+
+ expectSame(
+ reflectClass(C),
+ reflectClass(Subclass).superclass.superclass);
+}
+
+testSubclass2() {
+ checkClass(Subclass2, [
+ 'Class(s(Subclass2) in s(test.mixin_test), top-level)',
+ 'Class(s(MixinApplication) in s(test.mixin_test), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{Subclass2: Method(s(Subclass2) in s(Subclass2), constructor),'
+ ' g: Method(s(g) in s(Subclass2))}',
+ reflectClass(Subclass2).members);
+
+ expectSame(
+ reflectClass(MixinApplication),
+ reflectClass(Subclass2).superclass);
+}
+
+testSubclassA() {
+ checkClass(SubclassA, [
+ 'Class(s(SubclassA) in s(test.mixin_test), top-level)',
+ 'Class(s(test.mixin_test.Mixin2(test.mixin_test.Mixin(test.model.C))),'
+ ' top-level)',
+ 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{SubclassA: Method(s(SubclassA) in s(SubclassA), constructor),'
+ ' fa: Method(s(fa) in s(SubclassA))}',
+ reflectClass(SubclassA).members);
+
+ expect(
+ // TODO(ahe): The owner should probably be the mixin application.
+ '{Mixin2: Method(s(Mixin2) in s(Mixin2), constructor),'
+ ' i2: Variable(s(i2) in s(Mixin2)),'
+ ' m2: Method(s(m2) in s(Mixin2))}',
+ reflectClass(SubclassA).superclass.members);
+
+ expect(
+ // TODO(ahe): The owner should probably be the mixin application.
+ '{Mixin: Method(s(Mixin) in s(Mixin), constructor),'
+ ' i: Variable(s(i) in s(Mixin)),'
+ ' m: Method(s(m) in s(Mixin))}',
+ reflectClass(SubclassA).superclass.superclass.members);
+
+ expectSame(
+ reflectClass(C),
+ reflectClass(SubclassA).superclass.superclass.superclass);
+}
+
+testSubclass2A() {
+ checkClass(Subclass2A, [
+ 'Class(s(Subclass2A) in s(test.mixin_test), top-level)',
+ 'Class(s(MixinApplicationA) in s(test.mixin_test), top-level)',
+ 'Class(s(test.mixin_test.Mixin(test.model.C)), top-level)',
+ 'Class(s(C) in s(test.model), top-level)',
+ 'Class(s(B) in s(test.model), top-level)',
+ 'Class(s(A) in s(test.model), top-level)',
+ 'Class(s(Object) in s(dart.core), top-level)',
+ ]);
+
+ expect(
+ '{Subclass2A: Method(s(Subclass2A) in s(Subclass2A), constructor),'
+ ' ga: Method(s(ga) in s(Subclass2A))}',
+ reflectClass(Subclass2A).members);
+
+ expectSame(reflectClass(MixinApplicationA),
+ reflectClass(Subclass2A).superclass);
+}
+
+main() {
+ testMixin();
+ testMixin2();
+ testMixinApplication();
+ testMixinApplicationA();
+ testUnusedMixinApplication();
+ testSubclass();
+ testSubclass2();
+ testSubclassA();
+ testSubclass2A();
+}
« no previous file with comments | « dart/tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698