| 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.members, 'ClassMirror.members'); |
| 45 checkMap(cm.variables, 'ClassMirror.variables'); |
| 46 checkMap(cm.methods, 'ClassMirror.methods'); |
| 47 checkMap(cm.getters, 'ClassMirror.getters'); |
| 48 checkMap(cm.setters, 'ClassMirror.setters'); |
| 49 checkMap(cm.constructors, 'ClassMirror.constructors'); |
| 50 checkList(cm.metadata, 'ClassMirror.metadata'); |
| 51 checkList(cm.superinterfaces, 'ClassMirror.superinterfaces'); |
| 52 checkList(cm.typeArguments, 'ClassMirror.typeArguments'); |
| 53 checkList(cm.typeVariables, 'ClassMirror.typeVariables'); |
| 54 |
| 55 cm.methods.values.forEach(checkMethod); |
| 56 cm.getters.values.forEach(checkMethod); |
| 57 cm.setters.values.forEach(checkMethod); |
| 58 cm.constructors.values.forEach(checkMethod); |
| 59 cm.variables.values.forEach(checkVariable); |
| 60 cm.typeVariables.forEach(checkTypeVariable); |
| 61 } |
| 62 |
| 63 checkLibrary(LibraryMirror lm) { |
| 64 checkMap(lm.members, 'LibraryMirror.members'); |
| 65 checkMap(lm.variables, 'LibraryMirror.variables'); |
| 66 checkMap(lm.classes, 'LibraryMirror.classes'); |
| 67 // TODO(rmacnak): Revisit after members hoisted to TypeMirror. |
| 68 // checkMap(lm.types, 'LibraryMirror.types'); |
| 69 checkMap(lm.functions, 'LibraryMirror.functions'); |
| 70 checkMap(lm.getters, 'LibraryMirror.getters'); |
| 71 checkMap(lm.setters, 'LibraryMirror.setters'); |
| 72 checkList(lm.metadata, 'LibraryMirror.metadata'); |
| 73 |
| 74 // lm.types.forEach(checkType); |
| 75 lm.classes.values.forEach(checkClass); |
| 76 lm.functions.values.forEach(checkMethod); |
| 77 lm.getters.values.forEach(checkMethod); |
| 78 lm.setters.values.forEach(checkMethod); |
| 79 lm.variables.values.forEach(checkVariable); |
| 80 } |
| 81 |
| 82 main() { |
| 83 currentMirrorSystem().libraries.values.forEach(checkLibrary); |
| 84 // checkType(currentMirrorSystem().voidType); |
| 85 // checkType(currentMirrorSystem().dynamicType); |
| 86 } |
| OLD | NEW |