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 import 'dart:io' as io; | |
6 | |
7 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
8 import 'package:pathos/path.dart' as path; | 6 import 'package:pathos/path.dart' as path; |
9 | 7 |
10 main() { | 8 main() { |
11 var builder = new path.Builder(style: path.Style.url, | 9 var builder = new path.Builder(style: path.Style.url, |
12 root: 'http://dartlang.org/root/path'); | 10 root: 'http://dartlang.org/root/path'); |
13 | 11 |
14 test('separator', () { | 12 test('separator', () { |
15 expect(builder.separator, '/'); | 13 expect(builder.separator, '/'); |
16 }); | 14 }); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 test('given relative path', () { | 427 test('given relative path', () { |
430 // The path is considered relative to the root, so it basically just | 428 // The path is considered relative to the root, so it basically just |
431 // normalizes. | 429 // normalizes. |
432 expect(builder.relative(''), '.'); | 430 expect(builder.relative(''), '.'); |
433 expect(builder.relative('.'), '.'); | 431 expect(builder.relative('.'), '.'); |
434 expect(builder.relative('a'), 'a'); | 432 expect(builder.relative('a'), 'a'); |
435 expect(builder.relative('a/b.txt'), 'a/b.txt'); | 433 expect(builder.relative('a/b.txt'), 'a/b.txt'); |
436 expect(builder.relative('../a/b.txt'), '../a/b.txt'); | 434 expect(builder.relative('../a/b.txt'), '../a/b.txt'); |
437 expect(builder.relative('a/./b/../c.txt'), 'a/c.txt'); | 435 expect(builder.relative('a/./b/../c.txt'), 'a/c.txt'); |
438 }); | 436 }); |
| 437 |
| 438 // Regression |
| 439 test('from root-only path', () { |
| 440 expect(builder.relative('http://dartlang.org', |
| 441 from: 'http://dartlang.org'), |
| 442 '.'); |
| 443 expect(builder.relative('http://dartlang.org/root/path', |
| 444 from: 'http://dartlang.org'), |
| 445 'root/path'); |
| 446 }); |
439 }); | 447 }); |
440 | 448 |
441 group('from relative root', () { | 449 group('from relative root', () { |
442 var r = new path.Builder(style: path.Style.url, root: 'foo/bar'); | 450 var r = new path.Builder(style: path.Style.url, root: 'foo/bar'); |
443 | 451 |
444 test('given absolute path', () { | 452 test('given absolute path', () { |
445 expect(r.relative('http://google.com/'), equals('http://google.com')); | 453 expect(r.relative('http://google.com/'), equals('http://google.com')); |
446 expect(r.relative('http://google.com'), equals('http://google.com')); | 454 expect(r.relative('http://google.com'), equals('http://google.com')); |
447 expect(r.relative('file:///'), equals('file://')); | 455 expect(r.relative('file:///'), equals('file://')); |
448 expect(r.relative('file://'), equals('file://')); | 456 expect(r.relative('file://'), equals('file://')); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 556 |
549 expect(r.relative('http://dartlang.org/foo/bar/baz', from: 'foo/bar'), | 557 expect(r.relative('http://dartlang.org/foo/bar/baz', from: 'foo/bar'), |
550 equals('http://dartlang.org/foo/bar/baz')); | 558 equals('http://dartlang.org/foo/bar/baz')); |
551 expect(r.relative('file:///foo/bar/baz', from: 'foo/bar'), | 559 expect(r.relative('file:///foo/bar/baz', from: 'foo/bar'), |
552 equals('file:///foo/bar/baz')); | 560 equals('file:///foo/bar/baz')); |
553 expect(r.relative('/foo/bar/baz', from: 'foo/bar'), | 561 expect(r.relative('/foo/bar/baz', from: 'foo/bar'), |
554 equals('/foo/bar/baz')); | 562 equals('/foo/bar/baz')); |
555 | 563 |
556 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); | 564 expect(r.relative('..', from: 'foo/bar'), equals('../../..')); |
557 }); | 565 }); |
| 566 |
| 567 test('from a . root', () { |
| 568 var r = new path.Builder(style: path.Style.url, root: '.'); |
| 569 expect(r.relative('http://dartlang.org/foo/bar/baz'), |
| 570 equals('http://dartlang.org/foo/bar/baz')); |
| 571 expect(r.relative('file:///foo/bar/baz'), equals('file:///foo/bar/baz')); |
| 572 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); |
| 573 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); |
| 574 }); |
558 }); | 575 }); |
559 | 576 |
560 group('resolve', () { | 577 group('resolve', () { |
561 test('allows up to seven parts', () { | 578 test('allows up to seven parts', () { |
562 expect(builder.resolve('a'), 'http://dartlang.org/root/path/a'); | 579 expect(builder.resolve('a'), 'http://dartlang.org/root/path/a'); |
563 expect(builder.resolve('a', 'b'), 'http://dartlang.org/root/path/a/b'); | 580 expect(builder.resolve('a', 'b'), 'http://dartlang.org/root/path/a/b'); |
564 expect(builder.resolve('a', 'b', 'c'), | 581 expect(builder.resolve('a', 'b', 'c'), |
565 'http://dartlang.org/root/path/a/b/c'); | 582 'http://dartlang.org/root/path/a/b/c'); |
566 expect(builder.resolve('a', 'b', 'c', 'd'), | 583 expect(builder.resolve('a', 'b', 'c', 'd'), |
567 'http://dartlang.org/root/path/a/b/c/d'); | 584 'http://dartlang.org/root/path/a/b/c/d'); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 expect(builder.withoutExtension('a/.'), 'a/.'); | 619 expect(builder.withoutExtension('a/.'), 'a/.'); |
603 expect(builder.withoutExtension('a/.b'), 'a/.b'); | 620 expect(builder.withoutExtension('a/.b'), 'a/.b'); |
604 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); | 621 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); |
605 expect(builder.withoutExtension(r'a.b\c'), r'a'); | 622 expect(builder.withoutExtension(r'a.b\c'), r'a'); |
606 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); | 623 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); |
607 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); | 624 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); |
608 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); | 625 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); |
609 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); | 626 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); |
610 }); | 627 }); |
611 } | 628 } |
OLD | NEW |