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

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest_test.dart

Issue 2640793005: Implement UriResolver.restoreAbsolute() for DartUriResolver. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/source.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
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 library analyzer.test.generated.all_the_rest_test; 5 library analyzer.test.generated.all_the_rest_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 20 matching lines...) Expand all
31 import 'package:analyzer/src/generated/testing/ast_test_factory.dart'; 31 import 'package:analyzer/src/generated/testing/ast_test_factory.dart';
32 import 'package:analyzer/src/generated/testing/element_factory.dart'; 32 import 'package:analyzer/src/generated/testing/element_factory.dart';
33 import 'package:analyzer/src/generated/testing/test_type_provider.dart'; 33 import 'package:analyzer/src/generated/testing/test_type_provider.dart';
34 import 'package:analyzer/src/generated/testing/token_factory.dart'; 34 import 'package:analyzer/src/generated/testing/token_factory.dart';
35 import 'package:analyzer/src/generated/utilities_dart.dart'; 35 import 'package:analyzer/src/generated/utilities_dart.dart';
36 import 'package:analyzer/src/source/source_resource.dart'; 36 import 'package:analyzer/src/source/source_resource.dart';
37 import 'package:path/path.dart' as path; 37 import 'package:path/path.dart' as path;
38 import 'package:source_span/source_span.dart'; 38 import 'package:source_span/source_span.dart';
39 import 'package:test/test.dart'; 39 import 'package:test/test.dart';
40 import 'package:test_reflective_loader/test_reflective_loader.dart'; 40 import 'package:test_reflective_loader/test_reflective_loader.dart';
41 import 'package:typed_mock/typed_mock.dart' show TypedMock, when;
41 42
42 import 'parser_test.dart'; 43 import 'parser_test.dart';
43 import 'resolver_test_case.dart'; 44 import 'resolver_test_case.dart';
44 import 'test_support.dart'; 45 import 'test_support.dart';
45 46
46 main() { 47 main() {
47 defineReflectiveSuite(() { 48 defineReflectiveSuite(() {
48 defineReflectiveTests(ContentCacheTest); 49 defineReflectiveTests(ContentCacheTest);
49 // ignore: deprecated_member_use 50 // ignore: deprecated_member_use
50 defineReflectiveTests(CustomUriResolverTest); 51 defineReflectiveTests(CustomUriResolverTest);
51 defineReflectiveTests(DartUriResolverTest); 52 defineReflectiveTests(DartUriResolverTest);
52 // ignore: deprecated_member_use 53 // ignore: deprecated_member_use
53 defineReflectiveTests(DirectoryBasedDartSdkTest); 54 defineReflectiveTests(DirectoryBasedDartSdkTest);
54 // ignore: deprecated_member_use 55 // ignore: deprecated_member_use
55 defineReflectiveTests(DirectoryBasedSourceContainerTest); 56 defineReflectiveTests(DirectoryBasedSourceContainerTest);
56 defineReflectiveTests(ElementLocatorTest); 57 defineReflectiveTests(ElementLocatorTest);
57 defineReflectiveTests(EnumMemberBuilderTest); 58 defineReflectiveTests(EnumMemberBuilderTest);
58 defineReflectiveTests(ErrorReporterTest); 59 defineReflectiveTests(ErrorReporterTest);
59 defineReflectiveTests(ErrorSeverityTest); 60 defineReflectiveTests(ErrorSeverityTest);
60 defineReflectiveTests(ExitDetectorTest); 61 defineReflectiveTests(ExitDetectorTest);
61 defineReflectiveTests(ExitDetectorTest2); 62 defineReflectiveTests(ExitDetectorTest2);
62 defineReflectiveTests(FileBasedSourceTest); 63 defineReflectiveTests(FileBasedSourceTest);
63 defineReflectiveTests(ResolveRelativeUriTest); 64 defineReflectiveTests(ResolveRelativeUriTest);
64 // ignore: deprecated_member_use 65 // ignore: deprecated_member_use
65 defineReflectiveTests(SDKLibrariesReaderTest); 66 defineReflectiveTests(SDKLibrariesReaderTest);
66 defineReflectiveTests(UriKindTest); 67 defineReflectiveTests(UriKindTest);
67 }); 68 });
68 } 69 }
69 70
70 /**
71 * Create a tiny mock SDK for use in URI resolution tests.
72 */
73 DartSdk _createSdk() {
74 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
75 String sdkFolderName =
76 resourceProvider.pathContext.separator == '/' ? '/sdk' : r'C:\sdk';
77 Folder sdkFolder = resourceProvider.newFolder(sdkFolderName);
78 expect(sdkFolder, isNotNull);
79 resourceProvider.newFile(
80 resourceProvider.pathContext.join(sdkFolderName, 'lib', '_internal',
81 'sdk_library_metadata', 'lib', 'libraries.dart'),
82 '''
83 const Map<String, LibraryInfo> libraries = const {
84 "core": const LibraryInfo("core/core.dart")
85 };
86 ''');
87 resourceProvider.newFile(
88 resourceProvider.pathContext
89 .join(sdkFolderName, 'lib', 'core', 'core.dart'),
90 '''
91 library dart.core;
92 ''');
93 return new FolderBasedDartSdk(resourceProvider, sdkFolder);
94 }
95
96 @reflectiveTest 71 @reflectiveTest
97 class ContentCacheTest { 72 class ContentCacheTest {
98 test_setContents() async { 73 test_setContents() async {
99 Source source = new TestSource(); 74 Source source = new TestSource();
100 ContentCache cache = new ContentCache(); 75 ContentCache cache = new ContentCache();
101 expect(cache.getContents(source), isNull); 76 expect(cache.getContents(source), isNull);
102 expect(cache.getModificationStamp(source), isNull); 77 expect(cache.getModificationStamp(source), isNull);
103 String contents = "library lib;"; 78 String contents = "library lib;";
104 expect(cache.setContents(source, contents), isNull); 79 expect(cache.setContents(source, contents), isNull);
105 expect(cache.getContents(source), contents); 80 expect(cache.getContents(source), contents);
(...skipping 27 matching lines...) Expand all
133 UriResolver resolver = new CustomUriResolver({ 108 UriResolver resolver = new CustomUriResolver({
134 'custom:library': filePath, 109 'custom:library': filePath,
135 }); 110 });
136 Source result = resolver.resolveAbsolute(Uri.parse("custom:library")); 111 Source result = resolver.resolveAbsolute(Uri.parse("custom:library"));
137 expect(result, isNotNull); 112 expect(result, isNotNull);
138 expect(result.fullName, filePath); 113 expect(result.fullName, filePath);
139 } 114 }
140 } 115 }
141 116
142 @reflectiveTest 117 @reflectiveTest
143 class DartUriResolverTest { 118 class DartUriResolverTest extends _SimpleDartSdkTest {
119 DartUriResolver resolver;
120
121 @override
122 setUp() {
123 super.setUp();
124 resolver = new DartUriResolver(sdk);
125 }
126
144 void test_creation() { 127 void test_creation() {
145 DartSdk sdk = _createSdk();
146 expect(new DartUriResolver(sdk), isNotNull); 128 expect(new DartUriResolver(sdk), isNotNull);
147 } 129 }
148 130
149 void test_isDartUri_null_scheme() { 131 void test_isDartUri_null_scheme() {
150 Uri uri = Uri.parse("foo.dart"); 132 Uri uri = Uri.parse("foo.dart");
151 expect('', uri.scheme); 133 expect('', uri.scheme);
152 expect(DartUriResolver.isDartUri(uri), isFalse); 134 expect(DartUriResolver.isDartUri(uri), isFalse);
153 } 135 }
154 136
155 void test_resolve_dart() { 137 void test_resolve_dart_library() {
156 DartSdk sdk = _createSdk(); 138 Source source = resolver.resolveAbsolute(Uri.parse('dart:core'));
157 UriResolver resolver = new DartUriResolver(sdk); 139 expect(source, isNotNull);
158 Source result = resolver.resolveAbsolute(Uri.parse("dart:core"));
159 expect(result, isNotNull);
160 } 140 }
161 141
162 void test_resolve_dart_nonExistingLibrary() { 142 void test_resolve_dart_nonExistingLibrary() {
163 DartSdk sdk = _createSdk();
164 UriResolver resolver = new DartUriResolver(sdk);
165 Source result = resolver.resolveAbsolute(Uri.parse("dart:cor")); 143 Source result = resolver.resolveAbsolute(Uri.parse("dart:cor"));
166 expect(result, isNull); 144 expect(result, isNull);
167 } 145 }
168 146
147 void test_resolve_dart_part() {
148 Source source = resolver.resolveAbsolute(Uri.parse('dart:core/int.dart'));
149 expect(source, isNotNull);
150 }
151
169 void test_resolve_nonDart() { 152 void test_resolve_nonDart() {
170 DartSdk sdk = _createSdk();
171 UriResolver resolver = new DartUriResolver(sdk);
172 Source result = 153 Source result =
173 resolver.resolveAbsolute(Uri.parse("package:some/file.dart")); 154 resolver.resolveAbsolute(Uri.parse("package:some/file.dart"));
174 expect(result, isNull); 155 expect(result, isNull);
175 } 156 }
157
158 void test_restoreAbsolute_library() {
159 Source source = new _SourceMock();
160 Uri fileUri = resourceProvider.pathContext.toUri(coreCorePath);
161 when(source.uri).thenReturn(fileUri);
162 Uri dartUri = resolver.restoreAbsolute(source);
163 expect(dartUri.toString(), 'dart:core');
164 }
165
166 void test_restoreAbsolute_part() {
167 Source source = new _SourceMock();
168 Uri fileUri = resourceProvider.pathContext.toUri(coreIntPath);
169 when(source.uri).thenReturn(fileUri);
170 Uri dartUri = resolver.restoreAbsolute(source);
171 expect(dartUri.toString(), 'dart:core/int.dart');
172 }
176 } 173 }
177 174
178 @deprecated 175 @deprecated
179 @reflectiveTest 176 @reflectiveTest
180 class DirectoryBasedDartSdkTest { 177 class DirectoryBasedDartSdkTest {
181 void fail_getDocFileFor() { 178 void fail_getDocFileFor() {
182 DirectoryBasedDartSdk sdk = _createDartSdk(); 179 DirectoryBasedDartSdk sdk = _createDartSdk();
183 JavaFile docFile = sdk.getDocFileFor("html"); 180 JavaFile docFile = sdk.getDocFileFor("html");
184 expect(docFile, isNotNull); 181 expect(docFile, isNotNull);
185 } 182 }
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 2043
2047 test_hashCode() async { 2044 test_hashCode() async {
2048 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart"); 2045 JavaFile file1 = FileUtilities2.createFile("/does/not/exist.dart");
2049 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart"); 2046 JavaFile file2 = FileUtilities2.createFile("/does/not/exist.dart");
2050 FileBasedSource source1 = new FileBasedSource(file1); 2047 FileBasedSource source1 = new FileBasedSource(file1);
2051 FileBasedSource source2 = new FileBasedSource(file2); 2048 FileBasedSource source2 = new FileBasedSource(file2);
2052 expect(source2.hashCode, source1.hashCode); 2049 expect(source2.hashCode, source1.hashCode);
2053 } 2050 }
2054 2051
2055 test_isInSystemLibrary_contagious() async { 2052 test_isInSystemLibrary_contagious() async {
2056 DartSdk sdk = _createSdk(); 2053 DartSdk sdk = (new _SimpleDartSdkTest()..setUp()).sdk;
2057 UriResolver resolver = new DartUriResolver(sdk); 2054 UriResolver resolver = new DartUriResolver(sdk);
2058 SourceFactory factory = new SourceFactory([resolver]); 2055 SourceFactory factory = new SourceFactory([resolver]);
2059 // resolve dart:core 2056 // resolve dart:core
2060 Source result = resolver.resolveAbsolute(Uri.parse("dart:core")); 2057 Source result = resolver.resolveAbsolute(Uri.parse("dart:core"));
2061 expect(result, isNotNull); 2058 expect(result, isNotNull);
2062 expect(result.isInSystemLibrary, isTrue); 2059 expect(result.isInSystemLibrary, isTrue);
2063 // system libraries reference only other system libraries 2060 // system libraries reference only other system libraries
2064 Source partSource = factory.resolveUri(result, "num.dart"); 2061 Source partSource = factory.resolveUri(result, "num.dart");
2065 expect(partSource, isNotNull); 2062 expect(partSource, isNotNull);
2066 expect(partSource.isInSystemLibrary, isTrue); 2063 expect(partSource.isInSystemLibrary, isTrue);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI)); 2269 expect(UriKind.fromEncoding(0x70), same(UriKind.PACKAGE_URI));
2273 expect(UriKind.fromEncoding(0x58), same(null)); 2270 expect(UriKind.fromEncoding(0x58), same(null));
2274 } 2271 }
2275 2272
2276 test_getEncoding() async { 2273 test_getEncoding() async {
2277 expect(UriKind.DART_URI.encoding, 0x64); 2274 expect(UriKind.DART_URI.encoding, 0x64);
2278 expect(UriKind.FILE_URI.encoding, 0x66); 2275 expect(UriKind.FILE_URI.encoding, 0x66);
2279 expect(UriKind.PACKAGE_URI.encoding, 0x70); 2276 expect(UriKind.PACKAGE_URI.encoding, 0x70);
2280 } 2277 }
2281 } 2278 }
2279
2280 class _SimpleDartSdkTest {
2281 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
2282 String coreCorePath;
2283 String coreIntPath;
2284 DartSdk sdk;
2285
2286 void setUp() {
2287 Folder sdkFolder =
2288 resourceProvider.newFolder(resourceProvider.convertPath('/sdk'));
2289 resourceProvider.newFile(
2290 resourceProvider.convertPath(
2291 '/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'),
2292 '''
2293 const Map<String, LibraryInfo> libraries = const {
2294 "core": const LibraryInfo("core/core.dart")
2295 };
2296 ''');
2297 coreCorePath = resourceProvider.convertPath('/sdk/lib/core/core.dart');
2298 resourceProvider.newFile(
2299 coreCorePath,
2300 '''
2301 library dart.core;
2302 part 'int.dart';
2303 ''');
2304 coreIntPath = resourceProvider.convertPath('/sdk/lib/core/int.dart');
2305 resourceProvider.newFile(
2306 coreIntPath,
2307 '''
2308 part of dart.core;
2309 ''');
2310 sdk = new FolderBasedDartSdk(resourceProvider, sdkFolder);
2311 }
2312 }
2313
2314 class _SourceMock extends TypedMock implements Source {}
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/source.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698