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:test/test.dart'; | 5 import 'package:test/test.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 context = new path.Context( | 9 var context = new path.Context( |
10 style: path.Style.url, current: 'http://dartlang.org/root/path'); | 10 style: path.Style.url, current: 'http://dartlang.org/root/path'); |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 'http://dartlang.org', 'http://pub.dartlang.org/foo/bar'), isFalse); | 622 'http://dartlang.org', 'http://pub.dartlang.org/foo/bar'), isFalse); |
623 expect(context.isWithin('http://dartlang.org', '/foo/bar'), isTrue); | 623 expect(context.isWithin('http://dartlang.org', '/foo/bar'), isTrue); |
624 expect(context.isWithin('http://dartlang.org/foo', '/foo/bar'), isTrue); | 624 expect(context.isWithin('http://dartlang.org/foo', '/foo/bar'), isTrue); |
625 expect(context.isWithin('http://dartlang.org/foo', '/bar/baz'), isFalse); | 625 expect(context.isWithin('http://dartlang.org/foo', '/bar/baz'), isFalse); |
626 expect(context.isWithin('baz', 'http://dartlang.org/root/path/baz/bang'), | 626 expect(context.isWithin('baz', 'http://dartlang.org/root/path/baz/bang'), |
627 isTrue); | 627 isTrue); |
628 expect(context.isWithin('baz', 'http://dartlang.org/root/path/bang/baz'), | 628 expect(context.isWithin('baz', 'http://dartlang.org/root/path/bang/baz'), |
629 isFalse); | 629 isFalse); |
630 }); | 630 }); |
631 | 631 |
| 632 test('complex cases', () { |
| 633 expect(context.isWithin('foo/./bar', 'foo/bar/baz'), isTrue); |
| 634 expect(context.isWithin('foo//bar', 'foo/bar/baz'), isTrue); |
| 635 expect(context.isWithin('foo/qux/../bar', 'foo/bar/baz'), isTrue); |
| 636 expect(context.isWithin('foo/bar', 'foo/bar/baz/../..'), isFalse); |
| 637 expect(context.isWithin('foo/bar', 'foo/bar///'), isFalse); |
| 638 expect(context.isWithin('foo/.bar', 'foo/.bar/baz'), isTrue); |
| 639 expect(context.isWithin('foo/./bar', 'foo/.bar/baz'), isFalse); |
| 640 expect(context.isWithin('foo/..bar', 'foo/..bar/baz'), isTrue); |
| 641 expect(context.isWithin('http://example.org/', 'http://example.com/foo'), |
| 642 isFalse); |
| 643 expect(context.isWithin('http://example.org/', 'http://dartlang.org/foo'), |
| 644 isFalse); |
| 645 }); |
| 646 |
| 647 test('with root-relative paths', () { |
| 648 expect(context.isWithin('/foo', 'http://dartlang.org/foo/bar'), isTrue); |
| 649 expect(context.isWithin('http://dartlang.org/foo', '/foo/bar'), isTrue); |
| 650 expect(context.isWithin('/root', 'foo/bar'), isTrue); |
| 651 expect(context.isWithin('foo', '/root/path/foo/bar'), isTrue); |
| 652 expect(context.isWithin('/foo', '/foo/bar'), isTrue); |
| 653 }); |
| 654 |
632 test('from a relative root', () { | 655 test('from a relative root', () { |
633 var r = new path.Context(style: path.Style.url, current: 'foo/bar'); | 656 var r = new path.Context(style: path.Style.url, current: 'foo/bar'); |
634 expect(r.isWithin('.', 'a/b/c'), isTrue); | 657 expect(r.isWithin('.', 'a/b/c'), isTrue); |
635 expect(r.isWithin('.', '../a/b/c'), isFalse); | 658 expect(r.isWithin('.', '../a/b/c'), isFalse); |
636 expect(r.isWithin('.', '../../a/foo/b/c'), isFalse); | 659 expect(r.isWithin('.', '../../a/foo/b/c'), isFalse); |
637 expect(r.isWithin('http://dartlang.org/', 'http://dartlang.org/baz/bang'), | 660 expect(r.isWithin('http://dartlang.org/', 'http://dartlang.org/baz/bang'), |
638 isTrue); | 661 isTrue); |
639 expect(r.isWithin('.', 'http://dartlang.org/baz/bang'), isFalse); | 662 expect(r.isWithin('.', 'http://dartlang.org/baz/bang'), isFalse); |
640 }); | 663 }); |
641 }); | 664 }); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 780 |
758 test('with a root-relative URI', () { | 781 test('with a root-relative URI', () { |
759 expect(context.prettyUri('/a/b'), '/a/b'); | 782 expect(context.prettyUri('/a/b'), '/a/b'); |
760 }); | 783 }); |
761 | 784 |
762 test('with a Uri object', () { | 785 test('with a Uri object', () { |
763 expect(context.prettyUri(Uri.parse('a/b')), 'a/b'); | 786 expect(context.prettyUri(Uri.parse('a/b')), 'a/b'); |
764 }); | 787 }); |
765 }); | 788 }); |
766 } | 789 } |
OLD | NEW |