OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 Google Inc. All Rights Reserved. |
| 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at |
| 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. |
| 14 |
| 15 library quiver.mirrors_test; |
| 16 |
| 17 import 'dart:collection'; |
| 18 import 'dart:mirrors'; |
| 19 |
| 20 import 'package:quiver/mirrors.dart'; |
| 21 import 'package:test/test.dart'; |
| 22 |
| 23 main() { |
| 24 group('getTypeName', () { |
| 25 test('should return the qualified name for a type', () { |
| 26 expect(getTypeName(Object), const Symbol('dart.core.Object')); |
| 27 expect(getTypeName(Foo), const Symbol('quiver.mirrors_test.Foo')); |
| 28 }); |
| 29 }); |
| 30 |
| 31 group('implements', () { |
| 32 test('should return true if an object implements an interface', () { |
| 33 var foo = new Foo(); |
| 34 expect(implements(foo, Object), true); |
| 35 expect(implements(foo, Foo), true); |
| 36 expect(implements(foo, Comparable), true); |
| 37 expect(implements(foo, Iterable), true); |
| 38 }); |
| 39 |
| 40 test("should return false if an object doesn't implement an interface", () { |
| 41 var foo = new Foo(); |
| 42 expect(implements(foo, String), false); |
| 43 expect(implements(foo, num), false); |
| 44 }); |
| 45 }); |
| 46 |
| 47 group('classImplements', () { |
| 48 test('should return true if an class implements an interface', () { |
| 49 var foo = new Foo(); |
| 50 var mirror = reflect(foo).type; |
| 51 expect(classImplements(mirror, reflectClass(Object)), true); |
| 52 expect(classImplements(mirror, reflectClass(Foo)), true); |
| 53 expect(classImplements(mirror, reflectClass(Comparable)), true); |
| 54 expect(classImplements(mirror, reflectClass(Iterable)), true); |
| 55 }); |
| 56 |
| 57 test("should return false if an object doesn't implement an interface", () { |
| 58 var foo = new Foo(); |
| 59 var mirror = reflect(foo).type; |
| 60 expect(classImplements(mirror, reflectClass(String)), false); |
| 61 expect(classImplements(mirror, reflectClass(num)), false); |
| 62 }); |
| 63 }); |
| 64 |
| 65 group('getMemberMirror', () { |
| 66 test('should return a member of a class', () { |
| 67 var mirror = reflect(new Foo()).type; |
| 68 expect(getDeclaration(mirror, const Symbol('toString')), |
| 69 new isInstanceOf<MethodMirror>()); |
| 70 expect(getDeclaration(mirror, const Symbol('a')), |
| 71 new isInstanceOf<VariableMirror>()); |
| 72 }); |
| 73 }); |
| 74 |
| 75 group('Method', () { |
| 76 test('should be callable', () { |
| 77 var i = 2; |
| 78 var mirror = reflect(i); |
| 79 var method = new Method(mirror, const Symbol('+')); |
| 80 expect(method(3), 5); |
| 81 }); |
| 82 |
| 83 test('should be callable with named arguments', () { |
| 84 // this test will fail when named argument support is added |
| 85 var i = [1, 2]; |
| 86 var mirror = reflect(i); |
| 87 var method = new Method(mirror, const Symbol('toList')); |
| 88 expect(method(growable: false), [1, 2]); |
| 89 }); |
| 90 }); |
| 91 } |
| 92 |
| 93 class Foo extends IterableBase implements Comparable { |
| 94 String a; |
| 95 get iterator => null; |
| 96 int compareTo(o) => 0; |
| 97 } |
OLD | NEW |