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 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
6 import 'package:path/path.dart' as path; | 6 import 'package:path/path.dart' as path; |
7 | 7 |
8 main() { | 8 main() { |
9 var builder = new path.Builder(style: path.Style.url, | 9 var builder = new path.Builder(style: path.Style.url, |
10 root: 'http://dartlang.org/root/path'); | 10 root: 'http://dartlang.org/root/path'); |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 test('from a . root', () { | 608 test('from a . root', () { |
609 var r = new path.Builder(style: path.Style.url, root: '.'); | 609 var r = new path.Builder(style: path.Style.url, root: '.'); |
610 expect(r.relative('http://dartlang.org/foo/bar/baz'), | 610 expect(r.relative('http://dartlang.org/foo/bar/baz'), |
611 equals('http://dartlang.org/foo/bar/baz')); | 611 equals('http://dartlang.org/foo/bar/baz')); |
612 expect(r.relative('file:///foo/bar/baz'), equals('file:///foo/bar/baz')); | 612 expect(r.relative('file:///foo/bar/baz'), equals('file:///foo/bar/baz')); |
613 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); | 613 expect(r.relative('/foo/bar/baz'), equals('/foo/bar/baz')); |
614 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); | 614 expect(r.relative('foo/bar/baz'), equals('foo/bar/baz')); |
615 }); | 615 }); |
616 }); | 616 }); |
617 | 617 |
| 618 group('isWithin', () { |
| 619 test('simple cases', () { |
| 620 expect(builder.isWithin('foo/bar', 'foo/bar'), isFalse); |
| 621 expect(builder.isWithin('foo/bar', 'foo/bar/baz'), isTrue); |
| 622 expect(builder.isWithin('foo/bar', 'foo/baz'), isFalse); |
| 623 expect(builder.isWithin('foo/bar', '../path/foo/bar/baz'), isTrue); |
| 624 expect(builder.isWithin( |
| 625 'http://dartlang.org', 'http://dartlang.org/foo/bar'), |
| 626 isTrue); |
| 627 expect(builder.isWithin( |
| 628 'http://dartlang.org', 'http://pub.dartlang.org/foo/bar'), |
| 629 isFalse); |
| 630 expect(builder.isWithin('http://dartlang.org', '/foo/bar'), isTrue); |
| 631 expect(builder.isWithin('http://dartlang.org/foo', '/foo/bar'), isTrue); |
| 632 expect(builder.isWithin('http://dartlang.org/foo', '/bar/baz'), isFalse); |
| 633 expect(builder.isWithin('baz', 'http://dartlang.org/root/path/baz/bang'), |
| 634 isTrue); |
| 635 expect(builder.isWithin('baz', 'http://dartlang.org/root/path/bang/baz'), |
| 636 isFalse); |
| 637 }); |
| 638 |
| 639 test('from a relative root', () { |
| 640 var r = new path.Builder(style: path.Style.url, root: 'foo/bar'); |
| 641 expect(builder.isWithin('.', 'a/b/c'), isTrue); |
| 642 expect(builder.isWithin('.', '../a/b/c'), isFalse); |
| 643 expect(builder.isWithin('.', '../../a/foo/b/c'), isFalse); |
| 644 expect(builder.isWithin( |
| 645 'http://dartlang.org/', 'http://dartlang.org/baz/bang'), |
| 646 isTrue); |
| 647 expect(builder.isWithin('.', 'http://dartlang.org/baz/bang'), isFalse); |
| 648 }); |
| 649 }); |
| 650 |
618 group('resolve', () { | 651 group('resolve', () { |
619 test('allows up to seven parts', () { | 652 test('allows up to seven parts', () { |
620 expect(builder.resolve('a'), 'http://dartlang.org/root/path/a'); | 653 expect(builder.resolve('a'), 'http://dartlang.org/root/path/a'); |
621 expect(builder.resolve('a', 'b'), 'http://dartlang.org/root/path/a/b'); | 654 expect(builder.resolve('a', 'b'), 'http://dartlang.org/root/path/a/b'); |
622 expect(builder.resolve('a', 'b', 'c'), | 655 expect(builder.resolve('a', 'b', 'c'), |
623 'http://dartlang.org/root/path/a/b/c'); | 656 'http://dartlang.org/root/path/a/b/c'); |
624 expect(builder.resolve('a', 'b', 'c', 'd'), | 657 expect(builder.resolve('a', 'b', 'c', 'd'), |
625 'http://dartlang.org/root/path/a/b/c/d'); | 658 'http://dartlang.org/root/path/a/b/c/d'); |
626 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), | 659 expect(builder.resolve('a', 'b', 'c', 'd', 'e'), |
627 'http://dartlang.org/root/path/a/b/c/d/e'); | 660 'http://dartlang.org/root/path/a/b/c/d/e'); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), | 727 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), |
695 Uri.parse('http://dartlang.org/path/to/foo%23bar')); | 728 Uri.parse('http://dartlang.org/path/to/foo%23bar')); |
696 // Since the input path is also a URI, special characters should already | 729 // Since the input path is also a URI, special characters should already |
697 // be percent encoded there too. | 730 // be percent encoded there too. |
698 expect(builder.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), | 731 expect(builder.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), |
699 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); | 732 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); |
700 expect(builder.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), | 733 expect(builder.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), |
701 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); | 734 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); |
702 }); | 735 }); |
703 } | 736 } |
OLD | NEW |