OLD | NEW |
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 pathos_windows_test; | 5 library pathos_windows_test; |
6 | 6 |
7 import 'dart:io' as io; | |
8 | |
9 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
10 import 'package:pathos/path.dart' as path; | 8 import 'package:pathos/path.dart' as path; |
11 | 9 |
12 main() { | 10 main() { |
13 var builder = new path.Builder(style: path.Style.windows, | 11 var builder = new path.Builder(style: path.Style.windows, |
14 root: r'C:\root\path'); | 12 root: r'C:\root\path'); |
15 | 13 |
16 if (new path.Builder().style == path.Style.windows) { | 14 if (new path.Builder().style == path.Style.windows) { |
17 group('absolute', () { | 15 group('absolute', () { |
18 expect(path.absolute(r'a\b.txt'), path.join(path.current, r'a\b.txt')); | 16 expect(path.absolute(r'a\b.txt'), path.join(path.current, r'a\b.txt')); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 test('given relative path', () { | 324 test('given relative path', () { |
327 // The path is considered relative to the root, so it basically just | 325 // The path is considered relative to the root, so it basically just |
328 // normalizes. | 326 // normalizes. |
329 expect(builder.relative(''), '.'); | 327 expect(builder.relative(''), '.'); |
330 expect(builder.relative('.'), '.'); | 328 expect(builder.relative('.'), '.'); |
331 expect(builder.relative('a'), 'a'); | 329 expect(builder.relative('a'), 'a'); |
332 expect(builder.relative(r'a\b.txt'), r'a\b.txt'); | 330 expect(builder.relative(r'a\b.txt'), r'a\b.txt'); |
333 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt'); | 331 expect(builder.relative(r'..\a\b.txt'), r'..\a\b.txt'); |
334 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); | 332 expect(builder.relative(r'a\.\b\..\c.txt'), r'a\c.txt'); |
335 }); | 333 }); |
| 334 |
| 335 // Regression |
| 336 test('from root-only path', () { |
| 337 expect(builder.relative(r'C:\', from: r'C:\'), '.'); |
| 338 expect(builder.relative(r'C:\root\path', from: r'C:\'), r'root\path'); |
| 339 }); |
336 }); | 340 }); |
337 | 341 |
338 group('from relative root', () { | 342 group('from relative root', () { |
339 var r = new path.Builder(style: path.Style.windows, root: r'foo\bar'); | 343 var r = new path.Builder(style: path.Style.windows, root: r'foo\bar'); |
340 | 344 |
341 test('given absolute path', () { | 345 test('given absolute path', () { |
342 expect(r.relative(r'C:\'), equals(r'C:\')); | 346 expect(r.relative(r'C:\'), equals(r'C:\')); |
343 expect(r.relative(r'C:\a\b'), equals(r'C:\a\b')); | 347 expect(r.relative(r'C:\a\b'), equals(r'C:\a\b')); |
344 }); | 348 }); |
345 | 349 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 expect(() => r.relative('..', from: r'C:\foo\bar'), throwsArgumentError); | 382 expect(() => r.relative('..', from: r'C:\foo\bar'), throwsArgumentError); |
379 expect(r.relative(r'C:\foo\bar\baz', from: r'foo\bar'), | 383 expect(r.relative(r'C:\foo\bar\baz', from: r'foo\bar'), |
380 equals(r'C:\foo\bar\baz')); | 384 equals(r'C:\foo\bar\baz')); |
381 expect(r.relative('..', from: r'foo\bar'), equals(r'..\..\..')); | 385 expect(r.relative('..', from: r'foo\bar'), equals(r'..\..\..')); |
382 }); | 386 }); |
383 | 387 |
384 test('given absolute with different root prefix', () { | 388 test('given absolute with different root prefix', () { |
385 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); | 389 expect(builder.relative(r'D:\a\b'), r'D:\a\b'); |
386 expect(builder.relative(r'\\a\b'), r'\\a\b'); | 390 expect(builder.relative(r'\\a\b'), r'\\a\b'); |
387 }); | 391 }); |
| 392 |
| 393 test('from a . root', () { |
| 394 var r = new path.Builder(style: path.Style.windows, root: '.'); |
| 395 expect(r.relative(r'C:\foo\bar\baz'), equals(r'C:\foo\bar\baz')); |
| 396 expect(r.relative(r'foo\bar\baz'), equals(r'foo\bar\baz')); |
| 397 }); |
388 }); | 398 }); |
389 | 399 |
390 group('resolve', () { | 400 group('resolve', () { |
391 test('allows up to seven parts', () { | 401 test('allows up to seven parts', () { |
392 expect(builder.resolve('a'), r'C:\root\path\a'); | 402 expect(builder.resolve('a'), r'C:\root\path\a'); |
393 expect(builder.resolve('a', 'b'), r'C:\root\path\a\b'); | 403 expect(builder.resolve('a', 'b'), r'C:\root\path\a\b'); |
394 expect(builder.resolve('a', 'b', 'c'), r'C:\root\path\a\b\c'); | 404 expect(builder.resolve('a', 'b', 'c'), r'C:\root\path\a\b\c'); |
395 expect(builder.resolve('a', 'b', 'c', 'd'), r'C:\root\path\a\b\c\d'); | 405 expect(builder.resolve('a', 'b', 'c', 'd'), r'C:\root\path\a\b\c\d'); |
396 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), | 406 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), |
397 r'C:\root\path\a\b\c\d\e'); | 407 r'C:\root\path\a\b\c\d\e'); |
(...skipping 27 matching lines...) Expand all Loading... |
425 expect(builder.withoutExtension(r'a\.'), r'a\.'); | 435 expect(builder.withoutExtension(r'a\.'), r'a\.'); |
426 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); | 436 expect(builder.withoutExtension(r'a\.b'), r'a\.b'); |
427 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); | 437 expect(builder.withoutExtension(r'a.b\c'), r'a.b\c'); |
428 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); | 438 expect(builder.withoutExtension(r'a/b.c/d'), r'a/b.c/d'); |
429 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); | 439 expect(builder.withoutExtension(r'a\b/c'), r'a\b/c'); |
430 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); | 440 expect(builder.withoutExtension(r'a\b/c.d'), r'a\b/c'); |
431 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); | 441 expect(builder.withoutExtension(r'a.b/c'), r'a.b/c'); |
432 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\'); | 442 expect(builder.withoutExtension(r'a\b.c\'), r'a\b\'); |
433 }); | 443 }); |
434 } | 444 } |
OLD | NEW |