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

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: address comments 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
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: 'd:/'),
15 'c:');
nweiz 2013/07/22 21:00:33 It seems weird to me that the prefix here is "c:"
Bill Hesse 2013/07/23 16:07:00 The prefix for the URL tests is 'http://myserver',
16 relativeTest(new path.Builder(style: path.Style.windows, root: '.'), 'c:');
17 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'),
18 'http://myserver');
19 relativeTest(new path.Builder(style: path.Style.url, root: '.'),
20 'http://myserver');
21 relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'), '');
22 relativeTest(new path.Builder(style: path.Style.url, root: '.'), '');
23 });
24 }
25
26 void relativeTest(path.Builder builder, String prefix) {
27 var isRelative = (builder.root == '.');
28 // Cases where the arguments are absolute paths.
29 test(result, p, from) {
nweiz 2013/07/22 21:00:33 Calling this [test] is confusing given that [test]
Bill Hesse 2013/07/23 16:07:00 Done.
30 expect(builder.normalize(result), builder.relative(p, from: from));
31 }
32
33 test('c/d', '$prefix/a/b/c/d', '$prefix/a/b');
34 test('c/d', '$prefix/a/b/c/d', '$prefix/a/b/');
35 test('.', '$prefix/a', '$prefix/a');
36 // Trailing slashes in the inputs have no effect.
37 test('../../z/x/y', '$prefix/a/b/z/x/y', '$prefix/a/b/c/d/');
38 test('../../z/x/y', '$prefix/a/b/z/x/y', '$prefix/a/b/c/d');
39 test('../../z/x/y', '$prefix/a/b/z/x/y/', '$prefix/a/b/c/d');
40 test('../../../z/x/y', '$prefix/z/x/y', '$prefix/a/b/c');
41 test('../../../z/x/y', '$prefix/z/x/y', '$prefix/a/b/c/');
42
43 // Cases where the arguments are relative paths.
44 test('c/d', 'a/b/c/d', 'a/b');
45 test('.', 'a/b/c', 'a/b/c');
46 test('.', 'a/d/../b/c', 'a/b/c/');
47 test('.', '', '');
48 test('.', '.', '');
49 test('.', '', '.');
50 test('.', '.', '.');
51 test('.', '..', '..');
52 if (isRelative) test('..', '..', '.');
53 test('a', 'a', '');
54 test('a', 'a', '.');
55 test('..', '.', 'a');
56 test('.', 'a/b/f/../c', 'a/e/../b/c');
57 test('d', 'a/b/f/../c/d', 'a/e/../b/c');
58 test('..', 'a/b/f/../c', 'a/e/../b/c/e/');
59 test('../..', '', 'a/b/');
60 if (isRelative) test('../../..', '..', 'a/b/');
61 test('../b/c/d', 'b/c/d/', 'a/');
62 test('../a/b/c', 'x/y/a//b/./f/../c', 'x//y/z');
63
64 // Case where from is an exact substring of path.
65 test('a/b', '$prefix/x/y//a/b', '$prefix/x/y/');
66 test('a/b', 'x/y//a/b', 'x/y/');
67 test('../ya/b', '$prefix/x/ya/b', '$prefix/x/y');
68 test('../ya/b', 'x/ya/b', 'x/y');
69 test('../b', 'x/y/../b', 'x/y/.');
70 test('a/b/c', 'x/y/a//b/./f/../c', 'x/y');
71 test('.', '$prefix/x/y//', '$prefix/x/y/');
72 test('.', '$prefix/x/y/', '$prefix/x/y');
73
74 // Should always throw - no relative path can be constructed.
75 if (isRelative) {
76 expect(() => builder.relative('.', from: '..'), throws);
77 expect(() => builder.relative('a/b', from: '../../d'), throws);
78 expect(() => builder.relative('a/b', from: '$prefix/a/b'), throws);
79 // An absolute path relative from a relative path returns the absolute path.
80 test('$prefix/a/b', '$prefix/a/b', 'c/d');
81 }
82 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698