Index: pkg/path/test/posix_test.dart |
diff --git a/pkg/path/test/posix_test.dart b/pkg/path/test/posix_test.dart |
index c26a5ba8969b15ac5d9b084b4da93d952e12b2f4..714e14cf428ed744e839d6b76342ded3a47c77f9 100644 |
--- a/pkg/path/test/posix_test.dart |
+++ b/pkg/path/test/posix_test.dart |
@@ -165,6 +165,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/'); |
Bob Nystrom
2013/07/18 20:45:08
How about making a "preserves trailing separators"
Bill Hesse
2013/07/22 11:35:22
Done.
|
+ expect(builder.join('a/b/./c/..//', 'd/.././..//e/f//'), |
+ 'a/b/./c/..//d/.././..//e/f//'); |
+ expect(builder.join('a/b', 'c/../../../..'), 'a/b/c/../../../..'); |
Bob Nystrom
2013/07/18 20:45:08
This is a good test. Might be nice to have somethi
Bill Hesse
2013/07/22 11:35:22
Done.
|
+ expect(builder.join('', ''), ''); |
Bob Nystrom
2013/07/18 20:45:08
This is covered by line 158.
Bill Hesse
2013/07/22 11:35:22
Done.
|
+ expect(builder.join('a/b/c/', '/d'), '/d'); |
Bob Nystrom
2013/07/18 20:45:08
This is covered by line 140.
Bill Hesse
2013/07/22 11:35:22
Done.
|
+ expect(builder.join('a', 'b${builder.separator}'), 'a/b/'); |
Bob Nystrom
2013/07/18 20:45:08
You can just do "/" instead of ${builder.separator
Bill Hesse
2013/07/22 11:35:22
We already have a test for literal / at the end.
S
Bob Nystrom
2013/07/22 20:53:11
We already test what builder.separator returns, so
Bill Hesse
2013/07/23 16:07:00
Removed - I'm used to writing VM tests, where more
|
+ }); |
}); |
group('joinAll', () { |
@@ -212,12 +222,15 @@ main() { |
group('normalize', () { |
test('simple cases', () { |
- expect(builder.normalize(''), ''); |
+ expect(builder.normalize(''), '.'); |
expect(builder.normalize('.'), '.'); |
expect(builder.normalize('..'), '..'); |
expect(builder.normalize('a'), 'a'); |
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'\\'); |
Bob Nystrom
2013/07/18 20:45:08
Yay tests!
|
}); |
test('collapses redundant separators', () { |
@@ -249,24 +262,38 @@ main() { |
expect(builder.normalize('/..'), '/'); |
expect(builder.normalize('/../../..'), '/'); |
expect(builder.normalize('/../../../a'), '/a'); |
+ expect(builder.normalize('c:/..'), '.'); |
+ expect(builder.normalize('A:/../../..'), '../..'); |
Bob Nystrom
2013/07/18 20:45:08
Nice.
|
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(r'z/a/b/../../..\../c'), r'z/..\../c'); |
+ expect(builder.normalize(r'a/b\c/../d'), 'a/d'); |
}); |
test('does not walk before root on absolute paths', () { |
expect(builder.normalize('..'), '..'); |
expect(builder.normalize('../'), '..'); |
+ expect(builder.normalize('http://dartlang.org/..'), 'http:'); |
+ expect(builder.normalize('http://dartlang.org/../../a'), 'a'); |
+ expect(builder.normalize('file:///..'), '.'); |
+ expect(builder.normalize('file:///../../a'), '../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', () { |
@@ -274,6 +301,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'); |
}); |
}); |
@@ -429,4 +457,100 @@ main() { |
expect(builder.toUri('/path/to/foo#bar'), |
Uri.parse('file:///path/to/foo%23bar')); |
}); |
+ |
+ void testGetters(String p, List components, String properties) { |
Bob Nystrom
2013/07/18 20:45:08
Do you think it's worth adding these? I find them
Bill Hesse
2013/07/22 11:35:22
Removed. Some tests, like for '.', '..', and 'gul
|
+ 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'); |
+ }); |
} |