OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in |
| 3 // the LICENSE file. |
| 4 |
| 5 // File being transformed by the reflectable transformer. |
| 6 // Uses `dynamicReflectedType`. |
| 7 |
| 8 library test_reflectable.test.dynamic_reflected_type_test; |
| 9 |
| 10 import 'package:reflectable/reflectable.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 class Reflector extends Reflectable { |
| 14 const Reflector() : super(typeCapability); |
| 15 } |
| 16 |
| 17 const reflector = const Reflector(); |
| 18 |
| 19 @reflector |
| 20 class A {} |
| 21 |
| 22 @reflector |
| 23 class B<E> {} |
| 24 |
| 25 Matcher throwsUnsupported = throwsA(const isInstanceOf<UnsupportedError>()); |
| 26 |
| 27 void testDynamicReflectedType( |
| 28 String message, ClassMirror classMirror, Type expectedType) { |
| 29 test('Dynamic reflected type, $message', () { |
| 30 if (classMirror.hasDynamicReflectedType) { |
| 31 expect(classMirror.dynamicReflectedType, expectedType); |
| 32 } else { |
| 33 expect(() => classMirror.dynamicReflectedType, throwsUnsupported); |
| 34 } |
| 35 }); |
| 36 } |
| 37 |
| 38 main() { |
| 39 ClassMirror aMirror = reflector.reflectType(A); |
| 40 ClassMirror bMirror = reflector.reflectType(B); |
| 41 ClassMirror bInstantiationMirror = reflector.reflect(new B<int>()).type; |
| 42 testDynamicReflectedType('non-generic class', aMirror, A); |
| 43 testDynamicReflectedType('generic class', bMirror, B); |
| 44 testDynamicReflectedType('generic instantiation', bInstantiationMirror, B); |
| 45 } |
OLD | NEW |