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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 expect(builder.withoutExtension('a/.'), 'a/.'); | 658 expect(builder.withoutExtension('a/.'), 'a/.'); |
659 expect(builder.withoutExtension('a/.b'), 'a/.b'); | 659 expect(builder.withoutExtension('a/.b'), 'a/.b'); |
660 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); | 660 expect(builder.withoutExtension('a.b/c'), 'a.b/c'); |
661 expect(builder.withoutExtension(r'a.b\c'), r'a'); | 661 expect(builder.withoutExtension(r'a.b\c'), r'a'); |
662 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); | 662 expect(builder.withoutExtension(r'a/b\c'), r'a/b\c'); |
663 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); | 663 expect(builder.withoutExtension(r'a/b\c.d'), r'a/b\c'); |
664 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); | 664 expect(builder.withoutExtension('a/b.c/'), 'a/b/'); |
665 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); | 665 expect(builder.withoutExtension('a/b.c//'), 'a/b//'); |
666 }); | 666 }); |
667 | 667 |
668 | |
669 test('fromUri', () { | 668 test('fromUri', () { |
670 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo')), | 669 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo')), |
671 'http://dartlang.org/path/to/foo'); | 670 'http://dartlang.org/path/to/foo'); |
672 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo/')), | 671 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo/')), |
673 'http://dartlang.org/path/to/foo/'); | 672 'http://dartlang.org/path/to/foo/'); |
674 expect(builder.fromUri(Uri.parse('file:///path/to/foo')), | 673 expect(builder.fromUri(Uri.parse('file:///path/to/foo')), |
675 'file:///path/to/foo'); | 674 'file:///path/to/foo'); |
676 expect(builder.fromUri(Uri.parse('foo/bar')), 'foo/bar'); | 675 expect(builder.fromUri(Uri.parse('foo/bar')), 'foo/bar'); |
677 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo%23bar')), | 676 expect(builder.fromUri(Uri.parse('http://dartlang.org/path/to/foo%23bar')), |
678 'http://dartlang.org/path/to/foo%23bar'); | 677 'http://dartlang.org/path/to/foo%23bar'); |
| 678 // Since the resulting "path" is also a URL, special characters should |
| 679 // remain percent-encoded in the result. |
| 680 expect(builder.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')), |
| 681 r'_%7B_%7D_%60_%5E_%20_%22_%25_'); |
679 }); | 682 }); |
680 | 683 |
681 test('toUri', () { | 684 test('toUri', () { |
682 expect(builder.toUri('http://dartlang.org/path/to/foo'), | 685 expect(builder.toUri('http://dartlang.org/path/to/foo'), |
683 Uri.parse('http://dartlang.org/path/to/foo')); | 686 Uri.parse('http://dartlang.org/path/to/foo')); |
684 expect(builder.toUri('http://dartlang.org/path/to/foo/'), | 687 expect(builder.toUri('http://dartlang.org/path/to/foo/'), |
685 Uri.parse('http://dartlang.org/path/to/foo/')); | 688 Uri.parse('http://dartlang.org/path/to/foo/')); |
686 expect(builder.toUri('file:///path/to/foo'), | 689 expect(builder.toUri('file:///path/to/foo'), |
687 Uri.parse('file:///path/to/foo')); | 690 Uri.parse('file:///path/to/foo')); |
688 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); | 691 expect(builder.toUri('foo/bar'), Uri.parse('foo/bar')); |
689 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), | 692 expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'), |
690 Uri.parse('http://dartlang.org/path/to/foo%23bar')); | 693 Uri.parse('http://dartlang.org/path/to/foo%23bar')); |
| 694 // Since the input path is also a URI, special characters should already |
| 695 // be percent encoded there too. |
| 696 expect(builder.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), |
| 697 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); |
| 698 expect(builder.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), |
| 699 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); |
691 }); | 700 }); |
692 } | 701 } |
OLD | NEW |