OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "relative" on all styles of path.Context, on all platforms. | 5 // Test "relative" on all styles of path.Context, on all platforms. |
6 | 6 |
7 import "package:unittest/unittest.dart"; | 7 import "package:unittest/unittest.dart"; |
8 import "package:path/path.dart" as path; | 8 import "package:path/path.dart" as path; |
9 | 9 |
10 import "utils.dart"; | 10 import "utils.dart"; |
(...skipping 13 matching lines...) Expand all Loading... |
24 relativeTest( | 24 relativeTest( |
25 new path.Context(style: path.Style.url, current: 'file:///'), '/'); | 25 new path.Context(style: path.Style.url, current: 'file:///'), '/'); |
26 relativeTest(new path.Context(style: path.Style.url, current: '.'), '/'); | 26 relativeTest(new path.Context(style: path.Style.url, current: '.'), '/'); |
27 }); | 27 }); |
28 } | 28 } |
29 | 29 |
30 void relativeTest(path.Context context, String prefix) { | 30 void relativeTest(path.Context context, String prefix) { |
31 var isRelative = (context.current == '.'); | 31 var isRelative = (context.current == '.'); |
32 // Cases where the arguments are absolute paths. | 32 // Cases where the arguments are absolute paths. |
33 expectRelative(result, pathArg, fromArg) { | 33 expectRelative(result, pathArg, fromArg) { |
34 expect(context.normalize(result), context.relative(pathArg, from: fromArg)); | 34 expect(context.relative(pathArg, from: fromArg), context.normalize(result)); |
35 } | 35 } |
36 | 36 |
37 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b'); | 37 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b'); |
38 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b/'); | 38 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b/'); |
39 expectRelative('.', '${prefix}a', '${prefix}a'); | 39 expectRelative('.', '${prefix}a', '${prefix}a'); |
40 // Trailing slashes in the inputs have no effect. | 40 // Trailing slashes in the inputs have no effect. |
41 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y', '${prefix}a/b/c/d/'); | 41 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y', '${prefix}a/b/c/d/'); |
42 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y', '${prefix}a/b/c/d'); | 42 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y', '${prefix}a/b/c/d'); |
43 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y/', '${prefix}a/b/c/d'); | 43 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y/', '${prefix}a/b/c/d'); |
44 expectRelative('../../../z/x/y', '${prefix}z/x/y', '${prefix}a/b/c'); | 44 expectRelative('../../../z/x/y', '${prefix}z/x/y', '${prefix}a/b/c'); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // Should always throw - no relative path can be constructed. | 78 // Should always throw - no relative path can be constructed. |
79 if (isRelative) { | 79 if (isRelative) { |
80 expect(() => context.relative('.', from: '..'), throwsPathException); | 80 expect(() => context.relative('.', from: '..'), throwsPathException); |
81 expect(() => context.relative('a/b', from: '../../d'), throwsPathException); | 81 expect(() => context.relative('a/b', from: '../../d'), throwsPathException); |
82 expect(() => context.relative('a/b', from: '${prefix}a/b'), | 82 expect(() => context.relative('a/b', from: '${prefix}a/b'), |
83 throwsPathException); | 83 throwsPathException); |
84 // An absolute path relative from a relative path returns the absolute path. | 84 // An absolute path relative from a relative path returns the absolute path. |
85 expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d'); | 85 expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d'); |
86 } | 86 } |
87 } | 87 } |
OLD | NEW |