Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: dart/tests/compiler/dart2js/library_resolution_test.dart

Issue 803543002: Resolve libraries against their canonical URI. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42358. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/sdk/lib/html/html_common/html_common_dart2js.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /// Check that relative URIs are resolved against the canonical name of a
6 /// library. This only matters for dart:-libraries, so this test mocks up two
7 /// dart:-libraries.
8
9 import "dart:io";
10
11 import "dart:async";
12
13 import "memory_source_file_helper.dart";
14
15 import "package:async_helper/async_helper.dart";
16
17 import 'package:expect/expect.dart' show
18 Expect;
19
20 import 'package:compiler/src/elements/elements.dart' show
21 LibraryElement;
22
23 import 'package:compiler/src/dart2jslib.dart' show
24 MessageKind;
25
26 import 'package:_internal/libraries.dart' show
27 DART2JS_PLATFORM,
28 LibraryInfo;
29
30 const LibraryInfo mock1LibraryInfo = const LibraryInfo(
31 "mock1.dart",
32 category: "Shared",
33 documented: false,
34 platforms: DART2JS_PLATFORM);
35
36 const LibraryInfo mock2LibraryInfo = const LibraryInfo(
37 "mock2.dart",
38 category: "Shared",
39 documented: false,
40 platforms: DART2JS_PLATFORM);
41
42 class CustomCompiler extends Compiler {
43 final Map<String, LibraryInfo> customLibraryInfo;
44
45 CustomCompiler(
46 this.customLibraryInfo,
47 provider,
48 outputProvider,
49 handler,
50 libraryRoot,
51 packageRoot,
52 options,
53 environment)
54 : super(
55 provider,
56 outputProvider,
57 handler,
58 libraryRoot,
59 packageRoot,
60 options,
61 environment);
62
63 LibraryInfo lookupLibraryInfo(String name) {
64 if (name == "m_o_c_k_1") return mock1LibraryInfo;
65 if (name == "m_o_c_k_2") return mock2LibraryInfo;
66 return super.lookupLibraryInfo(name);
67 }
68 }
69
70 main() {
71 Uri sdkRoot = Uri.base.resolve("sdk/");
72 Uri packageRoot = Uri.base.resolve(Platform.packageRoot);
73
74 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
75 var handler = new FormattingDiagnosticHandler(provider);
76
77 outputProvider(String name, String extension) {
78 if (name != '') throw 'Attempt to output file "$name.$extension"';
79 return new NullSink('$name.$extension');
80 }
81
82 Future wrappedProvider(Uri uri) {
83 if (uri == sdkRoot.resolve('lib/mock1.dart')) {
84 return provider.readStringFromUri(Uri.parse('memory:mock1.dart'));
85 }
86 if (uri == sdkRoot.resolve('lib/mock2.dart')) {
87 return provider.readStringFromUri(Uri.parse('memory:mock2.dart'));
88 }
89 return provider.readStringFromUri(uri);
90 }
91
92 String expectedMessage =
93 MessageKind.LIBRARY_NOT_FOUND.message(
94 {'resolvedUri': 'dart:mock2.dart'}).computeMessage();
95
96 int actualMessageCount = 0;
97
98 wrappedHandler(
99 Uri uri, int begin, int end, String message, kind) {
100 if (message == expectedMessage) {
101 actualMessageCount++;
102 } else {
103 return handler(uri, begin, end, message, kind);
104 }
105 }
106
107 checkLibrary(LibraryElement library) {
108 Expect.equals(1, actualMessageCount);
109 }
110
111 Compiler compiler = new CustomCompiler(
112 {},
113 wrappedProvider,
114 outputProvider,
115 wrappedHandler,
116 sdkRoot,
117 packageRoot,
118 [],
119 {});
120
121 asyncStart();
122 compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1"))
123 .then(checkLibrary)
124 .then(asyncSuccess);
125 }
126
127 const Map MEMORY_SOURCE_FILES = const {
128 "mock1.dart": "library mock1; import 'mock2.dart';",
129 "mock2.dart": "library mock2;",
130 };
OLDNEW
« no previous file with comments | « dart/sdk/lib/html/html_common/html_common_dart2js.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698