OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.immutable_collections; |
| 6 |
| 7 import 'dart:mirrors'; |
| 8 import 'package:expect/expect.dart'; |
| 9 |
| 10 someException(e) => e is Exception || e is Error; |
| 11 |
| 12 checkList(Iterable l, String reason) { |
| 13 Expect.throws(() => l[0] = 'value', someException, reason); |
| 14 Expect.throws(() => l.add('value'), someException, reason); |
| 15 Expect.throws(() => l.clear(), someException, reason); |
| 16 } |
| 17 |
| 18 checkMap(Map m, String reason) { |
| 19 Expect.throws(() => m[#key] = 'value', someException, reason); |
| 20 checkList(m.keys, '$reason keys'); |
| 21 checkList(m.values, '$reason values'); |
| 22 } |
| 23 |
| 24 checkVariable(VariableMirror vm) { |
| 25 checkList(vm.metadata, 'VariableMirror.metadata'); |
| 26 } |
| 27 |
| 28 checkTypeVariable(TypeVariableMirror tvm) { |
| 29 checkList(tvm.metadata, 'TypeVariableMirror.metadata'); |
| 30 } |
| 31 |
| 32 checkParameter(ParameterMirror pm) { |
| 33 checkList(pm.metadata, 'ParameterMirror.metadata'); |
| 34 } |
| 35 |
| 36 checkMethod(MethodMirror mm) { |
| 37 checkList(mm.parameters, 'MethodMirror.parameters'); |
| 38 checkList(mm.metadata, 'MethodMirror.metadata'); |
| 39 |
| 40 mm.parameters.forEach(checkParameter); |
| 41 } |
| 42 |
| 43 checkClass(ClassMirror cm) { |
| 44 checkMap(cm.declarations, 'ClassMirror.declarations'); |
| 45 checkMap(cm.instanceMembers, 'ClassMirror.instanceMembers'); |
| 46 checkMap(cm.staticMembers, 'ClassMirror.staticMembers'); |
| 47 checkList(cm.metadata, 'ClassMirror.metadata'); |
| 48 checkList(cm.superinterfaces, 'ClassMirror.superinterfaces'); |
| 49 checkList(cm.typeArguments, 'ClassMirror.typeArguments'); |
| 50 checkList(cm.typeVariables, 'ClassMirror.typeVariables'); |
| 51 |
| 52 cm.declarations.values.forEach(checkDeclaration); |
| 53 cm.instanceMembers.values.forEach(checkDeclaration); |
| 54 cm.staticMembers.values.forEach(checkDeclaration); |
| 55 cm.typeVariables.forEach(checkTypeVariable); |
| 56 } |
| 57 |
| 58 checkType(TypeMirror tm) { |
| 59 checkList(tm.metadata, 'TypeMirror.metadata'); |
| 60 } |
| 61 |
| 62 checkDeclaration(DeclarationMirror dm) { |
| 63 if (dm is MethodMirror) checkMethod(dm); |
| 64 if (dm is ClassMirror) checkClass(dm); |
| 65 if (dm is TypeMirror) checkType(dm); |
| 66 if (dm is VariableMirror) checkVariable(dm); |
| 67 if (dm is TypeVariableMirror) checkTypeVariable(dm); |
| 68 } |
| 69 |
| 70 checkLibrary(LibraryMirror lm) { |
| 71 checkMap(lm.declarations, 'LibraryMirror.declarations'); |
| 72 checkList(lm.metadata, 'LibraryMirror.metadata'); |
| 73 |
| 74 lm.declarations.values.forEach(checkDeclaration); |
| 75 } |
| 76 |
| 77 main() { |
| 78 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
| 79 checkType(currentMirrorSystem().voidType); |
| 80 checkType(currentMirrorSystem().dynamicType); |
| 81 } |
OLD | NEW |