Chromium Code Reviews| Index: test_reflectable/test/meta_reflectors_user.dart |
| diff --git a/test_reflectable/test/meta_reflectors_user.dart b/test_reflectable/test/meta_reflectors_user.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..41510d175ac37dc2abfed4c00fb1032376307464 |
| --- /dev/null |
| +++ b/test_reflectable/test/meta_reflectors_user.dart |
| @@ -0,0 +1,135 @@ |
| +// Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
| +// source code is governed by a BSD-style license that can be found in |
| +// the LICENSE file. |
| + |
| +// File being transformed by the reflectable transformer. |
| +// Part of the entry point 'reflectors_test.dart'. |
| +// |
| +// Independence: This library depends on the domain classes `M1`..`M3`, |
| +// `A`..`D`, `P`, and it dynamically uses the reflectors, but it does not |
| +// statically depend on 'meta_reflectors_definer.dart' nor on |
| +// 'meta_reflectors_domain_definer.dart'. |
| + |
| +library test_reflectable.test.meta_reflectors_user; |
| + |
| +import "package:reflectable/reflectable.dart"; |
| +import "package:unittest/unittest.dart"; |
| +import "meta_reflectors_scoping.dart"; |
| +import "meta_reflectors_domain.dart"; |
| + |
| +testReflector(Reflectable reflector, String desc) { |
| + test("Mixin, $desc", () { |
| + ClassMirror aMirror = reflector.reflectType(A); |
| + ClassMirror bMirror = reflector.reflectType(B); |
| + ClassMirror cMirror = reflector.reflectType(C); |
| + ClassMirror dMirror = reflector.reflectType(D); |
| + ClassMirror m1Mirror = reflector.reflectType(M1); |
| + ClassMirror m2Mirror = reflector.reflectType(M2); |
| + ClassMirror m3Mirror = reflector.reflectType(M3); |
| + expect(aMirror.mixin, aMirror); |
| + expect(bMirror.mixin, bMirror); |
| + expect(cMirror.mixin, cMirror); |
| + expect(m1Mirror.mixin, m1Mirror); |
| + expect(m2Mirror.mixin, m2Mirror); |
| + expect(m3Mirror.mixin, m3Mirror); |
| + expect(bMirror.superclass.mixin, m1Mirror); |
| + expect(cMirror.superclass.superclass.mixin, m2Mirror); |
| + expect(cMirror.superclass.mixin, m3Mirror); |
| + expect(cMirror.superclass.superclass.superclass, bMirror); |
| + expect(dMirror.mixin, m1Mirror); |
| + expect(dMirror.superclass.mixin, aMirror); |
| + expect(bMirror.superclass.declarations["foo"].owner, m1Mirror); |
| + expect(bMirror.superclass.declarations["field"].owner, m1Mirror); |
| + expect(bMirror.superclass.declarations["staticBar"], null); |
| + expect(bMirror.superclass.hasReflectedType, true); |
| + expect(bMirror.superclass.reflectedType, const isInstanceOf<Type>()); |
| + expect(bMirror.superclass.superclass.reflectedType, |
| + const isInstanceOf<Type>()); |
| + }); |
| +} |
| + |
| +Matcher throwsANoSuchCapabilityException = |
| + throwsA(const isInstanceOf<NoSuchCapabilityError>()); |
| + |
| +Iterable<String> getNames(Iterable<Reflectable> reflectables) { |
| + return reflectables.map((Reflectable reflector) { |
| + String fullString = reflector.toString(); |
| + return fullString.substring(13, fullString.length - 1); |
| + }); |
| +} |
| + |
| +doit() { |
|
sigurdm
2015/10/09 07:52:04
what is 'it'? maybe call it: 'runTests'
eernst
2015/10/09 10:09:05
Done.
|
| + test("MetaReflector, set of reflectors", () { |
| + List<Reflectable> reflectors = Reflectable.reflectors.toList(); |
| + expect( |
| + getNames(reflectors).toSet(), |
| + [ |
| + "Reflector", |
| + "Reflector2", |
| + "ReflectorUpwardsClosed", |
| + "ReflectorUpwardsClosedToA", |
| + "ReflectorUpwardsClosedUntilA", |
| + "ScopeMetaReflector" |
| + ].toSet()); |
| + expect(getNames(const ScopeMetaReflector().reflectablesOfScope("polymer")), |
| + ["Reflector", "ReflectorUpwardsClosed"].toSet()); |
| + expect(getNames(const ScopeMetaReflector().reflectablesOfScope("observe")), |
| + ["Reflector2", "ReflectorUpwardsClosed"].toSet()); |
| + }); |
| + |
| + const ScopeMetaReflector().reflectablesOfScope("polymer").forEach( |
| + (Reflectable reflector) => testReflector(reflector, "$reflector")); |
| + |
| + test("MetaReflector, select by name", () { |
| + var reflector2 = Reflectable.reflectors |
| + .firstWhere((Reflectable reflector) => "$reflector".contains("2")); |
| + ClassMirror bMirror = reflector2.reflectType(B); |
| + ClassMirror cMirror = reflector2.reflectType(C); |
| + ClassMirror dMirror = reflector2.reflectType(D); |
| + ClassMirror m1Mirror = reflector2.reflectType(M1); |
| + ClassMirror m2Mirror = reflector2.reflectType(M2); |
| + ClassMirror m3Mirror = reflector2.reflectType(M3); |
| + expect(bMirror.mixin, bMirror); |
| + expect(cMirror.mixin, cMirror); |
| + expect(dMirror.mixin, m1Mirror); |
| + expect(m1Mirror.mixin, m1Mirror); |
| + // Test that metadata is preserved. |
| + expect(m1Mirror.metadata, contains(const P())); |
| + expect(m2Mirror.mixin, m2Mirror); |
| + expect(m3Mirror.mixin, m3Mirror); |
| + expect(bMirror.superclass.mixin, m1Mirror); |
| + // Test that the mixin-application does not inherit the metadata from its |
| + // mixin. |
| + expect(bMirror.superclass.metadata, isEmpty); |
| + expect( |
| + () => bMirror.superclass.superclass, throwsANoSuchCapabilityException); |
| + expect(cMirror.superclass.superclass.mixin, m2Mirror); |
| + expect(cMirror.superclass.mixin, m3Mirror); |
| + expect(cMirror.superclass.superclass.superclass, bMirror); |
| + expect(() => dMirror.superclass, throwsANoSuchCapabilityException); |
| + }); |
| + |
| + test("MetaReflector, select by capability", () { |
| + var reflector = Reflectable.reflectors.firstWhere((Reflectable reflector) { |
| + return (reflector.capabilities.any((ReflectCapability capability) => |
| + capability is SuperclassQuantifyCapability && |
| + capability.upperBound == A && |
| + !capability.excludeUpperBound)); |
| + }); |
| + ClassMirror aMirror = reflector.reflectType(A); |
| + ClassMirror bMirror = reflector.reflectType(B); |
| + ClassMirror cMirror = reflector.reflectType(C); |
| + ClassMirror dMirror = reflector.reflectType(D); |
| + expect(() => reflector.reflectType(M1), throwsANoSuchCapabilityException); |
| + expect(() => reflector.reflectType(M2), throwsANoSuchCapabilityException); |
| + expect(() => reflector.reflectType(M3), throwsANoSuchCapabilityException); |
| + expect(() => bMirror.superclass.mixin, throwsANoSuchCapabilityException); |
| + expect(bMirror.superclass.superclass, aMirror); |
| + expect(() => cMirror.superclass.mixin, throwsANoSuchCapabilityException); |
| + expect(() => cMirror.superclass.superclass.mixin, |
| + throwsANoSuchCapabilityException); |
| + expect(cMirror.superclass.superclass.superclass, bMirror); |
| + expect(() => dMirror.mixin, throwsANoSuchCapabilityException); |
| + expect(dMirror.superclass, aMirror); |
| + }); |
| +} |