| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this | 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 | 2 // source code is governed by a BSD-style license that can be found in |
| 3 // the LICENSE file. | 3 // the LICENSE file. |
| 4 | 4 |
| 5 /// Tests that metadata is preserved when the metadataCapability is present. | 5 /// Tests that metadata is preserved when the metadataCapability is present. |
| 6 // TODO(sigurdm) implement: Support for metadata-annotations of arguments. | 6 // TODO(sigurdm) implement: Support for metadata-annotations of arguments. |
| 7 | 7 |
| 8 library test_reflectable.test.metadata_test; | 8 library test_reflectable.test.metadata_test; |
| 9 | 9 |
| 10 import 'package:reflectable/reflectable.dart'; | 10 import 'package:reflectable/reflectable.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 class MyReflectable extends Reflectable { | 13 class MyReflectable extends Reflectable { |
| 14 const MyReflectable() : super( | 14 const MyReflectable() |
| 15 metadataCapability, instanceInvokeCapability, staticInvokeCapability); | 15 : super(metadataCapability, instanceInvokeCapability, |
| 16 staticInvokeCapability, declarationsCapability); |
| 16 } | 17 } |
| 17 | 18 |
| 18 const myReflectable = const MyReflectable(); | 19 const myReflectable = const MyReflectable(); |
| 19 | 20 |
| 20 class MyReflectable2 extends Reflectable { | 21 class MyReflectable2 extends Reflectable { |
| 21 const MyReflectable2() | 22 const MyReflectable2() |
| 22 : super(instanceInvokeCapability, staticInvokeCapability); | 23 : super(instanceInvokeCapability, staticInvokeCapability); |
| 23 } | 24 } |
| 24 | 25 |
| 25 const myReflectable2 = const MyReflectable2(); | 26 const myReflectable2 = const MyReflectable2(); |
| 26 | 27 |
| 27 const b = 13; | 28 const b = 13; |
| 28 const c = const [const Bar(const {"a": 14})]; | 29 const c = const [ |
| 30 const Bar(const {"a": 14}) |
| 31 ]; |
| 29 const d = true; | 32 const d = true; |
| 30 | 33 |
| 31 class K { | 34 class K { |
| 32 static const p = 2; | 35 static const p = 2; |
| 33 } | 36 } |
| 34 | 37 |
| 35 @myReflectable | 38 @myReflectable |
| 36 @Bar(const { | 39 @Bar(const { |
| 37 b: deprecated, | 40 b: deprecated, |
| 38 c: const Deprecated("tomorrow"), | 41 c: const Deprecated("tomorrow"), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 expect(myReflectable.reflectType(Foo).metadata, [ | 77 expect(myReflectable.reflectType(Foo).metadata, [ |
| 75 const MyReflectable(), | 78 const MyReflectable(), |
| 76 const Bar(const { | 79 const Bar(const { |
| 77 b: deprecated, | 80 b: deprecated, |
| 78 c: const Deprecated("tomorrow"), | 81 c: const Deprecated("tomorrow"), |
| 79 3: 3, | 82 3: 3, |
| 80 false: "s", | 83 false: "s", |
| 81 2: 6 | 84 2: 6 |
| 82 }), | 85 }), |
| 83 13, | 86 13, |
| 84 const [const Bar(const {"a": 14})] | 87 const [ |
| 88 const Bar(const {"a": 14}) |
| 89 ] |
| 85 ]); | 90 ]); |
| 86 | 91 |
| 87 expect(myReflectable.reflectType(Foo).declarations["foo"].metadata, [ | 92 expect(myReflectable.reflectType(Foo).declarations["foo"].metadata, [ |
| 88 const Bar(const {}), | 93 const Bar(const {}), |
| 89 13, | 94 13, |
| 90 const [const Bar(const {"a": 14})] | 95 const [ |
| 96 const Bar(const {"a": 14}) |
| 97 ] |
| 91 ]); | 98 ]); |
| 92 | 99 |
| 93 expect(myReflectable.reflectType(Foo).declarations["x"].metadata, [b]); | 100 expect(myReflectable.reflectType(Foo).declarations["x"].metadata, [b]); |
| 94 | 101 |
| 95 // The synthetic accessors do not have metadata. | 102 // The synthetic accessors do not have metadata. |
| 96 expect(myReflectable.reflectType(Foo).instanceMembers["x"].metadata, []); | 103 expect(myReflectable.reflectType(Foo).instanceMembers["x"].metadata, []); |
| 97 expect(myReflectable.reflectType(Foo).instanceMembers["x="].metadata, []); | 104 expect(myReflectable.reflectType(Foo).instanceMembers["x="].metadata, []); |
| 98 }); | 105 }); |
| 99 test("metadata without capability", () { | 106 test("metadata without capability", () { |
| 100 expect(() => myReflectable2.reflectType(Foo2).metadata, | 107 expect(() => myReflectable2.reflectType(Foo2).metadata, |
| 101 throwsA(const isInstanceOf<NoSuchCapabilityError>())); | 108 throwsA(const isInstanceOf<NoSuchCapabilityError>())); |
| 102 | 109 |
| 103 expect(() => myReflectable2.reflectType(Foo2).declarations["foo"].metadata, | 110 expect(() => myReflectable2.reflectType(Foo2).declarations["foo"].metadata, |
| 104 throwsA(const isInstanceOf<NoSuchCapabilityError>())); | 111 throwsA(const isInstanceOf<NoSuchCapabilityError>())); |
| 105 }); | 112 }); |
| 106 } | 113 } |
| OLD | NEW |