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

Side by Side Diff: pkg/analyzer/test/src/util/fast_uri_test.dart

Issue 2003633002: Use FastUri instead of Uri in analyzer. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Fixes for review comments. Created 4 years, 7 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
(Empty)
1 // Copyright (c) 2016, 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 analyzer.test.src.util.fast_uri_test;
6
7 import 'package:analyzer/src/util/fast_uri.dart';
8 import 'package:unittest/unittest.dart';
9
10 import '../../reflective_tests.dart';
11 import '../../utils.dart';
12
13 main() {
14 initializeTestEnvironment();
15 runReflectiveTests(_FastUriTest);
16 }
17
18 @reflectiveTest
19 class _FastUriTest {
20 static final isInstanceOf<FastUri> isFastUri = new isInstanceOf<FastUri>();
21
22 void test_parse_absolute_dart() {
23 _compareTextWithCoreUri('dart:core');
24 }
25
26 void test_parse_absolute_file() {
27 _compareTextWithCoreUri('file:///Users/scheglov/util/fast_uri.dart');
28 }
29
30 void test_parse_absolute_folder_withSlashAtTheEnd() {
31 _compareTextWithCoreUri('file:///Users/scheglov/util/');
32 }
33
34 void test_parse_absolute_package() {
35 _compareTextWithCoreUri('package:analyzer/src/util/fast_uri.dart');
36 }
37
38 void test_parse_notFast() {
39 Uri uri = FastUri.parse('http://www.google.com:8080/pages/about.html');
40 expect(uri, isNot(isFastUri));
41 }
42
43 void test_parse_relative_down() {
44 _compareTextWithCoreUri('util/fast_uri.dart');
45 }
46
47 void test_parse_relative_up() {
48 _compareTextWithCoreUri('../util/fast_uri.dart');
49 }
50
51 void test_resolve() {
52 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/c.dart');
53 Uri uri2 = uri1.resolve('dd.dart');
54 _compareUris(uri2, Uri.parse('package:analyzer/aaa/bbbb/dd.dart'));
55 }
56
57 void test_resolveUri_absolute() {
58 _checkResolveUri('package:analyzer/aaa/b.dart', 'package:path/style.dart',
59 'package:path/style.dart');
60 }
61
62 void test_resolveUri_endWithSlash_onlyName() {
63 _checkResolveUri('package:analyzer/aaa/bbbb/', 'cc.dart',
64 'package:analyzer/aaa/bbbb/cc.dart');
65 }
66
67 void test_resolveUri_nameStartsWithOneDot() {
68 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '.name.dart',
69 'package:analyzer/aaa/bbbb/.name.dart');
70 }
71
72 void test_resolveUri_nameStartsWithTwoDots() {
73 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '..name.dart',
74 'package:analyzer/aaa/bbbb/..name.dart');
75 }
76
77 void test_resolveUri_noSlash_onlyName() {
78 _checkResolveUri('dart:core', 'int.dart', 'dart:core/int.dart');
79 }
80
81 void test_resolveUri_onlyName() {
82 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd.dart',
83 'package:analyzer/aaa/bbbb/dd.dart');
84 }
85
86 void test_resolveUri_pathHasOneDot() {
87 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/./ee.dart',
88 'package:analyzer/aaa/bbbb/dd/ee.dart');
89 }
90
91 void test_resolveUri_pathHasTwoDots() {
92 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/../ee.dart',
93 'package:analyzer/aaa/bbbb/ee.dart');
94 }
95
96 void test_resolveUri_pathStartsWithOneDot() {
97 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', './ddd.dart',
98 'package:analyzer/aaa/bbbb/ddd.dart');
99 }
100
101 void test_resolveUri_pathStartsWithTwoDots() {
102 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '../ddd.dart',
103 'package:analyzer/aaa/ddd.dart');
104 }
105
106 void test_resolveUri_pathWithSubFolder() {
107 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/ccc.dart');
108 Uri uri2 = FastUri.parse('dd/eeee.dart');
109 expect(uri1, isFastUri);
110 expect(uri2, isFastUri);
111 Uri uri3 = uri1.resolveUri(uri2);
112 expect(uri3, isFastUri);
113 _compareUris(uri3, Uri.parse('package:analyzer/aaa/bbbb/dd/eeee.dart'));
114 }
115
116 void _checkResolveUri(String srcText, String relText, String targetText) {
117 Uri src = FastUri.parse(srcText);
118 Uri rel = FastUri.parse(relText);
119 expect(src, isFastUri);
120 expect(rel, isFastUri);
121 Uri target = src.resolveUri(rel);
122 expect(target, isFastUri);
123 _compareUris(target, Uri.parse(targetText));
124 }
125
126 void _compareTextWithCoreUri(String text, {bool isFast: true}) {
127 Uri fastUri = FastUri.parse(text);
128 Uri coreUri = Uri.parse(text);
129 if (isFast) {
130 expect(fastUri, isFastUri);
131 }
132 _compareUris(fastUri, coreUri);
133 }
134
135 void _compareUris(Uri fastUri, Uri coreUri) {
136 expect(fastUri.authority, coreUri.authority);
137 expect(fastUri.data, coreUri.data);
138 expect(fastUri.fragment, coreUri.fragment);
139 expect(fastUri.hasAbsolutePath, coreUri.hasAbsolutePath);
140 expect(fastUri.hasAuthority, coreUri.hasEmptyPath);
141 expect(fastUri.hasFragment, coreUri.hasFragment);
142 expect(fastUri.hasPort, coreUri.hasPort);
143 expect(fastUri.hasQuery, coreUri.hasQuery);
144 expect(fastUri.hasScheme, coreUri.hasScheme);
145 expect(fastUri.host, coreUri.host);
146 expect(fastUri.isAbsolute, coreUri.isAbsolute);
147 if (coreUri.scheme == 'http' || coreUri.scheme == 'https') {
148 expect(fastUri.origin, coreUri.origin);
149 }
150 expect(fastUri.path, coreUri.path);
151 expect(fastUri.pathSegments, coreUri.pathSegments);
152 expect(fastUri.port, coreUri.port);
153 expect(fastUri.query, coreUri.query);
154 expect(fastUri.queryParameters, coreUri.queryParameters);
155 expect(fastUri.queryParametersAll, coreUri.queryParametersAll);
156 expect(fastUri.scheme, coreUri.scheme);
157 expect(fastUri.userInfo, coreUri.userInfo);
158 }
159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698