| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'memory_compiler.dart'; | 8 import 'memory_compiler.dart'; |
| 9 import 'package:compiler/src/mirrors/source_mirrors.dart'; | 9 import 'package:compiler/src/mirrors/source_mirrors.dart'; |
| 10 | 10 |
| 11 const SOURCE_FILES = const { | 11 const SOURCE_FILES = const { |
| 12 'main.dart': ''' | 12 'main.dart': ''' |
| 13 import 'a.dart' show A1, A2; | 13 import 'a.dart' show A1, A2; |
| 14 import 'b.dart' as b hide B1; | 14 import 'b.dart' as b hide B1; |
| 15 export 'a.dart' show A2 hide A3, A1; | 15 export 'a.dart' show A2 hide A3, A1; |
| 16 export 'b.dart' hide B1, B2 show B3; | 16 export 'b.dart' hide B1, B2 show B3; |
| 17 import 'dart:core' as core; | 17 import 'dart:core' as core; |
| 18 import 'c.dart' deferred as c; |
| 18 | 19 |
| 19 main() {} | 20 main() {} |
| 20 ''', | 21 ''', |
| 21 'a.dart': ''' | 22 'a.dart': ''' |
| 22 class A1 {} | 23 class A1 {} |
| 23 class A2 {} | 24 class A2 {} |
| 24 class A3 {} | 25 class A3 {} |
| 25 ''', | 26 ''', |
| 26 'b.dart': ''' | 27 'b.dart': ''' |
| 27 class B1 {} | 28 class B1 {} |
| 28 class B2 {} | 29 class B2 {} |
| 29 class B3 {} | 30 class B3 {} |
| 31 ''', |
| 32 'c.dart': ''' |
| 33 foo() => 499; |
| 30 ''' | 34 ''' |
| 31 }; | 35 }; |
| 32 | 36 |
| 33 void main() { | 37 void main() { |
| 34 asyncTest(() => mirrorSystemFor(SOURCE_FILES).then((MirrorSystem mirrors) { | 38 asyncTest(() => mirrorSystemFor(SOURCE_FILES).then((MirrorSystem mirrors) { |
| 35 LibrarySourceMirror mainLibrary = | 39 LibrarySourceMirror mainLibrary = |
| 36 mirrors.libraries[Uri.parse('memory:main.dart')]; | 40 mirrors.libraries[Uri.parse('memory:main.dart')]; |
| 37 Expect.isNotNull(mainLibrary); | 41 Expect.isNotNull(mainLibrary); |
| 38 | 42 |
| 39 LibrarySourceMirror aLibrary = | 43 LibrarySourceMirror aLibrary = |
| 40 mirrors.libraries[Uri.parse('memory:a.dart')]; | 44 mirrors.libraries[Uri.parse('memory:a.dart')]; |
| 41 Expect.isNotNull(aLibrary); | 45 Expect.isNotNull(aLibrary); |
| 42 | 46 |
| 43 LibrarySourceMirror bLibrary = | 47 LibrarySourceMirror bLibrary = |
| 44 mirrors.libraries[Uri.parse('memory:b.dart')]; | 48 mirrors.libraries[Uri.parse('memory:b.dart')]; |
| 45 Expect.isNotNull(bLibrary); | 49 Expect.isNotNull(bLibrary); |
| 46 | 50 |
| 51 LibrarySourceMirror cLibrary = |
| 52 mirrors.libraries[Uri.parse('memory:c.dart')]; |
| 53 Expect.isNotNull(cLibrary); |
| 54 |
| 47 LibrarySourceMirror coreLibrary = | 55 LibrarySourceMirror coreLibrary = |
| 48 mirrors.libraries[Uri.parse('dart:core')]; | 56 mirrors.libraries[Uri.parse('dart:core')]; |
| 49 Expect.isNotNull(coreLibrary); | 57 Expect.isNotNull(coreLibrary); |
| 50 | 58 |
| 51 var dependencies = mainLibrary.libraryDependencies; | 59 var dependencies = mainLibrary.libraryDependencies; |
| 52 Expect.isNotNull(dependencies); | 60 Expect.isNotNull(dependencies); |
| 53 Expect.equals(5, dependencies.length); | 61 Expect.equals(6, dependencies.length); |
| 54 | 62 |
| 55 // import 'a.dart' show A1, A2; | 63 // import 'a.dart' show A1, A2; |
| 56 var dependency = dependencies[0]; | 64 var dependency = dependencies[0]; |
| 57 Expect.isNotNull(dependency); | 65 Expect.isNotNull(dependency); |
| 58 Expect.isTrue(dependency.isImport); | 66 Expect.isTrue(dependency.isImport); |
| 59 Expect.isFalse(dependency.isExport); | 67 Expect.isFalse(dependency.isExport); |
| 60 Expect.equals(mainLibrary, dependency.sourceLibrary); | 68 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 61 Expect.equals(aLibrary, dependency.targetLibrary); | 69 Expect.equals(aLibrary, dependency.targetLibrary); |
| 62 Expect.isNull(dependency.prefix); | 70 Expect.isNull(dependency.prefix); |
| 71 Expect.isFalse(dependency.isDeferred); |
| 63 | 72 |
| 64 var combinators = dependency.combinators; | 73 var combinators = dependency.combinators; |
| 65 Expect.isNotNull(combinators); | 74 Expect.isNotNull(combinators); |
| 66 Expect.equals(1, combinators.length); | 75 Expect.equals(1, combinators.length); |
| 67 | 76 |
| 68 var combinator = combinators[0]; | 77 var combinator = combinators[0]; |
| 69 Expect.isNotNull(combinator); | 78 Expect.isNotNull(combinator); |
| 70 Expect.isTrue(combinator.isShow); | 79 Expect.isTrue(combinator.isShow); |
| 71 Expect.isFalse(combinator.isHide); | 80 Expect.isFalse(combinator.isHide); |
| 72 Expect.listEquals(['A1', 'A2'], combinator.identifiers); | 81 Expect.listEquals(['A1', 'A2'], combinator.identifiers); |
| 73 | 82 |
| 74 // import 'b.dart' as b hide B1; | 83 // import 'b.dart' as b hide B1; |
| 75 dependency = dependencies[1]; | 84 dependency = dependencies[1]; |
| 76 Expect.isNotNull(dependency); | 85 Expect.isNotNull(dependency); |
| 77 Expect.isTrue(dependency.isImport); | 86 Expect.isTrue(dependency.isImport); |
| 78 Expect.isFalse(dependency.isExport); | 87 Expect.isFalse(dependency.isExport); |
| 79 Expect.equals(mainLibrary, dependency.sourceLibrary); | 88 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 80 Expect.equals(bLibrary, dependency.targetLibrary); | 89 Expect.equals(bLibrary, dependency.targetLibrary); |
| 81 Expect.equals('b', dependency.prefix); | 90 Expect.equals('b', dependency.prefix); |
| 91 Expect.isFalse(dependency.isDeferred); |
| 82 | 92 |
| 83 combinators = dependency.combinators; | 93 combinators = dependency.combinators; |
| 84 Expect.isNotNull(combinators); | 94 Expect.isNotNull(combinators); |
| 85 Expect.equals(1, combinators.length); | 95 Expect.equals(1, combinators.length); |
| 86 | 96 |
| 87 combinator = combinators[0]; | 97 combinator = combinators[0]; |
| 88 Expect.isNotNull(combinator); | 98 Expect.isNotNull(combinator); |
| 89 Expect.isFalse(combinator.isShow); | 99 Expect.isFalse(combinator.isShow); |
| 90 Expect.isTrue(combinator.isHide); | 100 Expect.isTrue(combinator.isHide); |
| 91 Expect.listEquals(['B1'], combinator.identifiers); | 101 Expect.listEquals(['B1'], combinator.identifiers); |
| 92 | 102 |
| 93 // export 'a.dart' show A2 hide A3, A1; | 103 // export 'a.dart' show A2 hide A3, A1; |
| 94 dependency = dependencies[2]; | 104 dependency = dependencies[2]; |
| 95 Expect.isNotNull(dependency); | 105 Expect.isNotNull(dependency); |
| 96 Expect.isFalse(dependency.isImport); | 106 Expect.isFalse(dependency.isImport); |
| 97 Expect.isTrue(dependency.isExport); | 107 Expect.isTrue(dependency.isExport); |
| 98 Expect.equals(mainLibrary, dependency.sourceLibrary); | 108 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 99 Expect.equals(aLibrary, dependency.targetLibrary); | 109 Expect.equals(aLibrary, dependency.targetLibrary); |
| 100 Expect.isNull(dependency.prefix); | 110 Expect.isNull(dependency.prefix); |
| 111 Expect.isFalse(dependency.isDeferred); |
| 101 | 112 |
| 102 combinators = dependency.combinators; | 113 combinators = dependency.combinators; |
| 103 Expect.isNotNull(combinators); | 114 Expect.isNotNull(combinators); |
| 104 Expect.equals(2, combinators.length); | 115 Expect.equals(2, combinators.length); |
| 105 | 116 |
| 106 combinator = combinators[0]; | 117 combinator = combinators[0]; |
| 107 Expect.isNotNull(combinator); | 118 Expect.isNotNull(combinator); |
| 108 Expect.isTrue(combinator.isShow); | 119 Expect.isTrue(combinator.isShow); |
| 109 Expect.isFalse(combinator.isHide); | 120 Expect.isFalse(combinator.isHide); |
| 110 Expect.listEquals(['A2'], combinator.identifiers); | 121 Expect.listEquals(['A2'], combinator.identifiers); |
| 111 | 122 |
| 112 combinator = combinators[1]; | 123 combinator = combinators[1]; |
| 113 Expect.isNotNull(combinator); | 124 Expect.isNotNull(combinator); |
| 114 Expect.isFalse(combinator.isShow); | 125 Expect.isFalse(combinator.isShow); |
| 115 Expect.isTrue(combinator.isHide); | 126 Expect.isTrue(combinator.isHide); |
| 116 Expect.listEquals(['A3', 'A1'], combinator.identifiers); | 127 Expect.listEquals(['A3', 'A1'], combinator.identifiers); |
| 117 | 128 |
| 118 // export 'b.dart' hide B1, B2 show B3; | 129 // export 'b.dart' hide B1, B2 show B3; |
| 119 dependency = dependencies[3]; | 130 dependency = dependencies[3]; |
| 120 Expect.isNotNull(dependency); | 131 Expect.isNotNull(dependency); |
| 121 Expect.isFalse(dependency.isImport); | 132 Expect.isFalse(dependency.isImport); |
| 122 Expect.isTrue(dependency.isExport); | 133 Expect.isTrue(dependency.isExport); |
| 123 Expect.equals(mainLibrary, dependency.sourceLibrary); | 134 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 124 Expect.equals(bLibrary, dependency.targetLibrary); | 135 Expect.equals(bLibrary, dependency.targetLibrary); |
| 125 Expect.isNull(dependency.prefix); | 136 Expect.isNull(dependency.prefix); |
| 137 Expect.isFalse(dependency.isDeferred); |
| 126 | 138 |
| 127 combinators = dependency.combinators; | 139 combinators = dependency.combinators; |
| 128 Expect.isNotNull(combinators); | 140 Expect.isNotNull(combinators); |
| 129 Expect.equals(2, combinators.length); | 141 Expect.equals(2, combinators.length); |
| 130 | 142 |
| 131 combinator = combinators[0]; | 143 combinator = combinators[0]; |
| 132 Expect.isNotNull(combinator); | 144 Expect.isNotNull(combinator); |
| 133 Expect.isFalse(combinator.isShow); | 145 Expect.isFalse(combinator.isShow); |
| 134 Expect.isTrue(combinator.isHide); | 146 Expect.isTrue(combinator.isHide); |
| 135 Expect.listEquals(['B1', 'B2'], combinator.identifiers); | 147 Expect.listEquals(['B1', 'B2'], combinator.identifiers); |
| 136 | 148 |
| 137 combinator = combinators[1]; | 149 combinator = combinators[1]; |
| 138 Expect.isNotNull(combinator); | 150 Expect.isNotNull(combinator); |
| 139 Expect.isTrue(combinator.isShow); | 151 Expect.isTrue(combinator.isShow); |
| 140 Expect.isFalse(combinator.isHide); | 152 Expect.isFalse(combinator.isHide); |
| 141 Expect.listEquals(['B3'], combinator.identifiers); | 153 Expect.listEquals(['B3'], combinator.identifiers); |
| 142 | 154 |
| 143 // import 'dart:core' as core; | 155 // import 'dart:core' as core; |
| 144 dependency = dependencies[4]; | 156 dependency = dependencies[4]; |
| 145 Expect.isNotNull(dependency); | 157 Expect.isNotNull(dependency); |
| 146 Expect.isTrue(dependency.isImport); | 158 Expect.isTrue(dependency.isImport); |
| 147 Expect.isFalse(dependency.isExport); | 159 Expect.isFalse(dependency.isExport); |
| 148 Expect.equals(mainLibrary, dependency.sourceLibrary); | 160 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 149 Expect.equals(coreLibrary, dependency.targetLibrary); | 161 Expect.equals(coreLibrary, dependency.targetLibrary); |
| 150 Expect.equals('core', dependency.prefix); | 162 Expect.equals('core', dependency.prefix); |
| 163 Expect.isFalse(dependency.isDeferred); |
| 151 | 164 |
| 152 combinators = dependency.combinators; | 165 combinators = dependency.combinators; |
| 153 Expect.isNotNull(combinators); | 166 Expect.isNotNull(combinators); |
| 167 Expect.equals(0, combinators.length); |
| 168 |
| 169 // import 'c.dart' deferred as c; |
| 170 dependency = dependencies[5]; |
| 171 Expect.isNotNull(dependency); |
| 172 Expect.isTrue(dependency.isImport); |
| 173 Expect.isFalse(dependency.isExport); |
| 174 Expect.equals(mainLibrary, dependency.sourceLibrary); |
| 175 Expect.equals(cLibrary, dependency.targetLibrary); |
| 176 Expect.equals('c', dependency.prefix); |
| 177 Expect.isTrue(dependency.isDeferred); |
| 178 |
| 179 combinators = dependency.combinators; |
| 180 Expect.isNotNull(combinators); |
| 154 Expect.equals(0, combinators.length); | 181 Expect.equals(0, combinators.length); |
| 155 })); | 182 })); |
| 156 } | 183 } |
| OLD | NEW |