OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test that the additional runtime type support is output to the right | 5 // Test that the additional runtime type support is output to the right |
6 // Files when using deferred loading. | 6 // Files when using deferred loading. |
7 | 7 |
| 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:compiler/src/dart2jslib.dart'; |
| 10 import 'package:compiler/src/js_backend/js_backend.dart' |
| 11 show JavaScriptBackend; |
8 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
9 import 'package:async_helper/async_helper.dart'; | 13 import 'memory_compiler.dart'; |
10 import 'memory_source_file_helper.dart'; | |
11 import 'output_collector.dart'; | 14 import 'output_collector.dart'; |
12 | 15 |
13 void main() { | 16 void main() { |
14 Uri script = currentDirectory.resolveUri(Platform.script); | |
15 Uri libraryRoot = script.resolve('../../../sdk/'); | |
16 Uri packageRoot = script.resolve('./packages/'); | |
17 | |
18 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); | |
19 var handler = new FormattingDiagnosticHandler(provider); | |
20 | |
21 OutputCollector collector = new OutputCollector(); | 17 OutputCollector collector = new OutputCollector(); |
22 | 18 Compiler compiler = compilerFor( |
23 Compiler compiler = new Compiler(provider.readStringFromUri, | 19 MEMORY_SOURCE_FILES, |
24 collector, | 20 outputProvider: collector); |
25 handler.diagnosticHandler, | |
26 libraryRoot, | |
27 packageRoot, | |
28 [], | |
29 {}); | |
30 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { | 21 asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) { |
31 String mainOutput = collector.getOutput('', 'js'); | 22 String mainOutput = collector.getOutput('', 'js'); |
32 String deferredOutput = collector.getOutput('out_1', 'part.js'); | 23 String deferredOutput = collector.getOutput('out_1', 'part.js'); |
33 String isPrefix = compiler.backend.namer.operatorIsPrefix; | 24 JavaScriptBackend backend = compiler.backend; |
| 25 String isPrefix = backend.namer.operatorIsPrefix; |
34 Expect.isTrue(deferredOutput.contains('${isPrefix}A: 1'), | 26 Expect.isTrue(deferredOutput.contains('${isPrefix}A: 1'), |
35 "Deferred output doesn't contain '${isPrefix}A: 1':\n" | 27 "Deferred output doesn't contain '${isPrefix}A: 1':\n" |
36 "$deferredOutput"); | 28 "$deferredOutput"); |
37 Expect.isFalse(mainOutput.contains('${isPrefix}A: 1')); | 29 Expect.isFalse(mainOutput.contains('${isPrefix}A: 1')); |
38 })); | 30 })); |
39 } | 31 } |
40 | 32 |
41 // We force additional runtime type support to be output for A by instantiating | 33 // We force additional runtime type support to be output for A by instantiating |
42 // it with a type argument, and testing for the type. The extra support should | 34 // it with a type argument, and testing for the type. The extra support should |
43 // go to the deferred hunk. | 35 // go to the deferred hunk. |
44 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ | 36 const Map MEMORY_SOURCE_FILES = const {"main.dart": """ |
45 import 'lib.dart' deferred as lib show f, A, instance; | 37 import 'lib.dart' deferred as lib show f, A, instance; |
46 | 38 |
47 void main() { | 39 void main() { |
48 lib.loadLibrary().then((_) { | 40 lib.loadLibrary().then((_) { |
49 print(lib.f(lib.instance)); | 41 print(lib.f(lib.instance)); |
50 }); | 42 }); |
51 } | 43 } |
52 """, "lib.dart": """ | 44 """, "lib.dart": """ |
53 class A<T> {} | 45 class A<T> {} |
54 | 46 |
55 class B<T> implements A<T> {} | 47 class B<T> implements A<T> {} |
56 | 48 |
57 B<B> instance = new B<B>(); | 49 B<B> instance = new B<B>(); |
58 | 50 |
59 bool f (Object o) { | 51 bool f (Object o) { |
60 return o is A<A>; | 52 return o is A<A>; |
61 } | 53 } |
62 """,}; | 54 """,}; |
OLD | NEW |