Chromium Code Reviews| Index: tests/standalone/io/path_test.dart |
| diff --git a/tests/standalone/io/path_test.dart b/tests/standalone/io/path_test.dart |
| index 6437072f6f5650ced617cdbc65ff01feb1642c67..bcfa7043cf7ac14482315cedaf3fa4b15412744e 100644 |
| --- a/tests/standalone/io/path_test.dart |
| +++ b/tests/standalone/io/path_test.dart |
| @@ -9,71 +9,83 @@ |
| void main() { |
| testBaseFunctions(); |
| testCanonicalize(); |
| + testJoinAppend(); |
| } |
| void testBaseFunctions() { |
| testGetters(new Path("/foo/bar/fisk.hest"), |
| - ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| - 'absolute canonical'); |
| - testGetters(new Path("/foo/bar/fisk.hest"), |
| - ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| - 'absolute canonical'); |
| - testGetters(new Path("/foo/bar/fisk.hest"), |
| - ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| + ['/foo/bar', 'fisk.hest', 'fisk', 'hest', '/foo/bar/fisk'], |
| 'absolute canonical'); |
| testGetters(new Path(''), |
| - ['', '', '', ''], |
| - 'empty'); |
| + ['', '', '', '', ''], |
| + 'empty'); |
| // This corner case leaves a trailing slash for the root. |
| testGetters(new Path('/'), |
| - ['/', '', '', ''], |
| - 'absolute directory canonical trailing'); |
| + ['/', '', '', '', '/'], |
| + 'absolute canonical trailing'); |
| testGetters(new Path('.'), |
| - ['', '.', '', ''], |
| - 'canonical'); |
| + ['', '.', '.', '', '.'], |
| + 'canonical'); |
| + testGetters(new Path('..'), |
| + ['', '..', '..', '', '..'], |
| + 'canonical'); |
| testGetters(new Path('/ab,;- .c.d'), |
| - ['/', 'ab,;- .c.d', 'ab,;- .c', 'd'], |
| - 'absolute directory canonical'); |
| + ['/', 'ab,;- .c.d', 'ab,;- .c', 'd', '/ab,;- .c'], |
| + 'absolute canonical'); |
| // Canonical and non-canonical cases |
| testGetters(new Path("a/b/../c/./d/e"), |
| - ['a/b/../c/./d', 'e', 'e', ''], |
| - ''); |
| + ['a/b/../c/./d', 'e', 'e', '', 'a/b/../c/./d/e'], |
| + ''); |
| testGetters(new Path("a./b../..c/.d/e"), |
| - ['a./b../..c/.d', 'e', 'e', ''], |
| - 'canonical'); |
| + ['a./b../..c/.d', 'e', 'e', '', 'a./b../..c/.d/e'], |
| + 'canonical'); |
| // .. is allowed at the beginning of a canonical relative path. |
| testGetters(new Path("../../a/b/c/d/"), |
| - ['../../a/b/c/d', '', '', ''], |
| - 'canonical directory trailing'); |
| + ['../../a/b/c/d', '', '', '', '../../a/b/c/d/'], |
| + 'canonical directory trailing'); |
|
Bill Hesse
2012/06/21 15:07:33
Remove 'directory'
|
| + |
| + // '.' at the end of a path is not considered an extension. |
| + testGetters(new Path("a/b.c/."), |
| + ['a/b.c', '.', '.', '', 'a/b.c/.'], |
| + ''); |
| + // '..' at the end of a path is not considered an extension. |
| + testGetters(new Path("a/bc/../.."), |
| + ['a/bc/..', '..', '..', '', 'a/bc/../..'], |
| + ''); |
| // Test the special path cleaning operations on the Windows platform. |
| if (Platform.operatingSystem == 'windows') { |
| testGetters(new Path.fromNative(@"c:\foo\bar\fisk.hest"), |
| - ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| + ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest', |
| + '/c:/foo/bar/fisk'], |
| 'absolute canonical'); |
| testGetters(new Path.fromNative("\\foo\\bar\\"), |
| - ['/foo/bar', '', '', ''], |
| + ['/foo/bar', '', '', '', '/foo/bar/'], |
| 'absolute directory canonical trailing'); |
|
Bill Hesse
2012/06/21 15:07:33
remove directory
|
| testGetters(new Path.fromNative("\\foo\\bar\\hest"), |
| - ['/foo/bar', 'hest', 'hest', ''], |
| + ['/foo/bar', 'hest', 'hest', '', '/foo/bar/hest'], |
| 'absolute canonical'); |
| testGetters(new Path.fromNative(@"foo/bar\hest/.fisk"), |
| - ['foo/bar/hest', '.fisk', '', 'fisk'], |
| + ['foo/bar/hest', '.fisk', '', 'fisk', 'foo/bar/hest/'], |
| 'canonical'); |
| - testGetters(new Path.fromNative(@"foo//bar\\hest/\/.fisk"), |
| - ['foo//bar//hest', '.fisk', '', 'fisk'], |
| + testGetters(new Path.fromNative(@"foo//bar\\hest/\/.fisk."), |
| + ['foo//bar//hest', '.fisk.', '.fisk', '', |
| + 'foo//bar//hest///.fisk'], |
| ''); |
| } else { |
| // Make sure that backslashes are uninterpreted on other platforms. |
| testGetters(new Path.fromNative(@"/foo\bar/bif/fisk.hest"), |
| - [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest'], |
| + [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest', |
| + @'/foo\bar/bif/fisk'], |
| 'absolute canonical'); |
| testGetters(new Path.fromNative(@"//foo\bar///bif////fisk.hest"), |
| - [@'//foo\bar///bif', 'fisk.hest', 'fisk', 'hest'], |
| + [@'//foo\bar///bif', 'fisk.hest', 'fisk', 'hest', |
| + @'//foo\bar///bif////fisk'], |
| 'absolute'); |
| testGetters(new Path.fromNative(@"/foo\ bar/bif/gule\ fisk.hest"), |
| - [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest'], |
| + [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest', |
| + @'/foo\ bar/bif/gule\ fisk'], |
| 'absolute canonical'); |
| } |
| } |
| @@ -82,12 +94,16 @@ void testBaseFunctions() { |
| void testGetters(Path path, List components, String properties) { |
| final int DIRNAME = 0; |
| final int FILENAME = 1; |
| - final int BASENAME = 2; |
| + final int FILENAME_NO_EXTENSION = 2; |
| final int EXTENSION = 3; |
| + final int PATH_NO_EXTENSION = 4; |
| Expect.equals(components[DIRNAME], path.directoryPath.toString()); |
| Expect.equals(components[FILENAME], path.filename); |
| - Expect.equals(components[BASENAME], path.filenameWithoutExtension); |
| + Expect.equals(components[FILENAME_NO_EXTENSION], |
| + path.filenameWithoutExtension); |
| Expect.equals(components[EXTENSION], path.extension); |
| + Expect.equals(components[PATH_NO_EXTENSION], |
| + path.pathWithoutExtension.toString()); |
| Expect.equals(path.isCanonical, properties.contains('canonical')); |
| Expect.equals(path.isAbsolute, properties.contains('absolute')); |
| @@ -122,3 +138,33 @@ void testCanonicalize() { |
| t('c:/foo/../../..', '..'); |
| t('c:/foo/../../bad/dad/./..', 'bad'); |
| } |
| + |
| +void testJoinAppend() { |
| + void testJoin(String a, String b, String c) { |
| + Expect.equals(new Path(a).join(new Path(b)).toString(), c); |
| + } |
| + |
| + testJoin('/a/b', 'c/d', '/a/b/c/d'); |
| + testJoin('a/', 'b/c/', 'a/b/c/'); |
| + testJoin('a/b/./c/..//', 'd/.././..//e/f//', 'a/e/f/'); |
| + testJoin('a/b', 'c/../../../..', '..'); |
| + testJoin('a/b', 'c/../../../', '.'); |
| + testJoin('/a/b', 'c/../../../..', '/'); |
| + testJoin('/a/b', 'c/../../../', '/'); |
| + testJoin('a/b', 'c/../../../../../', '../../'); |
| + testJoin('a/b/c', '../../d', 'a/d'); |
| + testJoin('/a/b/c', '../../d', '/a/d'); |
| + testJoin('/a/b/c', '../../d/', '/a/d/'); |
| + testJoin('a/b/c', '../../d/', 'a/d/'); |
| + |
| + void testAppend(String a, String b, String c) { |
| + Expect.equals(new Path(a).append(b).toString(), c); |
| + } |
| + |
| + testAppendConcat('/a/b', 'c', '/a/b/c'); |
|
Bill Hesse
2012/06/21 15:07:33
Remove "Concat"
|
| + testAppendConcat('a/b/', 'cd', 'a/b/cd'); |
| + testAppendConcat('.', '..', './..'); |
| + testAppendConcat('a/b', '/c/d', 'a/b//c/d'); |
| + |
| + Expect.throws(() => new Path('/a/b/').join(new Path('/c/d'))); |
| +} |