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

Side by Side Diff: pkg/analysis_server/test/package_uri_resolver_test.dart

Issue 422973002: Move PackageMapUriResolver into analyzer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
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 library test.resolver.package;
6
7 import 'dart:collection';
8
9 import 'package:analysis_server/src/package_uri_resolver.dart';
10 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/file_system/memory_file_system.dart';
13 import 'package:analyzer/src/generated/source.dart';
14 import 'package:unittest/unittest.dart';
15
16
17 main() {
18 groupSep = ' | ';
19 runReflectiveTests(_PackageMapUriResolverTest);
20 }
21
22
23 @ReflectiveTestCase()
24 class _PackageMapUriResolverTest {
25 static HashMap EMPTY_MAP = new HashMap<String, List<Folder>>();
26 MemoryResourceProvider provider = new MemoryResourceProvider();
27
28 setUp() {
29 }
30
31 tearDown() {
32 }
33
34 void test_fromEncoding_nonPackage() {
35 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
36 Uri uri = Uri.parse('file:/does/not/exist.dart');
37 Source result = resolver.fromEncoding(UriKind.DART_URI, uri);
38 expect(result, isNull);
39 }
40
41 void test_fromEncoding_package() {
42 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
43 Uri uri = Uri.parse('package:/does/not/exist.dart');
44 Source result = resolver.fromEncoding(UriKind.PACKAGE_URI, uri);
45 expect(result, isNotNull);
46 expect(result.fullName, '/does/not/exist.dart');
47 }
48
49 void test_isPackageUri() {
50 Uri uri = Uri.parse('package:test/test.dart');
51 expect(uri.scheme, 'package');
52 expect(PackageMapUriResolver.isPackageUri(uri), isTrue);
53 }
54
55 void test_isPackageUri_null_scheme() {
56 Uri uri = Uri.parse('foo.dart');
57 expect(uri.scheme, '');
58 expect(PackageMapUriResolver.isPackageUri(uri), isFalse);
59 }
60
61 void test_isPackageUri_other_scheme() {
62 Uri uri = Uri.parse('memfs:/foo.dart');
63 expect(uri.scheme, 'memfs');
64 expect(PackageMapUriResolver.isPackageUri(uri), isFalse);
65 }
66
67 void test_resolve_OK() {
68 const pkgFileA = '/pkgA/lib/libA.dart';
69 const pkgFileB = '/pkgB/lib/libB.dart';
70 provider.newFile(pkgFileA, 'library lib_a;');
71 provider.newFile(pkgFileB, 'library lib_b;');
72 PackageMapUriResolver resolver = new PackageMapUriResolver(provider,
73 <String, List<Folder>>{
74 'pkgA': [provider.getResource('/pkgA/lib/')],
75 'pkgB': [provider.getResource('/pkgB/lib/')]
76 });
77 {
78 Uri uri = Uri.parse('package:pkgA/libA.dart');
79 Source result = resolver.resolveAbsolute(uri);
80 expect(result, isNotNull);
81 expect(result.exists(), isTrue);
82 expect(result.uriKind, UriKind.PACKAGE_URI);
83 expect(result.fullName, pkgFileA);
84 }
85 {
86 Uri uri = Uri.parse('package:pkgB/libB.dart');
87 Source result = resolver.resolveAbsolute(uri);
88 expect(result, isNotNull);
89 expect(result.exists(), isTrue);
90 expect(result.uriKind, UriKind.PACKAGE_URI);
91 expect(result.fullName, pkgFileB);
92 }
93 }
94
95 void test_resolve_multiple_folders() {
96 const pkgFileA = '/part1/lib/libA.dart';
97 const pkgFileB = '/part2/lib/libB.dart';
98 provider.newFile(pkgFileA, 'library lib_a');
99 provider.newFile(pkgFileB, 'library lib_b');
100 PackageMapUriResolver resolver = new PackageMapUriResolver(provider,
101 <String, List<Folder>>{
102 'pkg': [provider.getResource('/part1/lib/'),
103 provider.getResource('/part2/lib/')]
104 });
105 {
106 Uri uri = Uri.parse('package:pkg/libA.dart');
107 Source result = resolver.resolveAbsolute(uri);
108 expect(result, isNotNull);
109 expect(result.exists(), isTrue);
110 expect(result.uriKind, UriKind.PACKAGE_URI);
111 expect(result.fullName, pkgFileA);
112 }
113 {
114 Uri uri = Uri.parse('package:pkg/libB.dart');
115 Source result = resolver.resolveAbsolute(uri);
116 expect(result, isNotNull);
117 expect(result.exists(), isTrue);
118 expect(result.uriKind, UriKind.PACKAGE_URI);
119 expect(result.fullName, pkgFileB);
120 }
121 }
122
123 void test_resolve_nonPackage() {
124 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
125 Uri uri = Uri.parse('dart:core');
126 Source result = resolver.resolveAbsolute(uri);
127 expect(result, isNull);
128 }
129
130 void test_resolve_package_invalid_leadingSlash() {
131 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
132 Uri uri = Uri.parse('package:/foo');
133 Source result = resolver.resolveAbsolute(uri);
134 expect(result, isNull);
135 }
136
137 void test_resolve_package_invalid_noSlash() {
138 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
139 Uri uri = Uri.parse('package:foo');
140 Source result = resolver.resolveAbsolute(uri);
141 expect(result, isNull);
142 }
143
144 void test_resolve_package_invalid_onlySlash() {
145 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
146 Uri uri = Uri.parse('package:/');
147 Source result = resolver.resolveAbsolute(uri);
148 expect(result, isNull);
149 }
150
151 void test_resolve_package_notInMap() {
152 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
153 Uri uri = Uri.parse('package:analyzer/analyzer.dart');
154 Source result = resolver.resolveAbsolute(uri);
155 expect(result, isNotNull);
156 expect(result.exists(), isFalse);
157 expect(result.fullName, 'package:analyzer/analyzer.dart');
158 }
159 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/package_uri_resolver.dart ('k') | pkg/analysis_server/test/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698