OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // Test the Path class in dart:io. | 5 // Test the Path class in dart:io. |
6 | 6 |
7 #import("dart:io"); | 7 #import("dart:io"); |
8 | 8 |
9 void main() { | 9 void main() { |
10 testBaseFunctions(); | 10 testBaseFunctions(); |
11 testCanonicalize(); | 11 testCanonicalize(); |
12 testJoinAppend(); | 12 testJoinAppend(); |
13 testRelativeTo(); | 13 testRelativeTo(); |
| 14 testWindowsShare(); |
14 } | 15 } |
15 | 16 |
16 void testBaseFunctions() { | 17 void testBaseFunctions() { |
17 testGetters(new Path("/foo/bar/fisk.hest"), | 18 testGetters(new Path("/foo/bar/fisk.hest"), |
18 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | 19 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
19 'absolute canonical'); | 20 'absolute canonical'); |
20 testGetters(new Path(''), | 21 testGetters(new Path(''), |
21 ['', '', '', ''], | 22 ['', '', '', ''], |
22 'empty'); | 23 'empty'); |
23 // This corner case leaves a trailing slash for the root. | 24 // This corner case leaves a trailing slash for the root. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 Expect.equals('../../../z/x/y', | 188 Expect.equals('../../../z/x/y', |
188 new Path('/z/x/y').relativeTo(new Path('/a/b/c/')).toString()); | 189 new Path('/z/x/y').relativeTo(new Path('/a/b/c/')).toString()); |
189 | 190 |
190 // Not implemented yet. Should return new Path('../b/c/d/'). | 191 // Not implemented yet. Should return new Path('../b/c/d/'). |
191 Expect.throws(() => | 192 Expect.throws(() => |
192 new Path('b/c/d/').relativeTo(new Path('a/'))); | 193 new Path('b/c/d/').relativeTo(new Path('a/'))); |
193 // Should always throw - no relative path can be constructed. | 194 // Should always throw - no relative path can be constructed. |
194 Expect.throws(() => | 195 Expect.throws(() => |
195 new Path('a/b').relativeTo(new Path('../../d'))); | 196 new Path('a/b').relativeTo(new Path('../../d'))); |
196 } | 197 } |
| 198 |
| 199 // Test that Windows share information is maintain through |
| 200 // Path operations. |
| 201 void testWindowsShare() { |
| 202 // Windows share information only makes sense on Windows. |
| 203 if (Platform.operatingSystem != 'windows') return; |
| 204 var path = new Path.fromNative(r'\\share\a\b\..\c'); |
| 205 Expect.isTrue(path.isAbsolute); |
| 206 Expect.isTrue(path.isWindowsShare); |
| 207 Expect.isFalse(path.hasTrailingSeparator); |
| 208 var canonical = path.canonicalize(); |
| 209 Expect.isTrue(canonical.isAbsolute); |
| 210 Expect.isTrue(canonical.isWindowsShare); |
| 211 Expect.isFalse(path.isCanonical); |
| 212 Expect.isTrue(canonical.isCanonical); |
| 213 var joined = canonical.join(new Path('d/e/f')); |
| 214 Expect.isTrue(joined.isAbsolute); |
| 215 Expect.isTrue(joined.isWindowsShare); |
| 216 var relativeTo = joined.relativeTo(canonical); |
| 217 Expect.isFalse(relativeTo.isAbsolute); |
| 218 Expect.isFalse(relativeTo.isWindowsShare); |
| 219 var nonShare = new Path('/share/a/c/d/e'); |
| 220 Expect.throws(() => nonShare.relativeTo(canonical)); |
| 221 Expect.isTrue(canonical.toString().startsWith('/share/a')); |
| 222 Expect.isTrue(canonical.toNativePath().startsWith(r'\\share\a')); |
| 223 Expect.listEquals(['share', 'a', 'c'], canonical.segments()); |
| 224 var appended = canonical.append('d'); |
| 225 Expect.isTrue(appended.isAbsolute); |
| 226 Expect.isTrue(appended.isWindowsShare); |
| 227 var directoryPath = canonical.directoryPath; |
| 228 Expect.isTrue(directoryPath.isAbsolute); |
| 229 Expect.isTrue(directoryPath.isWindowsShare); |
| 230 } |
OLD | NEW |