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 context = new path.Context(style: path.Style.url, | 9 var context = new path.Context(style: path.Style.url, |
10 current: 'http://dartlang.org/root/path'); | 10 current: 'http://dartlang.org/root/path'); |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 expect(context.toUri('foo/bar'), Uri.parse('foo/bar')); | 734 expect(context.toUri('foo/bar'), Uri.parse('foo/bar')); |
735 expect(context.toUri('http://dartlang.org/path/to/foo%23bar'), | 735 expect(context.toUri('http://dartlang.org/path/to/foo%23bar'), |
736 Uri.parse('http://dartlang.org/path/to/foo%23bar')); | 736 Uri.parse('http://dartlang.org/path/to/foo%23bar')); |
737 // Since the input path is also a URI, special characters should already | 737 // Since the input path is also a URI, special characters should already |
738 // be percent encoded there too. | 738 // be percent encoded there too. |
739 expect(context.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), | 739 expect(context.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), |
740 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); | 740 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); |
741 expect(context.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), | 741 expect(context.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), |
742 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); | 742 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); |
743 }); | 743 }); |
| 744 |
| 745 group('prettyUri', () { |
| 746 test('with a file: URI', () { |
| 747 expect(context.prettyUri(Uri.parse('file:///root/path/a/b')), |
| 748 'file:///root/path/a/b'); |
| 749 }); |
| 750 |
| 751 test('with an http: URI', () { |
| 752 expect(context.prettyUri('http://dartlang.org/root/path/a/b'), 'a/b'); |
| 753 expect(context.prettyUri('http://dartlang.org/root/path/a/../b'), 'b'); |
| 754 expect(context.prettyUri('http://dartlang.org/other/path/a/b'), |
| 755 'http://dartlang.org/other/path/a/b'); |
| 756 expect(context.prettyUri('http://pub.dartlang.org/root/path'), |
| 757 'http://pub.dartlang.org/root/path'); |
| 758 expect(context.prettyUri('http://dartlang.org/root/other'), |
| 759 '../other'); |
| 760 }); |
| 761 |
| 762 test('with a relative URI', () { |
| 763 expect(context.prettyUri('a/b'), 'a/b'); |
| 764 }); |
| 765 |
| 766 test('with a root-relative URI', () { |
| 767 expect(context.prettyUri('/a/b'), '/a/b'); |
| 768 }); |
| 769 |
| 770 test('with a Uri object', () { |
| 771 expect(context.prettyUri(Uri.parse('a/b')), 'a/b'); |
| 772 }); |
| 773 }); |
744 } | 774 } |
OLD | NEW |