Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: pkg/path/test/relative_test.dart

Issue 62753005: Refactor pkg/path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/path/test/posix_test.dart ('k') | pkg/path/test/url_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.Builder, 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";
11 11
12 void main() { 12 void main() {
13 test("test relative", () { 13 test("test relative", () {
14 relativeTest(new path.Builder(style: path.Style.posix, root: '.'), '/'); 14 relativeTest(new path.Context(style: path.Style.posix, current: '.'), '/');
15 relativeTest(new path.Builder(style: path.Style.posix, root: '/'), '/'); 15 relativeTest(new path.Context(style: path.Style.posix, current: '/'), '/');
16 relativeTest(new path.Builder(style: path.Style.windows, root: r'd:\'), 16 relativeTest(new path.Context(style: path.Style.windows, current: r'd:\'),
17 r'c:\'); 17 r'c:\');
18 relativeTest(new path.Builder(style: path.Style.windows, root: '.'), 18 relativeTest(new path.Context(style: path.Style.windows, current: '.'),
19 r'c:\'); 19 r'c:\');
20 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'), 20 relativeTest(new path.Context(style: path.Style.url, current: 'file:///'),
21 'http://myserver/'); 21 'http://myserver/');
22 relativeTest(new path.Builder(style: path.Style.url, root: '.'), 22 relativeTest(new path.Context(style: path.Style.url, current: '.'),
23 'http://myserver/'); 23 'http://myserver/');
24 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'), 24 relativeTest(new path.Context(style: path.Style.url, current: 'file:///'),
25 '/'); 25 '/');
26 relativeTest(new path.Builder(style: path.Style.url, root: '.'), '/'); 26 relativeTest(new path.Context(style: path.Style.url, current: '.'), '/');
27 }); 27 });
28 } 28 }
29 29
30 void relativeTest(path.Builder builder, String prefix) { 30 void relativeTest(path.Context context, String prefix) {
31 var isRelative = (builder.root == '.'); 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(builder.normalize(result), builder.relative(pathArg, from: fromArg)); 34 expect(context.normalize(result), context.relative(pathArg, from: fromArg));
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 25 matching lines...) Expand all
70 expectRelative('a/b', 'x/y//a/b', 'x/y/'); 70 expectRelative('a/b', 'x/y//a/b', 'x/y/');
71 expectRelative('../ya/b', '${prefix}x/ya/b', '${prefix}x/y'); 71 expectRelative('../ya/b', '${prefix}x/ya/b', '${prefix}x/y');
72 expectRelative('../ya/b', 'x/ya/b', 'x/y'); 72 expectRelative('../ya/b', 'x/ya/b', 'x/y');
73 expectRelative('../b', 'x/y/../b', 'x/y/.'); 73 expectRelative('../b', 'x/y/../b', 'x/y/.');
74 expectRelative('a/b/c', 'x/y/a//b/./f/../c', 'x/y'); 74 expectRelative('a/b/c', 'x/y/a//b/./f/../c', 'x/y');
75 expectRelative('.', '${prefix}x/y//', '${prefix}x/y/'); 75 expectRelative('.', '${prefix}x/y//', '${prefix}x/y/');
76 expectRelative('.', '${prefix}x/y/', '${prefix}x/y'); 76 expectRelative('.', '${prefix}x/y/', '${prefix}x/y');
77 77
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(() => builder.relative('.', from: '..'), throwsPathException); 80 expect(() => context.relative('.', from: '..'), throwsPathException);
81 expect(() => builder.relative('a/b', from: '../../d'), 81 expect(() => context.relative('a/b', from: '../../d'),
82 throwsPathException); 82 throwsPathException);
83 expect(() => builder.relative('a/b', from: '${prefix}a/b'), 83 expect(() => context.relative('a/b', from: '${prefix}a/b'),
84 throwsPathException); 84 throwsPathException);
85 // An absolute path relative from a relative path returns the absolute path. 85 // An absolute path relative from a relative path returns the absolute path.
86 expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d'); 86 expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d');
87 } 87 }
88 } 88 }
OLDNEW
« no previous file with comments | « pkg/path/test/posix_test.dart ('k') | pkg/path/test/url_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698