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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bfc7e9aa7e9a0d81c908236cb8104493278ad991 |
| --- /dev/null |
| +++ b/tests/standalone/io/path_test.dart |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +// |
| +// Process test program to test that compilation errors in the process |
| +// exit handler is reported correctly. |
| + |
| +#import("dart:io"); |
| + |
| +// Only here to make editor happy when Path is not in editor's dart:io. |
| +// Remove these two lines when committing. |
|
Søren Gjesse
2012/05/29 07:18:01
If you are only unit-testing the path library you
Bill Hesse
2012/05/31 15:55:10
I need to add a mock Platform in that case, unless
|
| +//#source("../../../runtime/bin/path.dart"); |
| +//#source("../../../runtime/bin/path_impl.dart"); |
| + |
| +void main() { |
| + testBaseFunctions(); |
| +} |
| + |
| +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'], |
| + 'absolute canonical'); |
| + testGetters(new Path(''), |
| + ['', '', '', ''], |
| + 'empty canonical'); |
| + // This corner case leaves a trailing slash for the root. |
| + testGetters(new Path('/'), |
| + ['/', '', '', ''], |
| + 'absolute directory canonical'); |
| + testGetters(new Path('/'), |
| + ['/', '', '', ''], |
| + 'absolute directory canonical'); |
| + testGetters(new Path('/ab,;- .c.d'), |
| + ['/', 'ab,;- .c.d', 'ab,;- .c', 'd'], |
| + 'absolute directory canonical'); |
| + |
| + // Non-canonical cases |
| + testGetters(new Path("a/b/../c/./d/e"), |
| + ['a/b/../c/./d', 'e', 'e', ''], |
| + ''); |
| + testGetters(new Path("a./b..//..c/.d/e"), |
| + ['a./b../..c/.d', 'e', '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'); |
| + |
| + |
| + |
| + // Test the special path cleaning operations on the Windows platform. |
| + if (Platform.operatingSystem == 'windows') { |
| + testGetters(new Path(@"c:\foo\bar\fisk.hest"), |
| + ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| + 'absolute canonical'); |
| + testGetters(new Path(@"\foo\bar\"), |
| + ['/foo/bar', '', '', ''], |
| + 'absolute directory canonical'); |
| + testGetters(new Path("\\foo\\bar\\hest"), |
| + ['/foo/bar', 'hest', 'hest', ''], |
| + 'absolute canonical'); |
| + testGetters(new Path(@"foo/bar\hest/.fisk"), |
| + ['foo/bar/hest', '.fisk', '', 'fisk'], |
| + 'canonical'); |
| + } else { |
| + // Make sure that backslashes are uninterpreted on other platforms. |
| + testGetters(new Path(@"/foo\bar/bif/fisk.hest"), |
| + [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest'], |
| + 'absolute canonical'); |
| + testGetters(new Path(@"/foo\ bar/bif/gule\ fisk.hest"), |
| + [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest'], |
| + 'absolute canonical'); |
| + } |
| +} |
| + |
| + |
| +void testGetters(Path path, List components, String properties) { |
| + final int DIRNAME = 0; |
| + final int FILENAME = 1; |
| + final int BASENAME = 2; |
| + final int EXTENSION = 3; |
| + Expect.equals(components[DIRNAME], path.dirname().toString()); |
| + Expect.equals(components[FILENAME], path.filename()); |
| + Expect.equals(components[BASENAME], path.basename()); |
| + Expect.equals(components[EXTENSION], path.extension()); |
| + |
| + Expect.equals(path.isCanonical, properties.contains('canonical')); |
| +} |