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 // Test the Path class in dart:io. | |
| 6 | |
| 7 #import("dart:io"); | |
| 8 | |
| 9 void main() { | |
| 10 testBaseFunctions(); | |
| 11 testCanonicalize(); | |
| 12 } | |
| 13 | |
| 14 void testBaseFunctions() { | |
| 15 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 16 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 17 'absolute canonical'); | |
| 18 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 19 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 20 'absolute canonical'); | |
| 21 testGetters(new Path("/foo/bar/fisk.hest"), | |
| 22 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 23 'absolute canonical'); | |
| 24 testGetters(new Path(''), | |
| 25 ['', '', '', ''], | |
| 26 'empty canonical'); | |
| 27 // This corner case leaves a trailing slash for the root. | |
| 28 testGetters(new Path('/'), | |
| 29 ['/', '', '', ''], | |
| 30 'absolute directory canonical'); | |
| 31 testGetters(new Path('/'), | |
| 32 ['/', '', '', ''], | |
| 33 'absolute directory canonical'); | |
| 34 testGetters(new Path('/ab,;- .c.d'), | |
| 35 ['/', 'ab,;- .c.d', 'ab,;- .c', 'd'], | |
| 36 'absolute directory canonical'); | |
| 37 | |
| 38 // Canonical and non-canonical cases | |
| 39 testGetters(new Path("a/b/../c/./d/e"), | |
| 40 ['a/b/../c/./d', 'e', 'e', ''], | |
| 41 ''); | |
| 42 testGetters(new Path("a./b../..c/.d/e"), | |
| 43 ['a./b../..c/.d', 'e', 'e', ''], | |
| 44 'canonical'); | |
| 45 // .. is allowed at the beginning of a canonical relative path. | |
| 46 testGetters(new Path("../../a/b/c/d/"), | |
| 47 ['../../a/b/c/d', '', '', ''], | |
| 48 'canonical directory'); | |
| 49 | |
|
Mads Ager (google)
2012/06/01 08:11:31
Remove a couple of these empty lines?
Bill Hesse
2012/06/15 14:23:08
Done.
| |
| 50 | |
| 51 | |
| 52 // Test the special path cleaning operations on the Windows platform. | |
| 53 if (Platform.operatingSystem == 'windows') { | |
| 54 testGetters(new Path.fromNative(@"c:\foo\bar\fisk.hest"), | |
| 55 ['/c:/foo/bar', 'fisk.hest', 'fisk', 'hest'], | |
| 56 'absolute canonical'); | |
| 57 testGetters(new Path.fromNative("\\foo\\bar\\"), | |
| 58 ['/foo/bar', '', '', ''], | |
| 59 'absolute directory canonical'); | |
| 60 testGetters(new Path.fromNative("\\foo\\bar\\hest"), | |
| 61 ['/foo/bar', 'hest', 'hest', ''], | |
| 62 'absolute canonical'); | |
| 63 testGetters(new Path.fromNative(@"foo/bar\hest/.fisk"), | |
| 64 ['foo/bar/hest', '.fisk', '', 'fisk'], | |
| 65 'canonical'); | |
| 66 testGetters(new Path.fromNative(@"foo//bar\\hest/\/.fisk"), | |
| 67 ['foo//bar//hest//', '.fisk', '', 'fisk'], | |
| 68 ''); | |
| 69 } else { | |
| 70 // Make sure that backslashes are uninterpreted on other platforms. | |
| 71 testGetters(new Path.fromNative(@"/foo\bar/bif/fisk.hest"), | |
| 72 [@'/foo\bar/bif', 'fisk.hest', 'fisk', 'hest'], | |
| 73 'absolute canonical'); | |
| 74 testGetters(new Path.fromNative(@"//foo\bar///bif////fisk.hest"), | |
| 75 [@'//foo\bar///bif///', 'fisk.hest', 'fisk', 'hest'], | |
| 76 'absolute'); | |
| 77 testGetters(new Path.fromNative(@"/foo\ bar/bif/gule\ fisk.hest"), | |
| 78 [@'/foo\ bar/bif', @'gule\ fisk.hest', @'gule\ fisk', 'hest'], | |
| 79 'absolute canonical'); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 | |
| 84 void testGetters(Path path, List components, String properties) { | |
| 85 final int DIRNAME = 0; | |
| 86 final int FILENAME = 1; | |
| 87 final int BASENAME = 2; | |
| 88 final int EXTENSION = 3; | |
| 89 Expect.equals(components[DIRNAME], path.directoryPath.toString()); | |
| 90 Expect.equals(components[FILENAME], path.filename); | |
| 91 Expect.equals(components[BASENAME], path.filenameWithoutExtension); | |
| 92 Expect.equals(components[EXTENSION], path.extension); | |
| 93 | |
| 94 Expect.equals(path.isCanonical, properties.contains('canonical')); | |
| 95 Expect.equals(path.isAbsolute, properties.contains('absolute')); | |
| 96 } | |
| 97 | |
| 98 void testCanonicalize() { | |
| 99 Function t = (input, canonicalized) { | |
| 100 Expect.equals(canonicalized, new Path(input).canonicalize().toString()); | |
| 101 }; | |
| 102 | |
| 103 t('.', '.'); | |
| 104 t('./.', '.'); | |
| 105 t('foo/..', '.'); | |
| 106 t('../foo', '../foo'); | |
| 107 t('/../foo', '/foo'); | |
| 108 t('/foo/..', '/'); | |
| 109 t('/foo/../', '/'); | |
| 110 t('/c:/../foo', '/c:/foo'); | |
| 111 t('/c:/foo/..', '/c:/'); | |
| 112 t('/c:/foo/../', '/c:/'); | |
| 113 t('..', '..'); | |
| 114 t('', ''); | |
| 115 t('/', '/'); | |
| 116 t('../foo/bar/..', '../foo'); | |
| 117 t('/../foo/bar/..', '/foo'); | |
| 118 t('foo/bar/../../../joe/../..', '../..'); | |
| 119 t('a/b/c/../../..d/./.e/f././', 'a/..d/.e/f./'); | |
| 120 t('/%:/foo/../..', '/%:/'); | |
| 121 t('c:/foo/../../..', '..'); | |
| 122 t('c:/foo/../../bad/dad/./..', 'bad'); | |
| 123 } | |
| OLD | NEW |