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

Unified Diff: pkg/path/test/url_test.dart

Issue 19231002: Port dart:io Path tests to package:path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix Windows failures Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: pkg/path/test/url_test.dart
diff --git a/pkg/path/test/url_test.dart b/pkg/path/test/url_test.dart
index d040a59840c5cca1ad924704981308a4687c0cf5..9cf10648f136f1b4306e29522c76a2799d9b8961 100644
--- a/pkg/path/test/url_test.dart
+++ b/pkg/path/test/url_test.dart
@@ -235,6 +235,16 @@ main() {
expect(() => builder.join('a', null, 'b'), throwsArgumentError);
expect(() => builder.join(null, 'a'), throwsArgumentError);
});
+
+ test('misc join tests ported from Path class', () {
+ expect(builder.join('a/', 'b/c/'), 'a/b/c/');
+ expect(builder.join('a/b/./c/..//', 'd/.././..//e/f//'),
+ 'a/b/./c/..//d/.././..//e/f//');
+ expect(builder.join('a/b', 'c/../../../..'), 'a/b/c/../../../..');
+ expect(builder.join('', ''), '');
+ expect(builder.join('a/b/c/', '/d'), '/d');
+ expect(builder.join('a', 'b${builder.separator}'), 'a/b/');
+ });
});
group('joinAll', () {
@@ -305,7 +315,7 @@ main() {
group('normalize', () {
test('simple cases', () {
- expect(builder.normalize(''), '');
+ expect(builder.normalize(''), '.');
expect(builder.normalize('.'), '.');
expect(builder.normalize('..'), '..');
expect(builder.normalize('a'), 'a');
@@ -315,6 +325,9 @@ main() {
expect(builder.normalize('file:///'), 'file://');
expect(builder.normalize('/'), '/');
expect(builder.normalize(r'\'), r'\');
+ expect(builder.normalize('C:/'), 'C:');
+ expect(builder.normalize(r'C:\'), r'C:\');
+ expect(builder.normalize(r'\\'), r'\\');
});
test('collapses redundant separators', () {
@@ -360,12 +373,16 @@ main() {
'http://dartlang.org/a');
expect(builder.normalize('file:///../../../a'), 'file:///a');
expect(builder.normalize('/../../../a'), '/a');
+ expect(builder.normalize('c:/..'), '.');
+ expect(builder.normalize('A:/../../..'), '../..');
expect(builder.normalize('a/..'), '.');
expect(builder.normalize('a/b/..'), 'a');
expect(builder.normalize('a/../b'), 'b');
expect(builder.normalize('a/./../b'), 'b');
expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d');
expect(builder.normalize('a/b/../../../../c'), '../../c');
+ expect(builder.normalize('z/a/b/../../..\../c'), 'z/..\../c');
+ expect(builder.normalize('a/b\c/../d'), 'a/d');
});
test('does not walk before root on absolute paths', () {
@@ -373,14 +390,23 @@ main() {
expect(builder.normalize('../'), '..');
expect(builder.normalize('http://dartlang.org/..'),
'http://dartlang.org');
+ expect(builder.normalize('http://dartlang.org/../a'),
+ 'http://dartlang.org/a');
expect(builder.normalize('file:///..'), 'file://');
+ expect(builder.normalize('file:///../a'), 'file:///a');
expect(builder.normalize('/..'), '/');
expect(builder.normalize('a/..'), '.');
+ expect(builder.normalize('../a'), '../a');
+ expect(builder.normalize('/../a'), '/a');
+ expect(builder.normalize('c:/../a'), 'a');
+ expect(builder.normalize('/../a'), '/a');
expect(builder.normalize('a/b/..'), 'a');
+ expect(builder.normalize('../a/b/..'), '../a');
expect(builder.normalize('a/../b'), 'b');
expect(builder.normalize('a/./../b'), 'b');
expect(builder.normalize('a/b/c/../../d/e/..'), 'a/d');
expect(builder.normalize('a/b/../../../../c'), '../../c');
+ expect(builder.normalize('a/b/c/../../..d/./.e/f././'), 'a/..d/.e/f.');
});
test('removes trailing separators', () {
@@ -388,6 +414,7 @@ main() {
expect(builder.normalize('.//'), '.');
expect(builder.normalize('a/'), 'a');
expect(builder.normalize('a/b/'), 'a/b');
+ expect(builder.normalize(r'a/b\'), r'a/b\');
expect(builder.normalize('a/b///'), 'a/b');
});
});
@@ -658,4 +685,101 @@ main() {
expect(builder.toUri('http://dartlang.org/path/to/foo%23bar'),
Uri.parse('http://dartlang.org/path/to/foo%23bar'));
});
+
+
+ void testGetters(String p, List components, String properties) {
+ final int DIRNAME = 0;
+ final int FILENAME = 1;
+ final int FILENAME_NO_EXTENSION = 2;
+ final int WITHOUT_EXTENSION = 3;
+ final int EXTENSION = 4;
+ final int ROOT_PREFIX = 5;
+ expect(components[DIRNAME], builder.dirname(p));
+ expect(components[FILENAME], builder.basename(p));
+ expect(components[FILENAME_NO_EXTENSION],
+ builder.basenameWithoutExtension(p));
+ expect(components[WITHOUT_EXTENSION],
+ builder.withoutExtension(p));
+ expect(components[EXTENSION], builder.extension(p));
+ expect(builder.isAbsolute(p), properties.contains('absolute'));
+ expect(components[ROOT_PREFIX], builder.rootPrefix(p));
+ if (properties.contains('normalized')) {
+ expect(p, builder.normalize(p));
+ } else {
+ expect(p, isNot(equals(builder.normalize(p))));
+ }
+ }
+
+ test('getters', () {
+ testGetters("/foo/bar/fisk.hest",
+ ['/foo/bar', 'fisk.hest', 'fisk', '/foo/bar/fisk',
+ '.hest', '/'],
+ 'absolute normalized');
+ testGetters('',
+ ['.', '', '', '', '', ''],
+ ''); // Issue with normalize('') == '.' change.
+ // This corner case leaves a trailing slash for the root.
+ testGetters('/',
+ ['/', '/', '/', '/', '', '/'],
+ 'absolute normalized');
+ testGetters('.',
+ ['.', '.', '.', '.', '', ''],
+ 'normalized');
+ testGetters('..',
+ ['.', '..', '..', '..', '', ''],
+ 'normalized');
+ testGetters('/ab,;- .c.d',
+ ['/', 'ab,;- .c.d', 'ab,;- .c', '/ab,;- .c', '.d', '/'],
+ 'absolute normalized');
+
+ // Normalized and non-normalized cases
+ testGetters("a/b/../c/./d/e",
+ ['a/b/../c/./d', 'e', 'e', 'a/b/../c/./d/e', '', ''],
+ '');
+ testGetters("a./b../..c/.d/e",
+ ['a./b../..c/.d', 'e', 'e', 'a./b../..c/.d/e', '', ''],
+ 'normalized');
+ testGetters("a/b/",
+ ['a', 'b', 'b', 'a/b/', '', ''],
+ '');
+ // .. is allowed at the beginning of a normalized relative path.
+ testGetters("../../a/b/c/d",
+ ['../../a/b/c', 'd', 'd', '../../a/b/c/d', '', ''],
+ 'normalized');
+
+ // '.' at the end of a path is not considered an extension.
+ testGetters("a/b.c/.",
+ ['a/b.c', '.', '.', 'a/b.c/.', '', ''],
+ '');
+ // '..' at the end of a path is not considered an extension.
+ testGetters("a/bc/../..",
+ ['a/bc/..', '..', '..', 'a/bc/../..', '', ''],
+ '');
+ // '.foo' at the end of a path is not considered an extension.
+ testGetters("a/bc/../.foo",
+ ['a/bc/..', '.foo', '.foo', 'a/bc/../.foo', '', ''],
+ '');
+ // '.foo.bar' at the end of a path is has extension '.bar'.
+ testGetters("a/bc/../.foo.bar",
+ ['a/bc/..', '.foo.bar', '.foo', 'a/bc/../.foo', '.bar', ''],
+ '');
+
+ // Make sure that backslashes are uninterpreted on other platforms.
+ testGetters(r"c:\foo\bar\fisk.hest",
+ ['.', r'c:\foo\bar\fisk.hest', r'c:\foo\bar\fisk',
+ r'c:\foo\bar\fisk', '.hest', ''],
+ 'normalized');
+ testGetters(r"/foo\bar/bif/fisk.hest",
+ [r'/foo\bar/bif', 'fisk.hest', 'fisk', r'/foo\bar/bif/fisk',
+ '.hest', '/'],
+ 'absolute normalized');
+ testGetters(r"//foo\bar///bif////fisk.hest",
+ [r'//foo\bar///bif', 'fisk.hest', 'fisk',
+ r'//foo\bar///bif////fisk', '.hest', '/'],
+ 'absolute');
+ testGetters(r"/foo\ bar/bif/gule\ fisk.hest",
+ [r'/foo\ bar/bif', r'gule\ fisk.hest', r'gule\ fisk',
+ r'/foo\ bar/bif/gule\ fisk', '.hest', '/'],
+ 'absolute normalized');
+ });
}

Powered by Google App Engine
This is Rietveld 408576698