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

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

Issue 337383005: PackageMapUriResolver for Dart server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 'package:analysis_server/src/package_uri_resolver.dart';
8 import 'package:analysis_server/src/resource.dart';
9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:unittest/unittest.dart';
11
12 import 'reflective_tests.dart';
13
14 main() {
15 groupSep = ' | ';
16
17 group('PackageMapUriResolver', () {
18 runReflectiveTests(_PackageMapUriResolverTest);
19 });
20 }
21
22
23 @ReflectiveTestCase()
24 class _PackageMapUriResolverTest {
25 static const EMPTY_MAP = const <String, Folder>{};
26 MemoryResourceProvider provider = new MemoryResourceProvider();
27
28 setUp() {
29 }
30
31 tearDown() {
32 }
33
34 void test_isPackageUri() {
35 Uri uri = Uri.parse('package:test/test.dart');
36 expect(uri.scheme, 'package');
37 expect(PackageMapUriResolver.isPackageUri(uri), isTrue);
38 }
39
40 void test_fromEncoding_nonPackage() {
41 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
42 Uri uri = Uri.parse('file:/does/not/exist.dart');
43 Source result = resolver.fromEncoding(UriKind.DART_URI, uri);
44 expect(result, isNull);
45 }
46
47 void test_fromEncoding_package() {
48 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
49 Uri uri = Uri.parse('package:/does/not/exist.dart');
50 Source result = resolver.fromEncoding(UriKind.PACKAGE_URI, uri);
51 expect(result, isNotNull);
52 expect(result.fullName, '/does/not/exist.dart');
53 }
54
55 void test_fromEncoding_packageSelf() {
56 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
57 Uri uri = Uri.parse('package:/does/not/exist.dart');
58 Source result = resolver.fromEncoding(UriKind.PACKAGE_SELF_URI, uri);
59 expect(result, isNotNull);
60 expect(result.fullName, '/does/not/exist.dart');
61 }
62
63 void test_isPackageUri_null_scheme() {
64 Uri uri = Uri.parse('foo.dart');
65 expect(uri.scheme, '');
66 expect(PackageMapUriResolver.isPackageUri(uri), isFalse);
67 }
68
69 void test_isPackageUri_other_scheme() {
70 Uri uri = Uri.parse('memfs:/foo.dart');
71 expect(uri.scheme, 'memfs');
72 expect(PackageMapUriResolver.isPackageUri(uri), isFalse);
73 }
74
75 void test_resolve_OK() {
76 const pkgFileA = '/pkgA/lib/libA.dart';
77 const pkgFileB = '/pkgB/lib/libB.dart';
78 provider.newFile(pkgFileA, 'library lib_a;');
79 provider.newFile(pkgFileB, 'library lib_b;');
80 PackageMapUriResolver resolver = new PackageMapUriResolver(provider,
81 <String, Folder>{
82 'pkgA': provider.getResource('/pkgA/lib/'),
83 'pkgB': provider.getResource('/pkgB/lib/')
84 });
85 {
86 Uri uri = Uri.parse('package:pkgA/libA.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, pkgFileA);
92 }
93 {
94 Uri uri = Uri.parse('package:pkgB/libB.dart');
95 Source result = resolver.resolveAbsolute(uri);
96 expect(result, isNotNull);
97 expect(result.exists(), isTrue);
98 expect(result.uriKind, UriKind.PACKAGE_URI);
99 expect(result.fullName, pkgFileB);
100 }
101 }
102
103 void test_resolve_nonPackage() {
104 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
105 Uri uri = Uri.parse('dart:core');
106 Source result = resolver.resolveAbsolute(uri);
107 expect(result, isNull);
108 }
109
110 void test_resolve_package_invalid_leadingSlash() {
111 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
112 Uri uri = Uri.parse('package:/foo');
113 Source result = resolver.resolveAbsolute(uri);
114 expect(result, isNull);
115 }
116
117 void test_resolve_package_invalid_noSlash() {
118 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
119 Uri uri = Uri.parse('package:foo');
120 Source result = resolver.resolveAbsolute(uri);
121 expect(result, isNull);
122 }
123
124 void test_resolve_package_invalid_onlySlash() {
125 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
126 Uri uri = Uri.parse('package:/');
127 Source result = resolver.resolveAbsolute(uri);
128 expect(result, isNull);
129 }
130
131 void test_resolve_package_notInMap() {
132 UriResolver resolver = new PackageMapUriResolver(provider, EMPTY_MAP);
133 Uri uri = Uri.parse('package:analyzer/analyzer.dart');
134 Source result = resolver.resolveAbsolute(uri);
135 expect(result, isNotNull);
136 expect(result.exists(), isFalse);
137 expect(result.fullName, 'package:analyzer/analyzer.dart');
138 }
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698