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

Side by Side Diff: pkg/path/test/windows_test.dart

Issue 59133009: Properly support UNC paths in pkg/path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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
« no previous file with comments | « pkg/path/lib/path.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 path.test.windows_test; 5 library path.test.windows_test;
6 6
7 import 'package:unittest/unittest.dart'; 7 import 'package:unittest/unittest.dart';
8 import 'package:path/path.dart' as path; 8 import 'package:path/path.dart' as path;
9 9
10 main() { 10 main() {
(...skipping 28 matching lines...) Expand all
39 expect(builder.extension(r'foo.dart\\'), '.dart'); 39 expect(builder.extension(r'foo.dart\\'), '.dart');
40 }); 40 });
41 41
42 test('rootPrefix', () { 42 test('rootPrefix', () {
43 expect(builder.rootPrefix(''), ''); 43 expect(builder.rootPrefix(''), '');
44 expect(builder.rootPrefix('a'), ''); 44 expect(builder.rootPrefix('a'), '');
45 expect(builder.rootPrefix(r'a\b'), ''); 45 expect(builder.rootPrefix(r'a\b'), '');
46 expect(builder.rootPrefix(r'C:\a\c'), r'C:\'); 46 expect(builder.rootPrefix(r'C:\a\c'), r'C:\');
47 expect(builder.rootPrefix('C:\\'), r'C:\'); 47 expect(builder.rootPrefix('C:\\'), r'C:\');
48 expect(builder.rootPrefix('C:/'), 'C:/'); 48 expect(builder.rootPrefix('C:/'), 'C:/');
49 49 expect(builder.rootPrefix(r'\\server\share\a\b'), r'\\server\share');
50 // TODO(nweiz): enable this once issue 7323 is fixed.
51 // expect(builder.rootPrefix(r'\\server\a\b'), r'\\server\');
52 }); 50 });
53 51
54 test('dirname', () { 52 test('dirname', () {
55 expect(builder.dirname(r''), '.'); 53 expect(builder.dirname(r''), '.');
56 expect(builder.dirname(r'a'), '.'); 54 expect(builder.dirname(r'a'), '.');
57 expect(builder.dirname(r'a\b'), 'a'); 55 expect(builder.dirname(r'a\b'), 'a');
58 expect(builder.dirname(r'a\b\c'), r'a\b'); 56 expect(builder.dirname(r'a\b\c'), r'a\b');
59 expect(builder.dirname(r'a\b.c'), 'a'); 57 expect(builder.dirname(r'a\b.c'), 'a');
60 expect(builder.dirname(r'a\'), '.'); 58 expect(builder.dirname(r'a\'), '.');
61 expect(builder.dirname('a/'), '.'); 59 expect(builder.dirname('a/'), '.');
62 expect(builder.dirname(r'a\.'), 'a'); 60 expect(builder.dirname(r'a\.'), 'a');
63 expect(builder.dirname(r'a\b/c'), r'a\b'); 61 expect(builder.dirname(r'a\b/c'), r'a\b');
64 expect(builder.dirname(r'C:\a'), r'C:\'); 62 expect(builder.dirname(r'C:\a'), r'C:\');
65 expect(builder.dirname(r'C:\\\a'), r'C:\'); 63 expect(builder.dirname(r'C:\\\a'), r'C:\');
66 expect(builder.dirname(r'C:\'), r'C:\'); 64 expect(builder.dirname(r'C:\'), r'C:\');
67 expect(builder.dirname(r'C:\\\'), r'C:\'); 65 expect(builder.dirname(r'C:\\\'), r'C:\');
68 expect(builder.dirname(r'a\b\'), r'a'); 66 expect(builder.dirname(r'a\b\'), r'a');
69 expect(builder.dirname(r'a/b\c'), 'a/b'); 67 expect(builder.dirname(r'a/b\c'), 'a/b');
70 expect(builder.dirname(r'a\\'), r'.'); 68 expect(builder.dirname(r'a\\'), r'.');
71 expect(builder.dirname(r'a\b\\'), 'a'); 69 expect(builder.dirname(r'a\b\\'), 'a');
72 expect(builder.dirname(r'a\\b'), 'a'); 70 expect(builder.dirname(r'a\\b'), 'a');
73 expect(builder.dirname(r'foo bar\gule fisk'), 'foo bar'); 71 expect(builder.dirname(r'foo bar\gule fisk'), 'foo bar');
72 expect(builder.dirname(r'\\server\share'), r'\\server\share');
73 expect(builder.dirname(r'\\server\share\dir'), r'\\server\share');
74 }); 74 });
75 75
76 test('basename', () { 76 test('basename', () {
77 expect(builder.basename(r''), ''); 77 expect(builder.basename(r''), '');
78 expect(builder.basename(r'.'), '.'); 78 expect(builder.basename(r'.'), '.');
79 expect(builder.basename(r'..'), '..'); 79 expect(builder.basename(r'..'), '..');
80 expect(builder.basename(r'.hest'), '.hest'); 80 expect(builder.basename(r'.hest'), '.hest');
81 expect(builder.basename(r'a'), 'a'); 81 expect(builder.basename(r'a'), 'a');
82 expect(builder.basename(r'a\b'), 'b'); 82 expect(builder.basename(r'a\b'), 'b');
83 expect(builder.basename(r'a\b\c'), 'c'); 83 expect(builder.basename(r'a\b\c'), 'c');
84 expect(builder.basename(r'a\b.c'), 'b.c'); 84 expect(builder.basename(r'a\b.c'), 'b.c');
85 expect(builder.basename(r'a\'), 'a'); 85 expect(builder.basename(r'a\'), 'a');
86 expect(builder.basename(r'a/'), 'a'); 86 expect(builder.basename(r'a/'), 'a');
87 expect(builder.basename(r'a\.'), '.'); 87 expect(builder.basename(r'a\.'), '.');
88 expect(builder.basename(r'a\b/c'), r'c'); 88 expect(builder.basename(r'a\b/c'), r'c');
89 expect(builder.basename(r'C:\a'), 'a'); 89 expect(builder.basename(r'C:\a'), 'a');
90 expect(builder.basename(r'C:\'), r'C:\'); 90 expect(builder.basename(r'C:\'), r'C:\');
91 expect(builder.basename(r'a\b\'), 'b'); 91 expect(builder.basename(r'a\b\'), 'b');
92 expect(builder.basename(r'a/b\c'), 'c'); 92 expect(builder.basename(r'a/b\c'), 'c');
93 expect(builder.basename(r'a\\'), 'a'); 93 expect(builder.basename(r'a\\'), 'a');
94 expect(builder.basename(r'a\b\\'), 'b'); 94 expect(builder.basename(r'a\b\\'), 'b');
95 expect(builder.basename(r'a\\b'), 'b'); 95 expect(builder.basename(r'a\\b'), 'b');
96 expect(builder.basename(r'a\\b'), 'b'); 96 expect(builder.basename(r'a\\b'), 'b');
97 expect(builder.basename(r'a\fisk hest.ma pa'), 'fisk hest.ma pa'); 97 expect(builder.basename(r'a\fisk hest.ma pa'), 'fisk hest.ma pa');
98 expect(builder.basename(r'\\server\share'), r'\\server\share');
99 expect(builder.basename(r'\\server\share\dir'), r'dir');
98 }); 100 });
99 101
100 test('basenameWithoutExtension', () { 102 test('basenameWithoutExtension', () {
101 expect(builder.basenameWithoutExtension(''), ''); 103 expect(builder.basenameWithoutExtension(''), '');
102 expect(builder.basenameWithoutExtension('.'), '.'); 104 expect(builder.basenameWithoutExtension('.'), '.');
103 expect(builder.basenameWithoutExtension('..'), '..'); 105 expect(builder.basenameWithoutExtension('..'), '..');
104 expect(builder.basenameWithoutExtension('.hest'), '.hest'); 106 expect(builder.basenameWithoutExtension('.hest'), '.hest');
105 expect(builder.basenameWithoutExtension('a'), 'a'); 107 expect(builder.basenameWithoutExtension('a'), 'a');
106 expect(builder.basenameWithoutExtension(r'a\b'), 'b'); 108 expect(builder.basenameWithoutExtension(r'a\b'), 'b');
107 expect(builder.basenameWithoutExtension(r'a\b\c'), 'c'); 109 expect(builder.basenameWithoutExtension(r'a\b\c'), 'c');
(...skipping 21 matching lines...) Expand all
129 expect(builder.isAbsolute(r'\a\b'), false); 131 expect(builder.isAbsolute(r'\a\b'), false);
130 expect(builder.isAbsolute('~'), false); 132 expect(builder.isAbsolute('~'), false);
131 expect(builder.isAbsolute('.'), false); 133 expect(builder.isAbsolute('.'), false);
132 expect(builder.isAbsolute(r'..\a'), false); 134 expect(builder.isAbsolute(r'..\a'), false);
133 expect(builder.isAbsolute(r'a:/a\b'), true); 135 expect(builder.isAbsolute(r'a:/a\b'), true);
134 expect(builder.isAbsolute(r'D:/a/b'), true); 136 expect(builder.isAbsolute(r'D:/a/b'), true);
135 expect(builder.isAbsolute(r'c:\'), true); 137 expect(builder.isAbsolute(r'c:\'), true);
136 expect(builder.isAbsolute(r'B:\'), true); 138 expect(builder.isAbsolute(r'B:\'), true);
137 expect(builder.isAbsolute(r'c:\a'), true); 139 expect(builder.isAbsolute(r'c:\a'), true);
138 expect(builder.isAbsolute(r'C:\a'), true); 140 expect(builder.isAbsolute(r'C:\a'), true);
139 expect(builder.isAbsolute(r'\\a'), true); 141 expect(builder.isAbsolute(r'\\server\share'), true);
140 expect(builder.isAbsolute(r'\\'), true); 142 expect(builder.isAbsolute(r'\\server\share\path'), true);
141 }); 143 });
142 144
143 test('isRelative', () { 145 test('isRelative', () {
144 expect(builder.isRelative(''), true); 146 expect(builder.isRelative(''), true);
145 expect(builder.isRelative('.'), true); 147 expect(builder.isRelative('.'), true);
146 expect(builder.isRelative('..'), true); 148 expect(builder.isRelative('..'), true);
147 expect(builder.isRelative('a'), true); 149 expect(builder.isRelative('a'), true);
148 expect(builder.isRelative(r'a\b'), true); 150 expect(builder.isRelative(r'a\b'), true);
149 expect(builder.isRelative(r'\a'), true); 151 expect(builder.isRelative(r'\a'), true);
150 expect(builder.isRelative(r'\a\b'), true); 152 expect(builder.isRelative(r'\a\b'), true);
151 expect(builder.isRelative('~'), true); 153 expect(builder.isRelative('~'), true);
152 expect(builder.isRelative('.'), true); 154 expect(builder.isRelative('.'), true);
153 expect(builder.isRelative(r'..\a'), true); 155 expect(builder.isRelative(r'..\a'), true);
154 expect(builder.isRelative(r'a:/a\b'), false); 156 expect(builder.isRelative(r'a:/a\b'), false);
155 expect(builder.isRelative(r'D:/a/b'), false); 157 expect(builder.isRelative(r'D:/a/b'), false);
156 expect(builder.isRelative(r'c:\'), false); 158 expect(builder.isRelative(r'c:\'), false);
157 expect(builder.isRelative(r'B:\'), false); 159 expect(builder.isRelative(r'B:\'), false);
158 expect(builder.isRelative(r'c:\a'), false); 160 expect(builder.isRelative(r'c:\a'), false);
159 expect(builder.isRelative(r'C:\a'), false); 161 expect(builder.isRelative(r'C:\a'), false);
160 expect(builder.isRelative(r'\\a'), false); 162 expect(builder.isRelative(r'\\server\share'), false);
161 expect(builder.isRelative(r'\\'), false); 163 expect(builder.isRelative(r'\\server\share\path'), false);
162 }); 164 });
163 165
164 group('join', () { 166 group('join', () {
165 test('allows up to eight parts', () { 167 test('allows up to eight parts', () {
166 expect(builder.join('a'), 'a'); 168 expect(builder.join('a'), 'a');
167 expect(builder.join('a', 'b'), r'a\b'); 169 expect(builder.join('a', 'b'), r'a\b');
168 expect(builder.join('a', 'b', 'c'), r'a\b\c'); 170 expect(builder.join('a', 'b', 'c'), r'a\b\c');
169 expect(builder.join('a', 'b', 'c', 'd'), r'a\b\c\d'); 171 expect(builder.join('a', 'b', 'c', 'd'), r'a\b\c\d');
170 expect(builder.join('a', 'b', 'c', 'd', 'e'), r'a\b\c\d\e'); 172 expect(builder.join('a', 'b', 'c', 'd', 'e'), r'a\b\c\d\e');
171 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f'), r'a\b\c\d\e\f'); 173 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f'), r'a\b\c\d\e\f');
172 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), r'a\b\c\d\e\f\g'); 174 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), r'a\b\c\d\e\f\g');
173 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), 175 expect(builder.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
174 r'a\b\c\d\e\f\g\h'); 176 r'a\b\c\d\e\f\g\h');
175 }); 177 });
176 178
177 test('does not add separator if a part ends or begins in one', () { 179 test('does not add separator if a part ends or begins in one', () {
178 expect(builder.join(r'a\', 'b', r'c\', 'd'), r'a\b\c\d'); 180 expect(builder.join(r'a\', 'b', r'c\', 'd'), r'a\b\c\d');
179 expect(builder.join('a/', 'b'), r'a/b'); 181 expect(builder.join('a/', 'b'), r'a/b');
180 expect(builder.join('a', '/b'), 'a/b'); 182 expect(builder.join('a', '/b'), 'a/b');
181 expect(builder.join('a', r'\b'), r'a\b'); 183 expect(builder.join('a', r'\b'), r'a\b');
182 }); 184 });
183 185
184 test('ignores parts before an absolute path', () { 186 test('ignores parts before an absolute path', () {
185 expect(builder.join('a', '/b', '/c', 'd'), r'a/b/c\d'); 187 expect(builder.join('a', '/b', '/c', 'd'), r'a/b/c\d');
186 expect(builder.join('a', r'c:\b', 'c', 'd'), r'c:\b\c\d'); 188 expect(builder.join('a', r'c:\b', 'c', 'd'), r'c:\b\c\d');
187 expect(builder.join('a', r'\\b', r'\\c', 'd'), r'\\c\d'); 189 expect(builder.join('a', r'\\b\c', r'\\d\e', 'f'), r'\\d\e\f');
188 }); 190 });
189 191
190 test('ignores trailing nulls', () { 192 test('ignores trailing nulls', () {
191 expect(builder.join('a', null), equals('a')); 193 expect(builder.join('a', null), equals('a'));
192 expect(builder.join('a', 'b', 'c', null, null), equals(r'a\b\c')); 194 expect(builder.join('a', 'b', 'c', null, null), equals(r'a\b\c'));
193 }); 195 });
194 196
195 test('ignores empty strings', () { 197 test('ignores empty strings', () {
196 expect(builder.join(''), ''); 198 expect(builder.join(''), '');
197 expect(builder.join('', ''), ''); 199 expect(builder.join('', ''), '');
(...skipping 25 matching lines...) Expand all
223 test('does not add separator if a part ends or begins in one', () { 225 test('does not add separator if a part ends or begins in one', () {
224 expect(builder.joinAll([r'a\', 'b', r'c\', 'd']), r'a\b\c\d'); 226 expect(builder.joinAll([r'a\', 'b', r'c\', 'd']), r'a\b\c\d');
225 expect(builder.joinAll(['a/', 'b']), r'a/b'); 227 expect(builder.joinAll(['a/', 'b']), r'a/b');
226 expect(builder.joinAll(['a', '/b']), 'a/b'); 228 expect(builder.joinAll(['a', '/b']), 'a/b');
227 expect(builder.joinAll(['a', r'\b']), r'a\b'); 229 expect(builder.joinAll(['a', r'\b']), r'a\b');
228 }); 230 });
229 231
230 test('ignores parts before an absolute path', () { 232 test('ignores parts before an absolute path', () {
231 expect(builder.joinAll(['a', '/b', '/c', 'd']), r'a/b/c\d'); 233 expect(builder.joinAll(['a', '/b', '/c', 'd']), r'a/b/c\d');
232 expect(builder.joinAll(['a', r'c:\b', 'c', 'd']), r'c:\b\c\d'); 234 expect(builder.joinAll(['a', r'c:\b', 'c', 'd']), r'c:\b\c\d');
233 expect(builder.joinAll(['a', r'\\b', r'\\c', 'd']), r'\\c\d'); 235 expect(builder.joinAll(['a', r'\\b\c', r'\\d\e', 'f']), r'\\d\e\f');
234 }); 236 });
235 }); 237 });
236 238
237 group('split', () { 239 group('split', () {
238 test('simple cases', () { 240 test('simple cases', () {
239 expect(builder.split(''), []); 241 expect(builder.split(''), []);
240 expect(builder.split('.'), ['.']); 242 expect(builder.split('.'), ['.']);
241 expect(builder.split('..'), ['..']); 243 expect(builder.split('..'), ['..']);
242 expect(builder.split('foo'), equals(['foo'])); 244 expect(builder.split('foo'), equals(['foo']));
243 expect(builder.split(r'foo\bar.txt'), equals(['foo', 'bar.txt'])); 245 expect(builder.split(r'foo\bar.txt'), equals(['foo', 'bar.txt']));
244 expect(builder.split(r'foo\bar/baz'), equals(['foo', 'bar', 'baz'])); 246 expect(builder.split(r'foo\bar/baz'), equals(['foo', 'bar', 'baz']));
245 expect(builder.split(r'foo\..\bar\.\baz'), 247 expect(builder.split(r'foo\..\bar\.\baz'),
246 equals(['foo', '..', 'bar', '.', 'baz'])); 248 equals(['foo', '..', 'bar', '.', 'baz']));
247 expect(builder.split(r'foo\\bar\\\baz'), equals(['foo', 'bar', 'baz'])); 249 expect(builder.split(r'foo\\bar\\\baz'), equals(['foo', 'bar', 'baz']));
248 expect(builder.split(r'foo\/\baz'), equals(['foo', 'baz'])); 250 expect(builder.split(r'foo\/\baz'), equals(['foo', 'baz']));
249 expect(builder.split('.'), equals(['.'])); 251 expect(builder.split('.'), equals(['.']));
250 expect(builder.split(''), equals([])); 252 expect(builder.split(''), equals([]));
251 expect(builder.split('foo/'), equals(['foo'])); 253 expect(builder.split('foo/'), equals(['foo']));
252 expect(builder.split(r'C:\'), equals([r'C:\'])); 254 expect(builder.split(r'C:\'), equals([r'C:\']));
253 }); 255 });
254 256
255 test('includes the root for absolute paths', () { 257 test('includes the root for absolute paths', () {
256 expect(builder.split(r'C:\foo\bar\baz'), 258 expect(builder.split(r'C:\foo\bar\baz'),
257 equals([r'C:\', 'foo', 'bar', 'baz'])); 259 equals([r'C:\', 'foo', 'bar', 'baz']));
258 expect(builder.split(r'C:\\'), equals([r'C:\'])); 260 expect(builder.split(r'C:\\'), equals([r'C:\']));
259 261
260 // TODO(nweiz): enable these once issue 7323 is fixed. 262 expect(builder.split(r'\\server\share\foo\bar\baz'),
261 // expect(builder.split(r'\\server\foo\bar\baz'), 263 equals([r'\\server\share', 'foo', 'bar', 'baz']));
262 // equals([r'\\server\', 'foo', 'bar', 'baz'])); 264 expect(builder.split(r'\\server\share'), equals([r'\\server\share']));
263 // expect(builder.split(r'\\server\'), equals([r'\\server\']));
264 }); 265 });
265 }); 266 });
266 267
267 group('normalize', () { 268 group('normalize', () {
268 test('simple cases', () { 269 test('simple cases', () {
269 expect(builder.normalize(''), '.'); 270 expect(builder.normalize(''), '.');
270 expect(builder.normalize('.'), '.'); 271 expect(builder.normalize('.'), '.');
271 expect(builder.normalize('..'), '..'); 272 expect(builder.normalize('..'), '..');
272 expect(builder.normalize('a'), 'a'); 273 expect(builder.normalize('a'), 'a');
273 expect(builder.normalize(r'\'), '.'); 274 expect(builder.normalize(r'\'), '.');
274 expect(builder.normalize('/'), r'.'); 275 expect(builder.normalize('/'), r'.');
275 expect(builder.normalize('C:/'), r'C:\'); 276 expect(builder.normalize('C:/'), r'C:\');
276 expect(builder.normalize(r'C:\'), r'C:\'); 277 expect(builder.normalize(r'C:\'), r'C:\');
277 expect(builder.normalize(r'\\'), r'\\'); 278 expect(builder.normalize(r'\\server\share'), r'\\server\share');
278 expect(builder.normalize('a\\.\\\xc5\u0bf8-;\u{1f085}\u{00}\\c\\d\\..\\'), 279 expect(builder.normalize('a\\.\\\xc5\u0bf8-;\u{1f085}\u{00}\\c\\d\\..\\'),
279 'a\\\xc5\u0bf8-;\u{1f085}\u{00}\x5cc'); 280 'a\\\xc5\u0bf8-;\u{1f085}\u{00}\x5cc');
280 }); 281 });
281 282
282 test('collapses redundant separators', () { 283 test('collapses redundant separators', () {
283 expect(builder.normalize(r'a\b\c'), r'a\b\c'); 284 expect(builder.normalize(r'a\b\c'), r'a\b\c');
284 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d'); 285 expect(builder.normalize(r'a\\b\\\c\\\\d'), r'a\b\c\d');
285 }); 286 });
286 287
287 test('eliminates "." parts', () { 288 test('eliminates "." parts', () {
288 expect(builder.normalize(r'.\'), '.'); 289 expect(builder.normalize(r'.\'), '.');
289 expect(builder.normalize(r'c:\.'), r'c:\'); 290 expect(builder.normalize(r'c:\.'), r'c:\');
290 expect(builder.normalize(r'B:\.\'), r'B:\'); 291 expect(builder.normalize(r'B:\.\'), r'B:\');
291 expect(builder.normalize(r'\\.'), r'\\'); 292 expect(builder.normalize(r'\\server\share\.'), r'\\server\share');
292 expect(builder.normalize(r'\\.\'), r'\\');
293 expect(builder.normalize(r'.\.'), '.'); 293 expect(builder.normalize(r'.\.'), '.');
294 expect(builder.normalize(r'a\.\b'), r'a\b'); 294 expect(builder.normalize(r'a\.\b'), r'a\b');
295 expect(builder.normalize(r'a\.b\c'), r'a\.b\c'); 295 expect(builder.normalize(r'a\.b\c'), r'a\.b\c');
296 expect(builder.normalize(r'a\./.\b\.\c'), r'a\b\c'); 296 expect(builder.normalize(r'a\./.\b\.\c'), r'a\b\c');
297 expect(builder.normalize(r'.\./a'), 'a'); 297 expect(builder.normalize(r'.\./a'), 'a');
298 expect(builder.normalize(r'a/.\.'), 'a'); 298 expect(builder.normalize(r'a/.\.'), 'a');
299 }); 299 });
300 300
301 test('eliminates ".." parts', () { 301 test('eliminates ".." parts', () {
302 expect(builder.normalize('..'), '..'); 302 expect(builder.normalize('..'), '..');
303 expect(builder.normalize(r'..\'), '..'); 303 expect(builder.normalize(r'..\'), '..');
304 expect(builder.normalize(r'..\..\..'), r'..\..\..'); 304 expect(builder.normalize(r'..\..\..'), r'..\..\..');
305 expect(builder.normalize(r'../..\..\'), r'..\..\..'); 305 expect(builder.normalize(r'../..\..\'), r'..\..\..');
306 // TODO(rnystrom): Is this how Python handles absolute paths on Windows? 306 expect(builder.normalize(r'\\server\share\..'), r'\\server\share');
307 expect(builder.normalize(r'\\..'), r'\\'); 307 expect(builder.normalize(r'\\server\share\..\../..\a'),
308 expect(builder.normalize(r'\\..\..\..'), r'\\'); 308 r'\\server\share\a');
309 expect(builder.normalize(r'\\..\../..\a'), r'\\a');
310 expect(builder.normalize(r'c:\..'), r'c:\'); 309 expect(builder.normalize(r'c:\..'), r'c:\');
311 expect(builder.normalize(r'A:/..\..\..'), r'A:\'); 310 expect(builder.normalize(r'A:/..\..\..'), r'A:\');
312 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a'); 311 expect(builder.normalize(r'b:\..\..\..\a'), r'b:\a');
313 expect(builder.normalize(r'b:\r\..\..\..\a\c\.\..'), r'b:\a'); 312 expect(builder.normalize(r'b:\r\..\..\..\a\c\.\..'), r'b:\a');
314 expect(builder.normalize(r'a\..'), '.'); 313 expect(builder.normalize(r'a\..'), '.');
315 expect(builder.normalize(r'..\a'), r'..\a'); 314 expect(builder.normalize(r'..\a'), r'..\a');
316 expect(builder.normalize(r'c:\..\a'), r'c:\a'); 315 expect(builder.normalize(r'c:\..\a'), r'c:\a');
317 // A path starting with '\' is not an absolute path on Windows. 316 // A path starting with '\' is not an absolute path on Windows.
318 expect(builder.normalize(r'\..\a'), r'..\a'); 317 expect(builder.normalize(r'\..\a'), r'..\a');
319 expect(builder.normalize(r'a\b\..'), 'a'); 318 expect(builder.normalize(r'a\b\..'), 'a');
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 var r = new path.Builder(style: path.Style.windows, root: r'relative\root' ); 426 var r = new path.Builder(style: path.Style.windows, root: r'relative\root' );
428 expect(r.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'), equals('baz')); 427 expect(r.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'), equals('baz'));
429 expect(() => r.relative('..', from: r'C:\foo\bar'), throwsArgumentError); 428 expect(() => r.relative('..', from: r'C:\foo\bar'), throwsArgumentError);
430 expect(r.relative(r'C:\foo\bar\baz', from: r'foo\bar'), 429 expect(r.relative(r'C:\foo\bar\baz', from: r'foo\bar'),
431 equals(r'C:\foo\bar\baz')); 430 equals(r'C:\foo\bar\baz'));
432 expect(r.relative('..', from: r'foo\bar'), equals(r'..\..\..')); 431 expect(r.relative('..', from: r'foo\bar'), equals(r'..\..\..'));
433 }); 432 });
434 433
435 test('given absolute with different root prefix', () { 434 test('given absolute with different root prefix', () {
436 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); 435 expect(builder.relative(r'D:\a\b'), r'D:\a\b');
437 expect(builder.relative(r'\\a\b'), r'\\a\b'); 436 expect(builder.relative(r'\\server\share\a\b'), r'\\server\share\a\b');
438 }); 437 });
439 438
440 test('from a . root', () { 439 test('from a . root', () {
441 var r = new path.Builder(style: path.Style.windows, root: '.'); 440 var r = new path.Builder(style: path.Style.windows, root: '.');
442 expect(r.relative(r'C:\foo\bar\baz'), equals(r'C:\foo\bar\baz')); 441 expect(r.relative(r'C:\foo\bar\baz'), equals(r'C:\foo\bar\baz'));
443 expect(r.relative(r'foo\bar\baz'), equals(r'foo\bar\baz')); 442 expect(r.relative(r'foo\bar\baz'), equals(r'foo\bar\baz'));
444 }); 443 });
445 }); 444 });
446 445
447 group('resolve', () { 446 group('resolve', () {
(...skipping 11 matching lines...) Expand all
459 }); 458 });
460 459
461 test('does not add separator if a part ends in one', () { 460 test('does not add separator if a part ends in one', () {
462 expect(builder.resolve(r'a\', 'b', r'c\', 'd'), r'C:\root\path\a\b\c\d'); 461 expect(builder.resolve(r'a\', 'b', r'c\', 'd'), r'C:\root\path\a\b\c\d');
463 expect(builder.resolve('a/', 'b'), r'C:\root\path\a/b'); 462 expect(builder.resolve('a/', 'b'), r'C:\root\path\a/b');
464 }); 463 });
465 464
466 test('ignores parts before an absolute path', () { 465 test('ignores parts before an absolute path', () {
467 expect(builder.resolve('a', '/b', '/c', 'd'), r'C:\root\path\a/b/c\d'); 466 expect(builder.resolve('a', '/b', '/c', 'd'), r'C:\root\path\a/b/c\d');
468 expect(builder.resolve('a', r'c:\b', 'c', 'd'), r'c:\b\c\d'); 467 expect(builder.resolve('a', r'c:\b', 'c', 'd'), r'c:\b\c\d');
469 expect(builder.resolve('a', r'\\b', r'\\c', 'd'), r'\\c\d'); 468 expect(builder.resolve('a', r'\\b\c', r'\\d\e', 'f'), r'\\d\e\f');
470 }); 469 });
471 }); 470 });
472 471
473 test('withoutExtension', () { 472 test('withoutExtension', () {
474 expect(builder.withoutExtension(''), ''); 473 expect(builder.withoutExtension(''), '');
475 expect(builder.withoutExtension('a'), 'a'); 474 expect(builder.withoutExtension('a'), 'a');
476 expect(builder.withoutExtension('.a'), '.a'); 475 expect(builder.withoutExtension('.a'), '.a');
477 expect(builder.withoutExtension('a.b'), 'a'); 476 expect(builder.withoutExtension('a.b'), 'a');
478 expect(builder.withoutExtension(r'a\b.c'), r'a\b'); 477 expect(builder.withoutExtension(r'a\b.c'), r'a\b');
479 expect(builder.withoutExtension(r'a\b.c.d'), r'a\b.c'); 478 expect(builder.withoutExtension(r'a\b.c.d'), r'a\b.c');
480 expect(builder.withoutExtension(r'a\'), r'a\'); 479 expect(builder.withoutExtension(r'a\'), r'a\');
481 expect(builder.withoutExtension(r'a\b\'), r'a\b\'); 480 expect(builder.withoutExtension(r'a\b\'), r'a\b\');
482 expect(builder.withoutExtension(r'a\.'), r'a\.'); 481 expect(builder.withoutExtension(r'a\.'), r'a\.');
483 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); 482 expect(builder.withoutExtension(r'a\.b'), r'a\.b');
484 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); 483 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c');
485 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); 484 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d');
486 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); 485 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c');
487 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); 486 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c');
488 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); 487 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c');
489 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\'); 488 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\');
490 }); 489 });
491 490
492 test('fromUri', () { 491 test('fromUri', () {
493 expect(builder.fromUri(Uri.parse('file:///C:/path/to/foo')), 492 expect(builder.fromUri(Uri.parse('file:///C:/path/to/foo')),
494 r'C:\path\to\foo'); 493 r'C:\path\to\foo');
495 expect(builder.fromUri(Uri.parse('file://hostname/path/to/foo')), 494 expect(builder.fromUri(Uri.parse('file://server/share/path/to/foo')),
496 r'\\hostname\path\to\foo'); 495 r'\\server\share\path\to\foo');
497 expect(builder.fromUri(Uri.parse('file:///C:/')), r'C:\'); 496 expect(builder.fromUri(Uri.parse('file:///C:/')), r'C:\');
498 expect(builder.fromUri(Uri.parse('file://hostname/')), r'\\hostname\'); 497 expect(builder.fromUri(Uri.parse('file://server/share')),
498 r'\\server\share');
499 expect(builder.fromUri(Uri.parse('foo/bar')), r'foo\bar'); 499 expect(builder.fromUri(Uri.parse('foo/bar')), r'foo\bar');
500 expect(builder.fromUri(Uri.parse('/C:/path/to/foo')), r'C:\path\to\foo'); 500 expect(builder.fromUri(Uri.parse('/C:/path/to/foo')), r'C:\path\to\foo');
501 expect(builder.fromUri(Uri.parse('///C:/path/to/foo')), r'C:\path\to\foo'); 501 expect(builder.fromUri(Uri.parse('///C:/path/to/foo')), r'C:\path\to\foo');
502 expect(builder.fromUri(Uri.parse('//hostname/path/to/foo')), 502 expect(builder.fromUri(Uri.parse('//server/share/path/to/foo')),
503 r'\\hostname\path\to\foo'); 503 r'\\server\share\path\to\foo');
504 expect(builder.fromUri(Uri.parse('file:///C:/path/to/foo%23bar')), 504 expect(builder.fromUri(Uri.parse('file:///C:/path/to/foo%23bar')),
505 r'C:\path\to\foo#bar'); 505 r'C:\path\to\foo#bar');
506 expect(builder.fromUri(Uri.parse('file://hostname/path/to/foo%23bar')), 506 expect(builder.fromUri(Uri.parse('file://server/share/path/to/foo%23bar')),
507 r'\\hostname\path\to\foo#bar'); 507 r'\\server\share\path\to\foo#bar');
508 expect(builder.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')), 508 expect(builder.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')),
509 r'_{_}_`_^_ _"_%_'); 509 r'_{_}_`_^_ _"_%_');
510 expect(() => builder.fromUri(Uri.parse('http://dartlang.org')), 510 expect(() => builder.fromUri(Uri.parse('http://dartlang.org')),
511 throwsArgumentError); 511 throwsArgumentError);
512 }); 512 });
513 513
514 test('toUri', () { 514 test('toUri', () {
515 expect(builder.toUri(r'C:\path\to\foo'), 515 expect(builder.toUri(r'C:\path\to\foo'),
516 Uri.parse('file:///C:/path/to/foo')); 516 Uri.parse('file:///C:/path/to/foo'));
517 expect(builder.toUri(r'C:\path\to\foo\'), 517 expect(builder.toUri(r'C:\path\to\foo\'),
518 Uri.parse('file:///C:/path/to/foo/')); 518 Uri.parse('file:///C:/path/to/foo/'));
519 expect(builder.toUri(r'C:\'), Uri.parse('file:///C:/')); 519 expect(builder.toUri(r'C:\'), Uri.parse('file:///C:/'));
520 expect(builder.toUri(r'\\hostname\'), Uri.parse('file://hostname/')); 520 expect(builder.toUri(r'\\server\share'), Uri.parse('file://server/share'));
521 expect(builder.toUri(r'\\server\share\'),
522 Uri.parse('file://server/share/'));
521 expect(builder.toUri(r'foo\bar'), Uri.parse('foo/bar')); 523 expect(builder.toUri(r'foo\bar'), Uri.parse('foo/bar'));
522 expect(builder.toUri(r'C:\path\to\foo#bar'), 524 expect(builder.toUri(r'C:\path\to\foo#bar'),
523 Uri.parse('file:///C:/path/to/foo%23bar')); 525 Uri.parse('file:///C:/path/to/foo%23bar'));
524 expect(builder.toUri(r'\\hostname\path\to\foo#bar'), 526 expect(builder.toUri(r'\\server\share\path\to\foo#bar'),
525 Uri.parse('file://hostname/path/to/foo%23bar')); 527 Uri.parse('file://server/share/path/to/foo%23bar'));
526 expect(builder.toUri(r'C:\_{_}_`_^_ _"_%_'), 528 expect(builder.toUri(r'C:\_{_}_`_^_ _"_%_'),
527 Uri.parse('file:///C:/_%7B_%7D_%60_%5E_%20_%22_%25_')); 529 Uri.parse('file:///C:/_%7B_%7D_%60_%5E_%20_%22_%25_'));
528 expect(builder.toUri(r'_{_}_`_^_ _"_%_'), 530 expect(builder.toUri(r'_{_}_`_^_ _"_%_'),
529 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); 531 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_'));
530 }); 532 });
531 } 533 }
OLDNEW
« no previous file with comments | « pkg/path/lib/path.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698