Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 // Process test program to test that compilation errors in the process | |
| 6 // exit handler is reported correctly. | |
| 7 | |
| 8 #import("dart:io"); | |
| 9 | |
| 10 // Only here to make editor happy when Path is not in editor's dart:io. | |
| 11 // 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
| |
| 12 //#source("../../../runtime/bin/path.dart"); | |
| 13 //#source("../../../runtime/bin/path_impl.dart"); | |
| 14 | |
| 15 void main() { | |
| 16 testBaseFunctions(); | |
| 17 } | |
| 18 | |
| 19 void testBaseFunctions() { | |
| 20 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 21 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 22 'absolute canonical'); | |
| 23 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 24 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 25 'absolute canonical'); | |
| 26 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 27 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 28 'absolute canonical'); | |
| 29 testGetters(new Path(''), | |
| 30 ['', '', '', ''], | |
| 31 'empty canonical'); | |
| 32 // This corner case leaves a trailing slash for the root. | |
| 33 testGetters(new Path('/'), | |
| 34 ['/', '', '', ''], | |
| 35 'absolute directory canonical'); | |
| 36 testGetters(new Path('/'), | |
| 37 ['/', '', '', ''], | |
| 38 'absolute directory canonical'); | |
| 39 testGetters(new Path('/ab,;- .c.d'), | |
| 40 ['/', 'ab,;- .c.d', 'ab,;- .c', 'd'], | |
| 41 'absolute directory canonical'); | |
| 42 | |
| 43 // Non-canonical cases | |
| 44 testGetters(new Path("a/b/../c/./d/e"), | |
| 45 ['a/b/../c/./d', 'e', 'e', ''], | |
| 46 ''); | |
| 47 testGetters(new Path("a./b..//..c/.d/e"), | |
| 48 ['a./b../..c/.d', 'e', 'e', ''], | |
| 49 'canonical'); | |
| 50 // .. is allowed at the beginning of a canonical relative path. | |
| 51 testGetters(new Path("../../a/b/c/d/"), | |
| 52 ['../../a/b/c/d', '', '', ''], | |
| 53 'canonical directory'); | |
| 54 | |
| 55 | |
| 56 | |
| 57 // Test the special path cleaning operations on the Windows platform. | |
| 58 if (Platform.operatingSystem == 'windows') { | |
| 59 testGetters(new Path(@"c:\foo\bar\fisk.hest"), | |
| 60 ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 61 'absolute canonical'); | |
| 62 testGetters(new Path(@"\foo\bar\"), | |
| 63 ['/foo/bar', '', '', ''], | |
| 64 'absolute directory canonical'); | |
| 65 testGetters(new Path("\\foo\\bar\\hest"), | |
| 66 ['/foo/bar', 'hest', 'hest', ''], | |
| 67 'absolute canonical'); | |
| 68 testGetters(new Path(@"foo/bar\hest/.fisk"), | |
| 69 ['foo/bar/hest', '.fisk', '', 'fisk'], | |
| 70 'canonical'); | |
| 71 } else { | |
| 72 // Make sure that backslashes are uninterpreted on other platforms. | |
| 73 testGetters(new Path(@"/foo\bar/bif/fisk.hest"), | |
| 74 [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest'], | |
| 75 'absolute canonical'); | |
| 76 testGetters(new Path(@"/foo\ bar/bif/gule\ fisk.hest"), | |
| 77 [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest'], | |
| 78 'absolute canonical'); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 | |
| 83 void testGetters(Path path, List components, String properties) { | |
| 84 final int DIRNAME = 0; | |
| 85 final int FILENAME = 1; | |
| 86 final int BASENAME = 2; | |
| 87 final int EXTENSION = 3; | |
| 88 Expect.equals(components[DIRNAME], path.dirname().toString()); | |
| 89 Expect.equals(components[FILENAME], path.filename()); | |
| 90 Expect.equals(components[BASENAME], path.basename()); | |
| 91 Expect.equals(components[EXTENSION], path.extension()); | |
| 92 | |
| 93 Expect.equals(path.isCanonical, properties.contains('canonical')); | |
| 94 } | |
| OLD | NEW |