| 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 testRaw(); | 11 testRaw(); |
| 12 testCanonicalize(); | 12 testCanonicalize(); |
| 13 testJoinAppend(); | 13 testJoinAppend(); |
| 14 testRelativeTo(); | 14 testRelativeTo(); |
| 15 testWindowsShare(); | 15 testWindowsShare(); |
| 16 testWindowsDrive(); |
| 16 } | 17 } |
| 17 | 18 |
| 18 void testBaseFunctions() { | 19 void testBaseFunctions() { |
| 19 testGetters(new Path("/foo/bar/fisk.hest"), | 20 testGetters(new Path("/foo/bar/fisk.hest"), |
| 20 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], | 21 ['/foo/bar', 'fisk.hest', 'fisk', 'hest'], |
| 21 'absolute canonical'); | 22 'absolute canonical'); |
| 22 testGetters(new Path(''), | 23 testGetters(new Path(''), |
| 23 ['', '', '', ''], | 24 ['', '', '', ''], |
| 24 'empty'); | 25 'empty'); |
| 25 // This corner case leaves a trailing slash for the root. | 26 // This corner case leaves a trailing slash for the root. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 Expect.isTrue(canonical.toString().startsWith('/share/a')); | 295 Expect.isTrue(canonical.toString().startsWith('/share/a')); |
| 295 Expect.isTrue(canonical.toNativePath().startsWith(r'\\share\a')); | 296 Expect.isTrue(canonical.toNativePath().startsWith(r'\\share\a')); |
| 296 Expect.listEquals(['share', 'a', 'c'], canonical.segments()); | 297 Expect.listEquals(['share', 'a', 'c'], canonical.segments()); |
| 297 var appended = canonical.append('d'); | 298 var appended = canonical.append('d'); |
| 298 Expect.isTrue(appended.isAbsolute); | 299 Expect.isTrue(appended.isAbsolute); |
| 299 Expect.isTrue(appended.isWindowsShare); | 300 Expect.isTrue(appended.isWindowsShare); |
| 300 var directoryPath = canonical.directoryPath; | 301 var directoryPath = canonical.directoryPath; |
| 301 Expect.isTrue(directoryPath.isAbsolute); | 302 Expect.isTrue(directoryPath.isAbsolute); |
| 302 Expect.isTrue(directoryPath.isWindowsShare); | 303 Expect.isTrue(directoryPath.isWindowsShare); |
| 303 } | 304 } |
| 305 |
| 306 // Test that Windows drive information is handled correctly in relative |
| 307 // Path operations. |
| 308 void testWindowsDrive() { |
| 309 // Windows drive information only makes sense on Windows. |
| 310 if (Platform.operatingSystem != 'windows') return; |
| 311 // Test that case of drive letters is ignored, and that drive letters |
| 312 // are treated specially. |
| 313 var CPath = new Path(r'C:\a\b\..\c'); |
| 314 var cPath = new Path(r'c:\a\b\d'); |
| 315 var C2Path = new Path(r'C:\a\b\d'); |
| 316 var C3Path = new Path(r'C:\a\b'); |
| 317 var C4Path = new Path(r'C:\'); |
| 318 var DPath = new Path(r'D:\a\b\d\e'); |
| 319 var NoPath = new Path(r'\a\b\c\.'); |
| 320 |
| 321 Expect.throws(() => CPath.relativeTo(DPath)); |
| 322 Expect.throws(() => CPath.relativeTo(NoPath)); |
| 323 Expect.throws(() => NoPath.relativeTo(CPath)); |
| 324 Expect.equals('../../c', CPath.relativeTo(cPath).toString()); |
| 325 Expect.equals('../b/d', cPath.relativeTo(CPath).toString()); |
| 326 Expect.equals('.', DPath.relativeTo(DPath).toString()); |
| 327 Expect.equals('.', NoPath.relativeTo(NoPath).toString()); |
| 328 Expect.equals('.', C2Path.relativeTo(cPath).toString()); |
| 329 Expect.equals('..', C3Path.relativeTo(cPath).toString()); |
| 330 Expect.equals('d', cPath.relativeTo(C3Path).toString()); |
| 331 Expect.equals('a/b/d', cPath.relativeTo(C4Path).toString()); |
| 332 Expect.equals('../../../', C4Path.relativeTo(cPath).toString()); |
| 333 } |
| OLD | NEW |