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

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

Issue 19231002: Port dart:io Path tests to package:path. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add comment to relative(path, from: from) Created 7 years, 5 months 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Test "relative" on all styles of path.Builder, on all platforms.
6
7 import "package:unittest/unittest.dart";
8 import "package:path/path.dart" as path;
9
10 void main() {
11 test("test relative", () {
12 relativeTest(new path.Builder(style: path.Style.posix, root: '.'), '/');
13 relativeTest(new path.Builder(style: path.Style.posix, root: '/'), '/');
14 relativeTest(new path.Builder(style: path.Style.windows, root: r'd:\'),
15 r'c:\');
16 relativeTest(new path.Builder(style: path.Style.windows, root: '.'),
17 r'c:\');
18 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'),
19 'http://myserver/');
20 relativeTest(new path.Builder(style: path.Style.url, root: '.'),
21 'http://myserver/');
22 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'),
23 '/');
24 relativeTest(new path.Builder(style: path.Style.url, root: '.'), '/');
25 });
26 }
27
28 void relativeTest(path.Builder builder, String prefix) {
29 var isRelative = (builder.root == '.');
30 // Cases where the arguments are absolute paths.
31 expectRelative(result, pathArg, fromArg) {
32 expect(builder.normalize(result), builder.relative(pathArg, from: fromArg));
33 }
34
35 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b');
36 expectRelative('c/d', '${prefix}a/b/c/d', '${prefix}a/b/');
37 expectRelative('.', '${prefix}a', '${prefix}a');
38 // Trailing slashes in the inputs have no effect.
39 expectRelative('../../z/x/y', '${prefix}a/b/z/x/y', '${prefix}a/b/c/d/');
40 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}z/x/y', '${prefix}a/b/c');
43 expectRelative('../../../z/x/y', '${prefix}z/x/y', '${prefix}a/b/c/');
44
45 // Cases where the arguments are relative paths.
46 expectRelative('c/d', 'a/b/c/d', 'a/b');
47 expectRelative('.', 'a/b/c', 'a/b/c');
48 expectRelative('.', 'a/d/../b/c', 'a/b/c/');
49 expectRelative('.', '', '');
50 expectRelative('.', '.', '');
51 expectRelative('.', '', '.');
52 expectRelative('.', '.', '.');
53 expectRelative('.', '..', '..');
54 if (isRelative) expectRelative('..', '..', '.');
55 expectRelative('a', 'a', '');
56 expectRelative('a', 'a', '.');
57 expectRelative('..', '.', 'a');
58 expectRelative('.', 'a/b/f/../c', 'a/e/../b/c');
59 expectRelative('d', 'a/b/f/../c/d', 'a/e/../b/c');
60 expectRelative('..', 'a/b/f/../c', 'a/e/../b/c/e/');
61 expectRelative('../..', '', 'a/b/');
62 if (isRelative) expectRelative('../../..', '..', 'a/b/');
63 expectRelative('../b/c/d', 'b/c/d/', 'a/');
64 expectRelative('../a/b/c', 'x/y/a//b/./f/../c', 'x//y/z');
65
66 // Case where from is an exact substring of path.
67 expectRelative('a/b', '${prefix}x/y//a/b', '${prefix}x/y/');
68 expectRelative('a/b', 'x/y//a/b', 'x/y/');
69 expectRelative('../ya/b', '${prefix}x/ya/b', '${prefix}x/y');
70 expectRelative('../ya/b', 'x/ya/b', 'x/y');
71 expectRelative('../b', 'x/y/../b', 'x/y/.');
72 expectRelative('a/b/c', 'x/y/a//b/./f/../c', 'x/y');
73 expectRelative('.', '${prefix}x/y//', '${prefix}x/y/');
74 expectRelative('.', '${prefix}x/y/', '${prefix}x/y');
75
76 // Should always throw - no relative path can be constructed.
77 if (isRelative) {
78 expect(() => builder.relative('.', from: '..'), throwsArgumentError);
79 expect(() => builder.relative('a/b', from: '../../d'),
80 throwsArgumentError);
81 expect(() => builder.relative('a/b', from: '${prefix}a/b'),
82 throwsArgumentError);
83 // An absolute path relative from a relative path returns the absolute path.
84 expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d');
85 }
86 }
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