Chromium Code Reviews| Index: pkg/path/test/relative_test.dart |
| diff --git a/pkg/path/test/relative_test.dart b/pkg/path/test/relative_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b9f2775ac84c2dd2da49770384b9d6c017d3e8f |
| --- /dev/null |
| +++ b/pkg/path/test/relative_test.dart |
| @@ -0,0 +1,82 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +// |
| +// Test "relative" on all styles of path.Builder, on all platforms. |
| + |
| +import "package:unittest/unittest.dart"; |
| +import "package:path/path.dart" as path; |
| + |
| +void main() { |
| + test("test relative", () { |
| + relativeTest(new path.Builder(style: path.Style.posix, root: '.'), ''); |
| + relativeTest(new path.Builder(style: path.Style.posix, root: '/'), ''); |
| + relativeTest(new path.Builder(style: path.Style.windows, root: 'd:/'), |
| + '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',
|
| + relativeTest(new path.Builder(style: path.Style.windows, root: '.'), 'c:'); |
| + relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'), |
| + 'http://myserver'); |
| + relativeTest(new path.Builder(style: path.Style.url, root: '.'), |
| + 'http://myserver'); |
| + relativeTest(new path.Builder(style: path.Style.url, root: 'file:///'), ''); |
| + relativeTest(new path.Builder(style: path.Style.url, root: '.'), ''); |
| + }); |
| +} |
| + |
| +void relativeTest(path.Builder builder, String prefix) { |
| + var isRelative = (builder.root == '.'); |
| + // Cases where the arguments are absolute paths. |
| + 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.
|
| + expect(builder.normalize(result), builder.relative(p, from: from)); |
| + } |
| + |
| + test('c/d', '$prefix/a/b/c/d', '$prefix/a/b'); |
| + test('c/d', '$prefix/a/b/c/d', '$prefix/a/b/'); |
| + test('.', '$prefix/a', '$prefix/a'); |
| + // Trailing slashes in the inputs have no effect. |
| + test('../../z/x/y', '$prefix/a/b/z/x/y', '$prefix/a/b/c/d/'); |
| + test('../../z/x/y', '$prefix/a/b/z/x/y', '$prefix/a/b/c/d'); |
| + test('../../z/x/y', '$prefix/a/b/z/x/y/', '$prefix/a/b/c/d'); |
| + test('../../../z/x/y', '$prefix/z/x/y', '$prefix/a/b/c'); |
| + test('../../../z/x/y', '$prefix/z/x/y', '$prefix/a/b/c/'); |
| + |
| + // Cases where the arguments are relative paths. |
| + test('c/d', 'a/b/c/d', 'a/b'); |
| + test('.', 'a/b/c', 'a/b/c'); |
| + test('.', 'a/d/../b/c', 'a/b/c/'); |
| + test('.', '', ''); |
| + test('.', '.', ''); |
| + test('.', '', '.'); |
| + test('.', '.', '.'); |
| + test('.', '..', '..'); |
| + if (isRelative) test('..', '..', '.'); |
| + test('a', 'a', ''); |
| + test('a', 'a', '.'); |
| + test('..', '.', 'a'); |
| + test('.', 'a/b/f/../c', 'a/e/../b/c'); |
| + test('d', 'a/b/f/../c/d', 'a/e/../b/c'); |
| + test('..', 'a/b/f/../c', 'a/e/../b/c/e/'); |
| + test('../..', '', 'a/b/'); |
| + if (isRelative) test('../../..', '..', 'a/b/'); |
| + test('../b/c/d', 'b/c/d/', 'a/'); |
| + test('../a/b/c', 'x/y/a//b/./f/../c', 'x//y/z'); |
| + |
| + // Case where from is an exact substring of path. |
| + test('a/b', '$prefix/x/y//a/b', '$prefix/x/y/'); |
| + test('a/b', 'x/y//a/b', 'x/y/'); |
| + test('../ya/b', '$prefix/x/ya/b', '$prefix/x/y'); |
| + test('../ya/b', 'x/ya/b', 'x/y'); |
| + test('../b', 'x/y/../b', 'x/y/.'); |
| + test('a/b/c', 'x/y/a//b/./f/../c', 'x/y'); |
| + test('.', '$prefix/x/y//', '$prefix/x/y/'); |
| + test('.', '$prefix/x/y/', '$prefix/x/y'); |
| + |
| + // Should always throw - no relative path can be constructed. |
| + if (isRelative) { |
| + expect(() => builder.relative('.', from: '..'), throws); |
| + expect(() => builder.relative('a/b', from: '../../d'), throws); |
| + expect(() => builder.relative('a/b', from: '$prefix/a/b'), throws); |
| + // An absolute path relative from a relative path returns the absolute path. |
| + test('$prefix/a/b', '$prefix/a/b', 'c/d'); |
| + } |
| +} |