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

Side by Side Diff: utils/tests/pub/path/path_windows_test.dart

Issue 11553005: Move path-manipulation code from io.dart into path.dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes + relative fix Created 8 years 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 | « utils/tests/pub/path/path_posix_test.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; 5 library path_test;
6 6
7 import 'dart:io' as io; 7 import 'dart:io' as io;
8 8
9 import '../../../../pkg/unittest/lib/unittest.dart'; 9 import '../../../../pkg/unittest/lib/unittest.dart';
10 import '../../../pub/path.dart' as path; 10 import '../../../pub/path.dart' as path;
(...skipping 17 matching lines...) Expand all
28 test('extension', () { 28 test('extension', () {
29 expect(builder.extension(''), ''); 29 expect(builder.extension(''), '');
30 expect(builder.extension('foo.dart'), '.dart'); 30 expect(builder.extension('foo.dart'), '.dart');
31 expect(builder.extension('foo.dart.js'), '.js'); 31 expect(builder.extension('foo.dart.js'), '.js');
32 expect(builder.extension(r'a.b\c'), ''); 32 expect(builder.extension(r'a.b\c'), '');
33 expect(builder.extension('a.b/c.d'), '.d'); 33 expect(builder.extension('a.b/c.d'), '.d');
34 expect(builder.extension(r'~\.bashrc'), ''); 34 expect(builder.extension(r'~\.bashrc'), '');
35 expect(builder.extension(r'a.b/c'), r''); 35 expect(builder.extension(r'a.b/c'), r'');
36 }); 36 });
37 37
38 test('rootPrefix', () {
39 expect(builder.rootPrefix(''), '');
40 expect(builder.rootPrefix('a'), '');
41 expect(builder.rootPrefix(r'a\b'), '');
42 expect(builder.rootPrefix(r'C:\a\c'), r'C:\');
43 expect(builder.rootPrefix('C:\\'), r'C:\');
44 expect(builder.rootPrefix('C:/'), 'C:/');
45
46 // TODO(nweiz): enable this once issue 7323 is fixed.
47 // expect(builder.rootPrefix(r'\\server\a\b'), r'\\server\');
48 });
49
50 test('dirname', () {
51 expect(builder.dirname(r''), '.');
52 expect(builder.dirname(r'a'), '.');
53 expect(builder.dirname(r'a\b'), 'a');
54 expect(builder.dirname(r'a\b\c'), r'a\b');
55 expect(builder.dirname(r'a\b.c'), 'a');
56 expect(builder.dirname(r'a\'), 'a');
57 expect(builder.dirname('a/'), 'a');
58 expect(builder.dirname(r'a\.'), 'a');
59 expect(builder.dirname(r'a\b/c'), r'a\b');
60 expect(builder.dirname(r'C:\a'), r'C:\');
61 expect(builder.dirname('C:\\'), r'C:\');
62 expect(builder.dirname(r'a\b\'), r'a\b');
63 expect(builder.dirname(r'a/b\c'), 'a/b');
64 expect(builder.dirname(r'a\\'), r'a\');
65 });
66
38 test('basename', () { 67 test('basename', () {
39 expect(builder.basename(r''), ''); 68 expect(builder.basename(r''), '');
40 expect(builder.basename(r'a'), 'a'); 69 expect(builder.basename(r'a'), 'a');
41 expect(builder.basename(r'a\b'), 'b'); 70 expect(builder.basename(r'a\b'), 'b');
42 expect(builder.basename(r'a\b\c'), 'c'); 71 expect(builder.basename(r'a\b\c'), 'c');
43 expect(builder.basename(r'a\b.c'), 'b.c'); 72 expect(builder.basename(r'a\b.c'), 'b.c');
44 expect(builder.basename(r'a\'), ''); 73 expect(builder.basename(r'a\'), '');
45 expect(builder.basename(r'a/'), ''); 74 expect(builder.basename(r'a/'), '');
46 expect(builder.basename(r'a\.'), '.'); 75 expect(builder.basename(r'a\.'), '.');
47 expect(builder.basename(r'a\b/c'), r'c'); 76 expect(builder.basename(r'a\b/c'), r'c');
77 expect(builder.basename(r'C:\a'), 'a');
78 // TODO(nweiz): this should actually return 'C:\'
79 expect(builder.basename(r'C:\'), '');
80 expect(builder.basename(r'a\b\'), '');
81 expect(builder.basename(r'a/b\c'), 'c');
82 expect(builder.basename(r'a\\'), '');
48 }); 83 });
49 84
50 test('basenameWithoutExtension', () { 85 test('basenameWithoutExtension', () {
51 expect(builder.basenameWithoutExtension(''), ''); 86 expect(builder.basenameWithoutExtension(''), '');
52 expect(builder.basenameWithoutExtension('a'), 'a'); 87 expect(builder.basenameWithoutExtension('a'), 'a');
53 expect(builder.basenameWithoutExtension(r'a\b'), 'b'); 88 expect(builder.basenameWithoutExtension(r'a\b'), 'b');
54 expect(builder.basenameWithoutExtension(r'a\b\c'), 'c'); 89 expect(builder.basenameWithoutExtension(r'a\b\c'), 'c');
55 expect(builder.basenameWithoutExtension(r'a\b.c'), 'b'); 90 expect(builder.basenameWithoutExtension(r'a\b.c'), 'b');
56 expect(builder.basenameWithoutExtension(r'a\'), ''); 91 expect(builder.basenameWithoutExtension(r'a\'), '');
57 expect(builder.basenameWithoutExtension(r'a\.'), '.'); 92 expect(builder.basenameWithoutExtension(r'a\.'), '.');
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 expect(builder.join('a/', 'b'), r'a/b'); 151 expect(builder.join('a/', 'b'), r'a/b');
117 expect(builder.join('a', '/b'), 'a/b'); 152 expect(builder.join('a', '/b'), 'a/b');
118 expect(builder.join('a', r'\b'), r'a\b'); 153 expect(builder.join('a', r'\b'), r'a\b');
119 }); 154 });
120 155
121 test('ignores parts before an absolute path', () { 156 test('ignores parts before an absolute path', () {
122 expect(builder.join('a', '/b', '/c', 'd'), r'a/b/c\d'); 157 expect(builder.join('a', '/b', '/c', 'd'), r'a/b/c\d');
123 expect(builder.join('a', r'c:\b', 'c', 'd'), r'c:\b\c\d'); 158 expect(builder.join('a', r'c:\b', 'c', 'd'), r'c:\b\c\d');
124 expect(builder.join('a', r'\\b', r'\\c', 'd'), r'\\c\d'); 159 expect(builder.join('a', r'\\b', r'\\c', 'd'), r'\\c\d');
125 }); 160 });
161
162 test('ignores trailing nulls', () {
163 expect(builder.join('a', null), equals('a'));
164 expect(builder.join('a', 'b', 'c', null, null), equals(r'a\b\c'));
165 });
166
167 test('disallows intermediate nulls', () {
168 expect(() => builder.join('a', null, 'b'), throwsArgumentError);
169 expect(() => builder.join(null, 'a'), throwsArgumentError);
170 });
171 });
172
173 group('split', () {
174 test('simple cases', () {
175 expect(builder.split('foo'), equals(['foo']));
176 expect(builder.split(r'foo\bar'), equals(['foo', 'bar']));
177 expect(builder.split(r'foo\bar\baz'), equals(['foo', 'bar', 'baz']));
178 expect(builder.split(r'foo\..\bar\.\baz'),
179 equals(['foo', '..', 'bar', '.', 'baz']));
180 expect(builder.split(r'foo\\bar\\\baz'), equals(['foo', 'bar', 'baz']));
181 expect(builder.split(r'foo\/\baz'), equals(['foo', 'baz']));
182 expect(builder.split('.'), equals(['.']));
183 expect(builder.split(''), equals([]));
184 expect(builder.split('foo/'), equals(['foo']));
185 expect(builder.split(r'C:\'), equals([r'C:\']));
186 });
187
188 test('includes the root for absolute paths', () {
189 expect(builder.split(r'C:\foo\bar\baz'),
190 equals([r'C:\', 'foo', 'bar', 'baz']));
191 expect(builder.split(r'C:\\'), equals([r'C:\']));
192
193 // TODO(nweiz): enable these once issue 7323 is fixed.
194 // expect(builder.split(r'\\server\foo\bar\baz'),
195 // equals([r'\\server\', 'foo', 'bar', 'baz']));
196 // expect(builder.split(r'\\server\'), equals([r'\\server\']));
197 });
126 }); 198 });
127 199
128 group('normalize', () { 200 group('normalize', () {
129 test('simple cases', () { 201 test('simple cases', () {
130 expect(builder.normalize(''), ''); 202 expect(builder.normalize(''), '');
131 expect(builder.normalize('.'), '.'); 203 expect(builder.normalize('.'), '.');
132 expect(builder.normalize('..'), '..'); 204 expect(builder.normalize('..'), '..');
133 expect(builder.normalize('a'), 'a'); 205 expect(builder.normalize('a'), 'a');
134 expect(builder.normalize('C:/'), r'C:/'); 206 expect(builder.normalize('C:/'), r'C:/');
135 expect(builder.normalize(r'C:\'), r'C:\'); 207 expect(builder.normalize(r'C:\'), r'C:\');
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 expect(builder.relative('a'), 'a'); 290 expect(builder.relative('a'), 'a');
219 expect(builder.relative(r'a\b.txt'), r'a\b.txt'); 291 expect(builder.relative(r'a\b.txt'), r'a\b.txt');
220 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt'); 292 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt');
221 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); 293 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt');
222 }); 294 });
223 }); 295 });
224 296
225 group('from relative root', () { 297 group('from relative root', () {
226 var r = new path.Builder(style: path.Style.windows, root: r'foo\bar'); 298 var r = new path.Builder(style: path.Style.windows, root: r'foo\bar');
227 299
228 // These tests rely on the current working directory, so don't do the 300 test('given absolute path', () {
229 // right thing if you run them on the wrong platform. 301 expect(r.relative(r'C:\'), equals(r'C:\'));
230 if (io.Platform.operatingSystem == 'windows') { 302 expect(r.relative(r'C:\a\b'), equals(r'C:\a\b'));
231 test('given absolute path', () { 303 });
232 var b = new path.Builder(style: path.Style.windows);
233 // TODO(rnystrom): Use a path method here to get the root prefix
234 // when one exists.
235 var drive = path.current.substring(0, 3);
236 expect(r.relative(drive), b.join(b.relative(drive), r'..\..'));
237 expect(r.relative(b.join(drive, r'a\b')),
238 b.join(b.relative(drive), r'..\..\a\b'));
239
240 // TODO(rnystrom): Test behavior when drive letters differ.
241 });
242 }
243 304
244 test('given relative path', () { 305 test('given relative path', () {
245 // The path is considered relative to the root, so it basically just 306 // The path is considered relative to the root, so it basically just
246 // normalizes. 307 // normalizes.
247 expect(r.relative(''), '.'); 308 expect(r.relative(''), '.');
248 expect(r.relative('.'), '.'); 309 expect(r.relative('.'), '.');
249 expect(r.relative('..'), '..'); 310 expect(r.relative('..'), '..');
250 expect(r.relative('a'), 'a'); 311 expect(r.relative('a'), 'a');
251 expect(r.relative(r'a\b.txt'), r'a\b.txt'); 312 expect(r.relative(r'a\b.txt'), r'a\b.txt');
252 expect(r.relative(r'..\a/b.txt'), r'..\a\b.txt'); 313 expect(r.relative(r'..\a/b.txt'), r'..\a\b.txt');
253 expect(r.relative(r'a\./b\../c.txt'), r'a\c.txt'); 314 expect(r.relative(r'a\./b\../c.txt'), r'a\c.txt');
254 }); 315 });
255 }); 316 });
256 317
257 test('from a root with extension', () { 318 test('from a root with extension', () {
258 var r = new path.Builder(style: path.Style.windows, root: r'C:\dir.ext'); 319 var r = new path.Builder(style: path.Style.windows, root: r'C:\dir.ext');
259 expect(r.relative(r'C:\dir.ext\file'), 'file'); 320 expect(r.relative(r'C:\dir.ext\file'), 'file');
260 }); 321 });
261 322
323 test('with a root parameter', () {
324 expect(builder.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'),
325 equals('baz'));
326 expect(builder.relative('..', from: r'C:\foo\bar'),
327 equals(r'..\..\root'));
328 expect(builder.relative('..', from: r'D:\foo\bar'), equals(r'C:\root'));
329 expect(builder.relative(r'C:\foo\bar\baz', from: r'foo\bar'),
330 equals(r'..\..\..\..\foo\bar\baz'));
331 expect(builder.relative('..', from: r'foo\bar'), equals(r'..\..\..'));
332 });
333
334 test('with a root parameter and a relative root', () {
335 var r = new path.Builder(style: path.Style.windows, root: r'relative\root' );
336 expect(r.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'), equals('baz'));
337 expect(() => r.relative('..', from: r'C:\foo\bar'), throwsArgumentError);
338 expect(r.relative(r'C:\foo\bar\baz', from: r'foo\bar'),
339 equals(r'C:\foo\bar\baz'));
340 expect(r.relative('..', from: r'foo\bar'), equals(r'..\..\..'));
341 });
342
262 test('given absolute with different root prefix', () { 343 test('given absolute with different root prefix', () {
263 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); 344 expect(builder.relative(r'D:\a\b'), r'D:\a\b');
264 expect(builder.relative(r'\\a\b'), r'\\a\b'); 345 expect(builder.relative(r'\\a\b'), r'\\a\b');
265 }); 346 });
266 }); 347 });
267 348
268 group('resolve', () { 349 group('resolve', () {
269 test('allows up to seven parts', () { 350 test('allows up to seven parts', () {
270 expect(builder.resolve('a'), r'C:\root\path\a'); 351 expect(builder.resolve('a'), r'C:\root\path\a');
271 expect(builder.resolve('a', 'b'), r'C:\root\path\a\b'); 352 expect(builder.resolve('a', 'b'), r'C:\root\path\a\b');
(...skipping 30 matching lines...) Expand all
302 expect(builder.withoutExtension(r'a\b\'), r'a\b\'); 383 expect(builder.withoutExtension(r'a\b\'), r'a\b\');
303 expect(builder.withoutExtension(r'a\.'), r'a\.'); 384 expect(builder.withoutExtension(r'a\.'), r'a\.');
304 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); 385 expect(builder.withoutExtension(r'a\.b'), r'a\.b');
305 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); 386 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c');
306 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); 387 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d');
307 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); 388 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c');
308 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); 389 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c');
309 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); 390 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c');
310 }); 391 });
311 } 392 }
OLDNEW
« no previous file with comments | « utils/tests/pub/path/path_posix_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698