Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library test.hierarchy_invariants_test; | 5 library test.hierarchy_invariants_test; |
| 6 | 6 |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 | 8 |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 | 10 |
| 11 isAnonymousMixinApplication(classMirror) { | 11 isAnonymousMixinApplication(classMirror) { |
| 12 return MirrorSystem.getName(classMirror.simpleName).contains(' with '); | 12 return MirrorSystem.getName(classMirror.simpleName).contains(' with '); |
| 13 } | 13 } |
| 14 | 14 |
| 15 check(classMirror) { | 15 checkClass(classMirror) { |
| 16 if (classMirror is TypedefMirror) return; | |
|
rmacnak
2013/11/13 21:41:32
Can't happen anymore since TypedefMirror is no lon
| |
| 17 | |
| 18 Expect.isTrue(classMirror.simpleName is Symbol); | 16 Expect.isTrue(classMirror.simpleName is Symbol); |
| 19 Expect.notEquals(null, classMirror.owner); | 17 Expect.notEquals(null, classMirror.owner); |
| 20 Expect.isTrue(classMirror.owner is LibraryMirror); | 18 Expect.isTrue(classMirror.owner is LibraryMirror); |
| 21 if (!isAnonymousMixinApplication(classMirror)) { | 19 if (!isAnonymousMixinApplication(classMirror)) { |
| 22 Expect.equals(classMirror.originalDeclaration, | 20 Expect.equals(classMirror.originalDeclaration, |
| 23 classMirror.owner.classes[classMirror.simpleName]); | 21 classMirror.owner.classes[classMirror.simpleName]); |
| 24 } else { | 22 } else { |
| 25 Expect.isNull(classMirror.owner.classes[classMirror.simpleName]); | 23 Expect.isNull(classMirror.owner.classes[classMirror.simpleName]); |
| 26 } | 24 } |
| 27 Expect.isTrue(classMirror.superinterfaces is List); | 25 Expect.isTrue(classMirror.superinterfaces is List); |
| 28 if (classMirror.superclass == null) { | 26 if (classMirror.superclass == null) { |
| 29 Expect.equals(reflectClass(Object), classMirror); | 27 Expect.equals(reflectClass(Object), classMirror); |
| 30 } else { | 28 } else { |
| 31 check(classMirror.superclass); | 29 checkClass(classMirror.superclass); |
| 32 } | 30 } |
| 33 } | 31 } |
| 34 | 32 |
| 33 checkLibrary(libraryMirror) { | |
| 34 libraryMirror.classes.values.forEach(checkClass); | |
| 35 } | |
| 36 | |
| 35 main() { | 37 main() { |
| 36 currentMirrorSystem().libraries.values.forEach((libraryMirror) { | 38 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
| 37 libraryMirror.classes.values.forEach((classMirror) { | |
| 38 check(classMirror); | |
| 39 }); | |
| 40 }); | |
| 41 | |
| 42 Expect.throws(() => reflectClass(dynamic), | |
|
rmacnak
2013/11/13 21:41:32
Covered in another test.
| |
| 43 (e) => e is ArgumentError, | |
| 44 'dynamic is not a class'); | |
| 45 } | 39 } |
| OLD | NEW |