Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: pkg/path/test/url_test.dart

Issue 203673003: Allow [path.fromUri] to take a string as well as a URI. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 expect(context.withoutExtension('a/.'), 'a/.'); 693 expect(context.withoutExtension('a/.'), 'a/.');
694 expect(context.withoutExtension('a/.b'), 'a/.b'); 694 expect(context.withoutExtension('a/.b'), 'a/.b');
695 expect(context.withoutExtension('a.b/c'), 'a.b/c'); 695 expect(context.withoutExtension('a.b/c'), 'a.b/c');
696 expect(context.withoutExtension(r'a.b\c'), r'a'); 696 expect(context.withoutExtension(r'a.b\c'), r'a');
697 expect(context.withoutExtension(r'a/b\c'), r'a/b\c'); 697 expect(context.withoutExtension(r'a/b\c'), r'a/b\c');
698 expect(context.withoutExtension(r'a/b\c.d'), r'a/b\c'); 698 expect(context.withoutExtension(r'a/b\c.d'), r'a/b\c');
699 expect(context.withoutExtension('a/b.c/'), 'a/b/'); 699 expect(context.withoutExtension('a/b.c/'), 'a/b/');
700 expect(context.withoutExtension('a/b.c//'), 'a/b//'); 700 expect(context.withoutExtension('a/b.c//'), 'a/b//');
701 }); 701 });
702 702
703 test('fromUri', () { 703 group('fromUri', () {
704 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo')), 704 test('with a URI', () {
705 'http://dartlang.org/path/to/foo'); 705 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo')),
706 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo/')), 706 'http://dartlang.org/path/to/foo');
707 'http://dartlang.org/path/to/foo/'); 707 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo/')),
708 expect(context.fromUri(Uri.parse('file:///path/to/foo')), 708 'http://dartlang.org/path/to/foo/');
709 'file:///path/to/foo'); 709 expect(context.fromUri(Uri.parse('file:///path/to/foo')),
710 expect(context.fromUri(Uri.parse('foo/bar')), 'foo/bar'); 710 'file:///path/to/foo');
711 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo%23bar')), 711 expect(context.fromUri(Uri.parse('foo/bar')), 'foo/bar');
712 'http://dartlang.org/path/to/foo%23bar'); 712 expect(context.fromUri(Uri.parse('http://dartlang.org/path/to/foo%23bar')) ,
Bob Nystrom 2014/03/18 20:31:09 Long line.
nweiz 2014/03/18 22:02:19 Done.
713 // Since the resulting "path" is also a URL, special characters should 713 'http://dartlang.org/path/to/foo%23bar');
714 // remain percent-encoded in the result. 714 // Since the resulting "path" is also a URL, special characters should
715 expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')), 715 // remain percent-encoded in the result.
716 r'_%7B_%7D_%60_%5E_%20_%22_%25_'); 716 expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')),
717 r'_%7B_%7D_%60_%5E_%20_%22_%25_');
718 });
719
720 test('with a string', () {
721 expect(context.fromUri('http://dartlang.org/path/to/foo'),
722 'http://dartlang.org/path/to/foo');
723 });
717 }); 724 });
718 725
719 test('toUri', () { 726 test('toUri', () {
720 expect(context.toUri('http://dartlang.org/path/to/foo'), 727 expect(context.toUri('http://dartlang.org/path/to/foo'),
721 Uri.parse('http://dartlang.org/path/to/foo')); 728 Uri.parse('http://dartlang.org/path/to/foo'));
722 expect(context.toUri('http://dartlang.org/path/to/foo/'), 729 expect(context.toUri('http://dartlang.org/path/to/foo/'),
723 Uri.parse('http://dartlang.org/path/to/foo/')); 730 Uri.parse('http://dartlang.org/path/to/foo/'));
724 expect(context.toUri('file:///path/to/foo'), 731 expect(context.toUri('file:///path/to/foo'),
725 Uri.parse('file:///path/to/foo')); 732 Uri.parse('file:///path/to/foo'));
726 expect(context.toUri('foo/bar'), Uri.parse('foo/bar')); 733 expect(context.toUri('foo/bar'), Uri.parse('foo/bar'));
727 expect(context.toUri('http://dartlang.org/path/to/foo%23bar'), 734 expect(context.toUri('http://dartlang.org/path/to/foo%23bar'),
728 Uri.parse('http://dartlang.org/path/to/foo%23bar')); 735 Uri.parse('http://dartlang.org/path/to/foo%23bar'));
729 // Since the input path is also a URI, special characters should already 736 // Since the input path is also a URI, special characters should already
730 // be percent encoded there too. 737 // be percent encoded there too.
731 expect(context.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'), 738 expect(context.toUri(r'http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'),
732 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_')); 739 Uri.parse('http://foo.com/_%7B_%7D_%60_%5E_%20_%22_%25_'));
733 expect(context.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'), 740 expect(context.toUri(r'_%7B_%7D_%60_%5E_%20_%22_%25_'),
734 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')); 741 Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_'));
735 }); 742 });
736 } 743 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698