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

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

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 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
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:test_reflective_loader/test_reflective_loader.dart';
9 import 'package:unittest/unittest.dart';
10
11 import '../../utils.dart';
12
13 main() {
14 initializeTestEnvironment();
15 defineReflectiveTests(_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_hasAuthority() {
39 Uri uri = FastUri.parse('http://www.google.com/pages/about.html');
40 expect(uri, isNot(isFastUri));
41 }
42
43 void test_parse_notFast_hasPort() {
44 Uri uri = FastUri.parse('http://www.google.com:8080/pages/about.html');
45 expect(uri, isNot(isFastUri));
46 }
47
48 void test_parse_relative_down() {
49 _compareTextWithCoreUri('util/fast_uri.dart');
50 }
51
52 void test_parse_relative_up() {
53 _compareTextWithCoreUri('../util/fast_uri.dart');
54 }
55
56 void test_resolve() {
57 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/c.dart');
58 Uri uri2 = uri1.resolve('dd.dart');
59 _compareUris(uri2, Uri.parse('package:analyzer/aaa/bbbb/dd.dart'));
60 }
61
62 void test_resolveUri_absolute() {
63 _checkResolveUri('package:analyzer/aaa/b.dart', 'package:path/style.dart',
64 'package:path/style.dart');
65 }
66
67 void test_resolveUri_endWithSlash_onlyName() {
68 _checkResolveUri('package:analyzer/aaa/bbbb/', 'cc.dart',
69 'package:analyzer/aaa/bbbb/cc.dart');
70 }
71
72 void test_resolveUri_nameStartsWithOneDot() {
73 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '.name.dart',
74 'package:analyzer/aaa/bbbb/.name.dart');
75 }
76
77 void test_resolveUri_nameStartsWithTwoDots() {
78 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '..name.dart',
79 'package:analyzer/aaa/bbbb/..name.dart');
80 }
81
82 void test_resolveUri_noSlash_onlyName() {
83 _checkResolveUri('dart:core', 'int.dart', 'dart:core/int.dart');
84 }
85
86 void test_resolveUri_onlyName() {
87 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd.dart',
88 'package:analyzer/aaa/bbbb/dd.dart');
89 }
90
91 void test_resolveUri_pathHasOneDot() {
92 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/./ee.dart',
93 'package:analyzer/aaa/bbbb/dd/ee.dart');
94 }
95
96 void test_resolveUri_pathHasTwoDots() {
97 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', 'dd/../ee.dart',
98 'package:analyzer/aaa/bbbb/ee.dart');
99 }
100
101 void test_resolveUri_pathStartsWithOneDot() {
102 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', './ddd.dart',
103 'package:analyzer/aaa/bbbb/ddd.dart');
104 }
105
106 void test_resolveUri_pathStartsWithTwoDots() {
107 _checkResolveUri('package:analyzer/aaa/bbbb/ccc.dart', '../ddd.dart',
108 'package:analyzer/aaa/ddd.dart');
109 }
110
111 void test_resolveUri_pathWithSubFolder() {
112 Uri uri1 = FastUri.parse('package:analyzer/aaa/bbbb/ccc.dart');
113 Uri uri2 = FastUri.parse('dd/eeee.dart');
114 expect(uri1, isFastUri);
115 expect(uri2, isFastUri);
116 Uri uri3 = uri1.resolveUri(uri2);
117 expect(uri3, isFastUri);
118 _compareUris(uri3, Uri.parse('package:analyzer/aaa/bbbb/dd/eeee.dart'));
119 }
120
121 void _checkResolveUri(String srcText, String relText, String targetText) {
122 Uri src = FastUri.parse(srcText);
123 Uri rel = FastUri.parse(relText);
124 expect(src, isFastUri);
125 expect(rel, isFastUri);
126 Uri target = src.resolveUri(rel);
127 expect(target, isFastUri);
128 _compareUris(target, Uri.parse(targetText));
129 }
130
131 void _compareTextWithCoreUri(String text, {bool isFast: true}) {
132 Uri fastUri = FastUri.parse(text);
133 Uri coreUri = Uri.parse(text);
134 if (isFast) {
135 expect(fastUri, isFastUri);
136 }
137 _compareUris(fastUri, coreUri);
138 }
139
140 void _compareUris(Uri fastUri, Uri coreUri) {
141 expect(fastUri.authority, coreUri.authority);
142 expect(fastUri.data, coreUri.data);
143 expect(fastUri.fragment, coreUri.fragment);
144 expect(fastUri.hasAbsolutePath, coreUri.hasAbsolutePath);
145 expect(fastUri.hasAuthority, coreUri.hasAuthority);
146 expect(fastUri.hasEmptyPath, coreUri.hasEmptyPath);
147 expect(fastUri.hasFragment, coreUri.hasFragment);
148 expect(fastUri.hasPort, coreUri.hasPort);
149 expect(fastUri.hasQuery, coreUri.hasQuery);
150 expect(fastUri.hasScheme, coreUri.hasScheme);
151 expect(fastUri.host, coreUri.host);
152 expect(fastUri.isAbsolute, coreUri.isAbsolute);
153 if (coreUri.scheme == 'http' || coreUri.scheme == 'https') {
154 expect(fastUri.origin, coreUri.origin);
155 }
156 expect(fastUri.path, coreUri.path);
157 expect(fastUri.pathSegments, coreUri.pathSegments);
158 expect(fastUri.port, coreUri.port);
159 expect(fastUri.query, coreUri.query);
160 expect(fastUri.queryParameters, coreUri.queryParameters);
161 expect(fastUri.queryParametersAll, coreUri.queryParametersAll);
162 expect(fastUri.scheme, coreUri.scheme);
163 expect(fastUri.userInfo, coreUri.userInfo);
164 // Object
165 expect(fastUri.hashCode, coreUri.hashCode);
166 expect(fastUri == coreUri, isTrue);
167 expect(coreUri == fastUri, isTrue);
168 }
169 }
OLDNEW
« no previous file with comments | « packages/analyzer/test/src/util/asserts_test.dart ('k') | packages/analyzer/test/src/util/glob_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698