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

Side by Side Diff: pkg/analyzer/test/source/embedder_test.dart

Issue 2344933002: Fix recently introduced strong-mode errors (Closed)
Patch Set: Created 4 years, 3 months 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 @deprecated 5 @deprecated
6 library analyzer.test.source.embedder_test; 6 library analyzer.test.source.embedder_test;
7 7
8 import 'dart:core'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/source/embedder.dart'; 11 import 'package:analyzer/source/embedder.dart';
11 import 'package:analyzer/src/generated/sdk.dart'; 12 import 'package:analyzer/src/generated/sdk.dart';
12 import 'package:analyzer/src/generated/source.dart'; 13 import 'package:analyzer/src/generated/source.dart';
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; 14 import 'package:test_reflective_loader/test_reflective_loader.dart';
14 import 'package:unittest/unittest.dart'; 15 import 'package:unittest/unittest.dart';
15 16
16 import '../embedder_tests.dart'; 17 import '../embedder_tests.dart';
17 import '../resource_utils.dart'; 18 import '../resource_utils.dart';
18 19
19 main() { 20 main() {
20 defineReflectiveTests(DartUriResolverTest); 21 defineReflectiveTests(DartUriResolverTest);
21 defineReflectiveTests(EmbedderSdkTest); 22 defineReflectiveTests(EmbedderSdkTest);
22 defineReflectiveTests(EmbedderUriResolverTest); 23 defineReflectiveTests(EmbedderUriResolverTest);
23 } 24 }
24 25
25 @reflectiveTest 26 @reflectiveTest
26 class DartUriResolverTest extends EmbedderRelatedTest { 27 class DartUriResolverTest extends EmbedderRelatedTest {
27 void test_embedderYaml() { 28 void test_embedderYaml() {
28 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 29 EmbedderYamlLocator locator = new EmbedderYamlLocator({
29 'fox': [pathTranslator.getResource(foxLib)] 30 'fox': <Folder>[pathTranslator.getResource(foxLib)]
30 }); 31 });
31 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls); 32 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls);
32 DartUriResolver resolver = new DartUriResolver(sdk); 33 DartUriResolver resolver = new DartUriResolver(sdk);
33 34
34 void expectResolved(dartUri, posixPath) { 35 void expectResolved(dartUri, posixPath) {
35 Source source = resolver.resolveAbsolute(Uri.parse(dartUri)); 36 Source source = resolver.resolveAbsolute(Uri.parse(dartUri));
36 expect(source, isNotNull, reason: dartUri); 37 expect(source, isNotNull, reason: dartUri);
37 expect(source.fullName, posixToOSPath(posixPath)); 38 expect(source.fullName, posixToOSPath(posixPath));
38 } 39 }
39 40
40 // Check that they map to the correct paths. 41 // Check that they map to the correct paths.
41 expectResolved('dart:core', '$foxLib/core.dart'); 42 expectResolved('dart:core', '$foxLib/core.dart');
42 expectResolved('dart:fox', '$foxLib/slippy.dart'); 43 expectResolved('dart:fox', '$foxLib/slippy.dart');
43 expectResolved('dart:bear', '$foxLib/grizzly.dart'); 44 expectResolved('dart:bear', '$foxLib/grizzly.dart');
44 expectResolved('dart:relative', '$foxPath/relative.dart'); 45 expectResolved('dart:relative', '$foxPath/relative.dart');
45 expectResolved('dart:deep', '$foxLib/deep/directory/file.dart'); 46 expectResolved('dart:deep', '$foxLib/deep/directory/file.dart');
46 } 47 }
47 } 48 }
48 49
49 @reflectiveTest 50 @reflectiveTest
50 class EmbedderSdkTest extends EmbedderRelatedTest { 51 class EmbedderSdkTest extends EmbedderRelatedTest {
51 void test_creation() { 52 void test_creation() {
52 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 53 EmbedderYamlLocator locator = new EmbedderYamlLocator({
53 'fox': [pathTranslator.getResource(foxLib)] 54 'fox': <Folder>[pathTranslator.getResource(foxLib)]
54 }); 55 });
55 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls); 56 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls);
56 57
57 expect(sdk.urlMappings, hasLength(5)); 58 expect(sdk.urlMappings, hasLength(5));
58 } 59 }
59 60
60 void test_fromFileUri() { 61 void test_fromFileUri() {
61 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 62 EmbedderYamlLocator locator = new EmbedderYamlLocator({
62 'fox': [pathTranslator.getResource(foxLib)] 63 'fox': <Folder>[pathTranslator.getResource(foxLib)]
63 }); 64 });
64 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls); 65 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls);
65 66
66 expectSource(String posixPath, String dartUri) { 67 expectSource(String posixPath, String dartUri) {
67 Uri uri = Uri.parse(posixToOSFileUri(posixPath)); 68 Uri uri = Uri.parse(posixToOSFileUri(posixPath));
68 Source source = sdk.fromFileUri(uri); 69 Source source = sdk.fromFileUri(uri);
69 expect(source, isNotNull, reason: posixPath); 70 expect(source, isNotNull, reason: posixPath);
70 expect(source.uri.toString(), dartUri); 71 expect(source.uri.toString(), dartUri);
71 expect(source.fullName, posixToOSPath(posixPath)); 72 expect(source.fullName, posixToOSPath(posixPath));
72 } 73 }
73 74
74 expectSource('$foxLib/slippy.dart', 'dart:fox'); 75 expectSource('$foxLib/slippy.dart', 'dart:fox');
75 expectSource('$foxLib/deep/directory/file.dart', 'dart:deep'); 76 expectSource('$foxLib/deep/directory/file.dart', 'dart:deep');
76 expectSource('$foxLib/deep/directory/part.dart', 'dart:deep/part.dart'); 77 expectSource('$foxLib/deep/directory/part.dart', 'dart:deep/part.dart');
77 } 78 }
78 79
79 void test_getSdkLibrary() { 80 void test_getSdkLibrary() {
80 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 81 EmbedderYamlLocator locator = new EmbedderYamlLocator({
81 'fox': [pathTranslator.getResource(foxLib)] 82 'fox': <Folder>[pathTranslator.getResource(foxLib)]
82 }); 83 });
83 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls); 84 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls);
84 85
85 SdkLibrary lib = sdk.getSdkLibrary('dart:fox'); 86 SdkLibrary lib = sdk.getSdkLibrary('dart:fox');
86 expect(lib, isNotNull); 87 expect(lib, isNotNull);
87 expect(lib.path, posixToOSPath('$foxLib/slippy.dart')); 88 expect(lib.path, posixToOSPath('$foxLib/slippy.dart'));
88 expect(lib.shortName, 'dart:fox'); 89 expect(lib.shortName, 'dart:fox');
89 } 90 }
90 91
91 void test_mapDartUri() { 92 void test_mapDartUri() {
92 EmbedderYamlLocator locator = new EmbedderYamlLocator({ 93 EmbedderYamlLocator locator = new EmbedderYamlLocator({
93 'fox': [pathTranslator.getResource(foxLib)] 94 'fox': <Folder>[pathTranslator.getResource(foxLib)]
94 }); 95 });
95 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls); 96 EmbedderSdk sdk = new EmbedderSdk(locator.embedderYamls);
96 97
97 void expectSource(String dartUri, String posixPath) { 98 void expectSource(String dartUri, String posixPath) {
98 Source source = sdk.mapDartUri(dartUri); 99 Source source = sdk.mapDartUri(dartUri);
99 expect(source, isNotNull, reason: posixPath); 100 expect(source, isNotNull, reason: posixPath);
100 expect(source.uri.toString(), dartUri); 101 expect(source.uri.toString(), dartUri);
101 expect(source.fullName, posixToOSPath(posixPath)); 102 expect(source.fullName, posixToOSPath(posixPath));
102 } 103 }
103 104
104 expectSource('dart:core', '$foxLib/core.dart'); 105 expectSource('dart:core', '$foxLib/core.dart');
105 expectSource('dart:fox', '$foxLib/slippy.dart'); 106 expectSource('dart:fox', '$foxLib/slippy.dart');
106 expectSource('dart:deep', '$foxLib/deep/directory/file.dart'); 107 expectSource('dart:deep', '$foxLib/deep/directory/file.dart');
107 expectSource('dart:deep/part.dart', '$foxLib/deep/directory/part.dart'); 108 expectSource('dart:deep/part.dart', '$foxLib/deep/directory/part.dart');
108 } 109 }
109 } 110 }
110 111
111 @reflectiveTest 112 @reflectiveTest
112 class EmbedderUriResolverTest extends EmbedderRelatedTest { 113 class EmbedderUriResolverTest extends EmbedderRelatedTest {
113 void test_embedderYaml() { 114 void test_embedderYaml() {
114 var locator = new EmbedderYamlLocator({ 115 var locator = new EmbedderYamlLocator({
115 'fox': [pathTranslator.getResource(foxLib)] 116 'fox': <Folder>[pathTranslator.getResource(foxLib)]
116 }); 117 });
117 var resolver = new EmbedderUriResolver(locator.embedderYamls); 118 var resolver = new EmbedderUriResolver(locator.embedderYamls);
118 119
119 expectResolved(dartUri, posixPath) { 120 expectResolved(dartUri, posixPath) {
120 Source source = resolver.resolveAbsolute(Uri.parse(dartUri)); 121 Source source = resolver.resolveAbsolute(Uri.parse(dartUri));
121 expect(source, isNotNull, reason: dartUri); 122 expect(source, isNotNull, reason: dartUri);
122 expect(source.fullName, posixToOSPath(posixPath)); 123 expect(source.fullName, posixToOSPath(posixPath));
123 } 124 }
124 125
125 // We have five mappings. 126 // We have five mappings.
126 expect(resolver, hasLength(5)); 127 expect(resolver, hasLength(5));
127 // Check that they map to the correct paths. 128 // Check that they map to the correct paths.
128 expectResolved('dart:core', '$foxLib/core.dart'); 129 expectResolved('dart:core', '$foxLib/core.dart');
129 expectResolved('dart:fox', '$foxLib/slippy.dart'); 130 expectResolved('dart:fox', '$foxLib/slippy.dart');
130 expectResolved('dart:bear', '$foxLib/grizzly.dart'); 131 expectResolved('dart:bear', '$foxLib/grizzly.dart');
131 expectResolved('dart:relative', '$foxPath/relative.dart'); 132 expectResolved('dart:relative', '$foxPath/relative.dart');
132 expectResolved('dart:deep', '$foxLib/deep/directory/file.dart'); 133 expectResolved('dart:deep', '$foxLib/deep/directory/file.dart');
133 } 134 }
134 135
135 void test_nullEmbedderYamls() { 136 void test_nullEmbedderYamls() {
136 var resolver = new EmbedderUriResolver(null); 137 var resolver = new EmbedderUriResolver(null);
137 expect(resolver, hasLength(0)); 138 expect(resolver, hasLength(0));
138 } 139 }
139 140
140 void test_restoreAbsolute() { 141 void test_restoreAbsolute() {
141 var locator = new EmbedderYamlLocator({ 142 var locator = new EmbedderYamlLocator({
142 'fox': [pathTranslator.getResource(foxLib)] 143 'fox': <Folder>[pathTranslator.getResource(foxLib)]
143 }); 144 });
144 var resolver = new EmbedderUriResolver(locator.embedderYamls); 145 var resolver = new EmbedderUriResolver(locator.embedderYamls);
145 146
146 expectRestore(String dartUri, [String expected]) { 147 expectRestore(String dartUri, [String expected]) {
147 var parsedUri = Uri.parse(dartUri); 148 var parsedUri = Uri.parse(dartUri);
148 var source = resolver.resolveAbsolute(parsedUri); 149 var source = resolver.resolveAbsolute(parsedUri);
149 expect(source, isNotNull); 150 expect(source, isNotNull);
150 // Restore source's uri. 151 // Restore source's uri.
151 var restoreUri = resolver.restoreAbsolute(source); 152 var restoreUri = resolver.restoreAbsolute(source);
152 expect(restoreUri, isNotNull, reason: dartUri); 153 expect(restoreUri, isNotNull, reason: dartUri);
153 // Verify that it is 'dart:fox'. 154 // Verify that it is 'dart:fox'.
154 expect(restoreUri.toString(), expected ?? dartUri); 155 expect(restoreUri.toString(), expected ?? dartUri);
155 List<String> split = (expected ?? dartUri).split(':'); 156 List<String> split = (expected ?? dartUri).split(':');
156 expect(restoreUri.scheme, split[0]); 157 expect(restoreUri.scheme, split[0]);
157 expect(restoreUri.path, split[1]); 158 expect(restoreUri.path, split[1]);
158 } 159 }
159 160
160 expectRestore('dart:deep'); 161 expectRestore('dart:deep');
161 expectRestore('dart:deep/file.dart', 'dart:deep'); 162 expectRestore('dart:deep/file.dart', 'dart:deep');
162 expectRestore('dart:deep/part.dart'); 163 expectRestore('dart:deep/part.dart');
163 expectRestore('dart:deep/deep/file.dart'); 164 expectRestore('dart:deep/deep/file.dart');
164 } 165 }
165 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698