reformatted, remove unused fields and imports, updated readme
and fixed codereview.settings
R=nweiz@google.com
Review URL: https://codereview.chromium.org//831093005
diff --git a/README.md b/README.md
index 2e3eec1..5a172cd 100644
--- a/README.md
+++ b/README.md
@@ -14,13 +14,17 @@
The path library was designed to be imported with a prefix, though you don't
have to if you don't want to:
- import 'package:path/path.dart' as path;
+```dart
+import 'package:path/path.dart' as path;
+```
The most common way to use the library is through the top-level functions.
These manipulate path strings based on your current working directory and
the path style (POSIX, Windows, or URLs) of the host platform. For example:
- path.join("directory", "file.txt");
+```dart
+path.join("directory", "file.txt");
+```
This calls the top-level [join] function to join "directory" and
"file.txt" using the current platform's directory separator.
@@ -29,8 +33,10 @@
underlying platform that the program is running on, you can create a
[Context] and give it an explicit [Style]:
- var context = new path.Context(style: Style.windows);
- context.join("directory", "file.txt");
+```dart
+var context = new path.Context(style: Style.windows);
+context.join("directory", "file.txt");
+```
This will join "directory" and "file.txt" using the Windows path separator,
even when the program is run on a POSIX machine.
diff --git a/benchmark/benchmark.dart b/benchmark/benchmark.dart
index 60a2b53..419eee0 100644
--- a/benchmark/benchmark.dart
+++ b/benchmark/benchmark.dart
@@ -48,11 +48,7 @@
}
}
-const COMMON_PATHS = const [
- '.',
- '..',
- 'out/ReleaseIA32/packages',
-];
+const COMMON_PATHS = const ['.', '..', 'out/ReleaseIA32/packages'];
final STYLE_PATHS = {
path.Style.posix: [
diff --git a/codereview.settings b/codereview.settings
index eef3955..1ff4094 100644
--- a/codereview.settings
+++ b/codereview.settings
@@ -1,3 +1,3 @@
-CODE_REVIEW_SERVER: http://codereview.chromium.org/
+CODE_REVIEW_SERVER: https://codereview.chromium.org/
VIEW_VC: https://github.com/dart-lang/path/commit/
CC_LIST: reviews@dartlang.org
\ No newline at end of file
diff --git a/lib/path.dart b/lib/path.dart
index be6e95a..cfbaf11 100644
--- a/lib/path.dart
+++ b/lib/path.dart
@@ -99,8 +99,8 @@
///
/// path.absolute('path', 'to/foo'); // -> '/your/current/dir/path/to/foo'
String absolute(String part1, [String part2, String part3, String part4,
- String part5, String part6, String part7]) =>
- context.absolute(part1, part2, part3, part4, part5, part6, part7);
+ String part5, String part6, String part7]) =>
+ context.absolute(part1, part2, part3, part4, part5, part6, part7);
/// Gets the part of [path] after the last separator.
///
@@ -221,8 +221,8 @@
///
/// path.join('path', '/to', 'foo'); // -> '/to/foo'
String join(String part1, [String part2, String part3, String part4,
- String part5, String part6, String part7, String part8]) =>
- context.join(part1, part2, part3, part4, part5, part6, part7, part8);
+ String part5, String part6, String part7, String part8]) =>
+ context.join(part1, part2, part3, part4, part5, part6, part7, part8);
/// Joins the given path parts into a single path using the current platform's
/// [separator]. Example:
diff --git a/lib/src/context.dart b/lib/src/context.dart
index e9237a2..a3efd95 100644
--- a/lib/src/context.dart
+++ b/lib/src/context.dart
@@ -44,7 +44,9 @@
}
/// Create a [Context] to be used internally within path.
- Context._internal() : style = Style.platform, _current = null;
+ Context._internal()
+ : style = Style.platform,
+ _current = null;
Context._(this.style, this._current);
@@ -70,7 +72,7 @@
///
/// If [current] isn't absolute, this won't return an absolute path.
String absolute(String part1, [String part2, String part3, String part4,
- String part5, String part6, String part7]) {
+ String part5, String part6, String part7]) {
return join(current, part1, part2, part3, part4, part5, part6, part7);
}
@@ -94,7 +96,7 @@
///
/// context.basenameWithoutExtension('path/to/foo.dart/'); // -> 'foo'
String basenameWithoutExtension(String path) =>
- _parse(path).basenameWithoutExtension;
+ _parse(path).basenameWithoutExtension;
/// Gets the part of [path] before the last separator.
///
@@ -194,7 +196,7 @@
/// context.join('path', '/to', 'foo'); // -> '/to/foo'
///
String join(String part1, [String part2, String part3, String part4,
- String part5, String part6, String part7, String part8]) {
+ String part5, String part6, String part7, String part8]) {
var parts = [part1, part2, part3, part4, part5, part6, part7, part8];
_validateArgList("join", parts);
return joinAll(parts.where((part) => part != null));
@@ -274,8 +276,7 @@
List<String> split(String path) {
var parsed = _parse(path);
// Filter out empty parts that exist due to multiple separators in a row.
- parsed.parts = parsed.parts.where((part) => !part.isEmpty)
- .toList();
+ parsed.parts = parsed.parts.where((part) => !part.isEmpty).toList();
if (parsed.root != null) parsed.parts.insert(0, parsed.root);
return parsed.parts;
}
@@ -354,15 +355,16 @@
// one. In Windows, drive letters are case-insenstive and we allow
// calculation of relative paths, even if a path has not been normalized.
if (fromParsed.root != pathParsed.root &&
- ((fromParsed.root == null || pathParsed.root == null) ||
- fromParsed.root.toLowerCase().replaceAll('/', '\\') !=
- pathParsed.root.toLowerCase().replaceAll('/', '\\'))) {
+ ((fromParsed.root == null || pathParsed.root == null) ||
+ fromParsed.root.toLowerCase().replaceAll('/', '\\') !=
+ pathParsed.root.toLowerCase().replaceAll('/', '\\'))) {
return pathParsed.toString();
}
// Strip off their common prefix.
- while (fromParsed.parts.length > 0 && pathParsed.parts.length > 0 &&
- fromParsed.parts[0] == pathParsed.parts[0]) {
+ while (fromParsed.parts.length > 0 &&
+ pathParsed.parts.length > 0 &&
+ fromParsed.parts[0] == pathParsed.parts[0]) {
fromParsed.parts.removeAt(0);
fromParsed.separators.removeAt(1);
pathParsed.parts.removeAt(0);
@@ -375,11 +377,11 @@
if (fromParsed.parts.length > 0 && fromParsed.parts[0] == '..') {
throw new PathException('Unable to find a path to "$path" from "$from".');
}
- pathParsed.parts.insertAll(0,
- new List.filled(fromParsed.parts.length, '..'));
+ pathParsed.parts.insertAll(
+ 0, new List.filled(fromParsed.parts.length, '..'));
pathParsed.separators[0] = '';
- pathParsed.separators.insertAll(1,
- new List.filled(fromParsed.parts.length, style.separator));
+ pathParsed.separators.insertAll(
+ 1, new List.filled(fromParsed.parts.length, style.separator));
// Corner case: the paths completely collapsed.
if (pathParsed.parts.length == 0) return '.';
@@ -388,7 +390,10 @@
// Don't add a final '/.' in that case.
if (pathParsed.parts.length > 1 && pathParsed.parts.last == '.') {
pathParsed.parts.removeLast();
- pathParsed.separators..removeLast()..removeLast()..add('');
+ pathParsed.separators
+ ..removeLast()
+ ..removeLast()
+ ..add('');
}
// Make it relative.
@@ -415,7 +420,8 @@
}
var parts = this.split(relative);
- return this.isRelative(relative) && parts.first != '..' &&
+ return this.isRelative(relative) &&
+ parts.first != '..' &&
parts.first != '.';
}
@@ -518,7 +524,6 @@
var path = normalize(fromUri(uri));
var rel = relative(path);
- var components = split(rel);
// Only return a relative path if it's actually shorter than the absolute
// path. This avoids ugly things like long "../" chains to get to the root
@@ -544,7 +549,8 @@
// Show the arguments.
var message = new StringBuffer();
message.write("$method(");
- message.write(args.take(numArgs)
+ message.write(args
+ .take(numArgs)
.map((arg) => arg == null ? "null" : '"$arg"')
.join(", "));
message.write("): part ${i - 1} was null, but part $i was not.");
diff --git a/lib/src/parsed_path.dart b/lib/src/parsed_path.dart
index a7b0afd..b853eb1 100644
--- a/lib/src/parsed_path.dart
+++ b/lib/src/parsed_path.dart
@@ -41,8 +41,6 @@
bool get isAbsolute => root != null;
factory ParsedPath.parse(String path, InternalStyle style) {
- var before = path;
-
// Remove the root prefix, if any.
var root = style.getRoot(path);
var isRootRelative = style.isRootRelative(path);
@@ -78,8 +76,8 @@
return new ParsedPath._(style, root, isRootRelative, parts, separators);
}
- ParsedPath._(this.style, this.root, this.isRootRelative, this.parts,
- this.separators);
+ ParsedPath._(
+ this.style, this.root, this.isRootRelative, this.parts, this.separators);
String get basename {
var copy = this.clone();
@@ -134,9 +132,9 @@
// Canonicalize separators.
var newSeparators = new List.generate(
newParts.length, (_) => style.separator, growable: true);
- newSeparators.insert(0,
- isAbsolute && newParts.length > 0 && style.needsSeparator(root) ?
- style.separator : '');
+ newSeparators.insert(0, isAbsolute &&
+ newParts.length > 0 &&
+ style.needsSeparator(root) ? style.separator : '');
parts = newParts;
separators = newSeparators;
@@ -180,8 +178,6 @@
return [file.substring(0, lastDot), file.substring(lastDot)];
}
- ParsedPath clone() => new ParsedPath._(
- style, root, isRootRelative,
+ ParsedPath clone() => new ParsedPath._(style, root, isRootRelative,
new List.from(parts), new List.from(separators));
}
-
diff --git a/lib/src/style/url.dart b/lib/src/style/url.dart
index d5d0fdb..255f22a 100644
--- a/lib/src/style/url.dart
+++ b/lib/src/style/url.dart
@@ -6,7 +6,6 @@
import '../characters.dart' as chars;
import '../internal_style.dart';
-import '../utils.dart';
/// The style for URL paths.
class UrlStyle extends InternalStyle {
@@ -19,8 +18,8 @@
// Deprecated properties.
final separatorPattern = new RegExp(r'/');
- final needsSeparatorPattern = new RegExp(
- r"(^[a-zA-Z][-+.a-zA-Z\d]*://|[^/])$");
+ final needsSeparatorPattern =
+ new RegExp(r"(^[a-zA-Z][-+.a-zA-Z\d]*://|[^/])$");
final rootPattern = new RegExp(r"[a-zA-Z][-+.a-zA-Z\d]*://[^/]*");
final relativeRootPattern = new RegExp(r"^/");
diff --git a/lib/src/style/windows.dart b/lib/src/style/windows.dart
index 16e14d5..f38efa5 100644
--- a/lib/src/style/windows.dart
+++ b/lib/src/style/windows.dart
@@ -38,7 +38,7 @@
if (path.isEmpty) return 0;
if (path.codeUnitAt(0) == chars.SLASH) return 1;
if (path.codeUnitAt(0) == chars.BACKSLASH) {
- if (path.length < 2 || path.codeUnitAt(1) != chars.BACKSLASH) return 1;
+ if (path.length < 2 || path.codeUnitAt(1) != chars.BACKSLASH) return 1;
// The path is a network share. Search for up to two '\'s, as they are
// the server and share - and part of the root part.
var index = path.indexOf('\\', 2);
@@ -101,8 +101,8 @@
parsed.parts.add("");
}
- return new Uri(scheme: 'file', host: rootParts.first,
- pathSegments: parsed.parts);
+ return new Uri(
+ scheme: 'file', host: rootParts.first, pathSegments: parsed.parts);
} else {
// Drive-letter paths become "file:///C:/path/to/file".
@@ -116,8 +116,8 @@
// Get rid of the trailing "\" in "C:\" because the URI constructor will
// add a separator on its own.
- parsed.parts.insert(0,
- parsed.root.replaceAll("/", "").replaceAll("\\", ""));
+ parsed.parts.insert(
+ 0, parsed.root.replaceAll("/", "").replaceAll("\\", ""));
return new Uri(scheme: 'file', pathSegments: parsed.parts);
}
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index 0636261..e320749 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -10,7 +10,7 @@
/// lowercase).
bool isAlphabetic(int char) =>
(char >= chars.UPPER_A && char <= chars.UPPER_Z) ||
- (char >= chars.LOWER_A && char <= chars.LOWER_Z);
+ (char >= chars.LOWER_A && char <= chars.LOWER_Z);
/// Returns whether [char] is the code for an ASCII digit.
bool isNumeric(int char) => char >= chars.ZERO && char <= chars.NINE;
diff --git a/test/browser_test.dart b/test/browser_test.dart
index d8584a4..0b56c7a 100644
--- a/test/browser_test.dart
+++ b/test/browser_test.dart
@@ -15,7 +15,7 @@
test('uses the window location if root and style are omitted', () {
var context = new path.Context();
expect(context.current,
- Uri.parse(window.location.href).resolve('.').toString());
+ Uri.parse(window.location.href).resolve('.').toString());
});
test('uses "." if root is omitted', () {
@@ -34,7 +34,7 @@
});
test('current', () {
- expect(path.current,
- Uri.parse(window.location.href).resolve('.').toString());
+ expect(
+ path.current, Uri.parse(window.location.href).resolve('.').toString());
});
}
diff --git a/test/io_test.dart b/test/io_test.dart
index 5663920..e855522 100644
--- a/test/io_test.dart
+++ b/test/io_test.dart
@@ -41,8 +41,8 @@
var dir = io.Directory.current.path;
try {
expect(path.absolute('foo/bar'), equals(path.join(dir, 'foo/bar')));
- expect(path.absolute('foo/bar'),
- equals(path.context.join(dir, 'foo/bar')));
+ expect(
+ path.absolute('foo/bar'), equals(path.context.join(dir, 'foo/bar')));
io.Directory.current = path.dirname(dir);
expect(path.normalize(path.absolute('foo/bar')),
diff --git a/test/posix_test.dart b/test/posix_test.dart
index e6aaba4..25e3419 100644
--- a/test/posix_test.dart
+++ b/test/posix_test.dart
@@ -10,8 +10,8 @@
import 'utils.dart';
main() {
- var context = new path.Context(
- style: path.Style.posix, current: '/root/path');
+ var context =
+ new path.Context(style: path.Style.posix, current: '/root/path');
test('separator', () {
expect(context.separator, '/');
@@ -184,7 +184,7 @@
test('join does not modify internal ., .., or trailing separators', () {
expect(context.join('a/', 'b/c/'), 'a/b/c/');
expect(context.join('a/b/./c/..//', 'd/.././..//e/f//'),
- 'a/b/./c/..//d/.././..//e/f//');
+ 'a/b/./c/..//d/.././..//e/f//');
expect(context.join('a/b', 'c/../../../..'), 'a/b/c/../../../..');
expect(context.join('a', 'b${context.separator}'), 'a/b/');
});
@@ -245,7 +245,7 @@
expect(context.normalize(r'C:\'), r'C:\');
expect(context.normalize(r'\\'), r'\\');
expect(context.normalize('a/./\xc5\u0bf8-;\u{1f085}\u{00}/c/d/../'),
- 'a/\xc5\u0bf8-;\u{1f085}\u{00}/c');
+ 'a/\xc5\u0bf8-;\u{1f085}\u{00}/c');
});
test('collapses redundant separators', () {
@@ -392,12 +392,12 @@
});
test('with a root parameter and a relative root', () {
- var r = new path.Context(
- style: path.Style.posix, current: 'relative/root');
+ var r =
+ new path.Context(style: path.Style.posix, current: 'relative/root');
expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
expect(() => r.relative('..', from: '/foo/bar'), throwsPathException);
- expect(r.relative('/foo/bar/baz', from: 'foo/bar'),
- equals('/foo/bar/baz'));
+ expect(
+ r.relative('/foo/bar/baz', from: 'foo/bar'), equals('/foo/bar/baz'));
expect(r.relative('..', from: 'foo/bar'), equals('../../..'));
});
@@ -449,8 +449,8 @@
test('ignores parts before an absolute path', () {
expect(context.absolute('a', '/b', '/c', 'd'), '/c/d');
- expect(context.absolute('a', r'c:\b', 'c', 'd'),
- r'/root/path/a/c:\b/c/d');
+ expect(
+ context.absolute('a', r'c:\b', 'c', 'd'), r'/root/path/a/c:\b/c/d');
expect(context.absolute('a', r'\\b', 'c', 'd'), r'/root/path/a/\\b/c/d');
});
});
@@ -477,8 +477,8 @@
group('fromUri', () {
test('with a URI', () {
expect(context.fromUri(Uri.parse('file:///path/to/foo')), '/path/to/foo');
- expect(context.fromUri(Uri.parse('file:///path/to/foo/')),
- '/path/to/foo/');
+ expect(
+ context.fromUri(Uri.parse('file:///path/to/foo/')), '/path/to/foo/');
expect(context.fromUri(Uri.parse('file:///')), '/');
expect(context.fromUri(Uri.parse('foo/bar')), 'foo/bar');
expect(context.fromUri(Uri.parse('/path/to/foo')), '/path/to/foo');
diff --git a/test/relative_test.dart b/test/relative_test.dart
index 58163d2..4523c8d 100644
--- a/test/relative_test.dart
+++ b/test/relative_test.dart
@@ -13,16 +13,16 @@
test("test relative", () {
relativeTest(new path.Context(style: path.Style.posix, current: '.'), '/');
relativeTest(new path.Context(style: path.Style.posix, current: '/'), '/');
- relativeTest(new path.Context(style: path.Style.windows, current: r'd:\'),
- r'c:\');
- relativeTest(new path.Context(style: path.Style.windows, current: '.'),
- r'c:\');
+ relativeTest(
+ new path.Context(style: path.Style.windows, current: r'd:\'), r'c:\');
+ relativeTest(
+ new path.Context(style: path.Style.windows, current: '.'), r'c:\');
relativeTest(new path.Context(style: path.Style.url, current: 'file:///'),
- 'http://myserver/');
+ 'http://myserver/');
relativeTest(new path.Context(style: path.Style.url, current: '.'),
- 'http://myserver/');
- relativeTest(new path.Context(style: path.Style.url, current: 'file:///'),
- '/');
+ 'http://myserver/');
+ relativeTest(
+ new path.Context(style: path.Style.url, current: 'file:///'), '/');
relativeTest(new path.Context(style: path.Style.url, current: '.'), '/');
});
}
@@ -78,10 +78,9 @@
// Should always throw - no relative path can be constructed.
if (isRelative) {
expect(() => context.relative('.', from: '..'), throwsPathException);
- expect(() => context.relative('a/b', from: '../../d'),
- throwsPathException);
+ expect(() => context.relative('a/b', from: '../../d'), throwsPathException);
expect(() => context.relative('a/b', from: '${prefix}a/b'),
- throwsPathException);
+ throwsPathException);
// An absolute path relative from a relative path returns the absolute path.
expectRelative('${prefix}a/b', '${prefix}a/b', 'c/d');
}
diff --git a/test/url_test.dart b/test/url_test.dart
index 3f7e6fe..aca161b 100644
--- a/test/url_test.dart
+++ b/test/url_test.dart
@@ -6,8 +6,8 @@
import 'package:path/path.dart' as path;
main() {
- var context = new path.Context(style: path.Style.url,
- current: 'http://dartlang.org/root/path');
+ var context = new path.Context(
+ style: path.Style.url, current: 'http://dartlang.org/root/path');
test('separator', () {
expect(context.separator, '/');
@@ -28,8 +28,8 @@
expect(context.rootPrefix(''), '');
expect(context.rootPrefix('a'), '');
expect(context.rootPrefix('a/b'), '');
- expect(context.rootPrefix('http://dartlang.org/a/c'),
- 'http://dartlang.org');
+ expect(
+ context.rootPrefix('http://dartlang.org/a/c'), 'http://dartlang.org');
expect(context.rootPrefix('file:///a/c'), 'file://');
expect(context.rootPrefix('/a/c'), '/');
expect(context.rootPrefix('http://dartlang.org/'), 'http://dartlang.org');
@@ -246,7 +246,7 @@
test('Join does not modify internal ., .., or trailing separators', () {
expect(context.join('a/', 'b/c/'), 'a/b/c/');
expect(context.join('a/b/./c/..//', 'd/.././..//e/f//'),
- 'a/b/./c/..//d/.././..//e/f//');
+ 'a/b/./c/..//d/.././..//e/f//');
expect(context.join('a/b', 'c/../../../..'), 'a/b/c/../../../..');
expect(context.join('a', 'b${context.separator}'), 'a/b/');
});
@@ -265,9 +265,12 @@
expect(context.joinAll(['a', '/', 'b', 'c']), '/b/c');
expect(context.joinAll(['a', '/b', 'http://dartlang.org/c', 'd']),
'http://dartlang.org/c/d');
- expect(context.joinAll(
- ['a', 'http://google.com/b', 'http://dartlang.org/c', 'd']),
- 'http://dartlang.org/c/d');
+ expect(context.joinAll([
+ 'a',
+ 'http://google.com/b',
+ 'http://dartlang.org/c',
+ 'd'
+ ]), 'http://dartlang.org/c/d');
expect(context.joinAll(['a', '/b', '/c', 'd']), '/c/d');
expect(context.joinAll(['a', r'c:\b', 'c', 'd']), r'a/c:\b/c/d');
expect(context.joinAll(['a', r'\\b', 'c', 'd']), r'a/\\b/c/d');
@@ -334,7 +337,7 @@
expect(context.normalize(r'C:\'), r'C:\');
expect(context.normalize(r'\\'), r'\\');
expect(context.normalize('a/./\xc5\u0bf8-;\u{1f085}\u{00}/c/d/../'),
- 'a/\xc5\u0bf8-;\u{1f085}\u{00}/c');
+ 'a/\xc5\u0bf8-;\u{1f085}\u{00}/c');
});
test('collapses redundant separators', () {
@@ -351,8 +354,8 @@
expect(context.normalize('http://dartlang.org/.'), 'http://dartlang.org');
expect(context.normalize('file:///.'), 'file://');
expect(context.normalize('/.'), '/');
- expect(context.normalize('http://dartlang.org/./'),
- 'http://dartlang.org');
+ expect(
+ context.normalize('http://dartlang.org/./'), 'http://dartlang.org');
expect(context.normalize('file:///./'), 'file://');
expect(context.normalize('/./'), '/');
expect(context.normalize('./.'), '.');
@@ -368,8 +371,8 @@
expect(context.normalize('../'), '..');
expect(context.normalize('../../..'), '../../..');
expect(context.normalize('../../../'), '../../..');
- expect(context.normalize('http://dartlang.org/..'),
- 'http://dartlang.org');
+ expect(
+ context.normalize('http://dartlang.org/..'), 'http://dartlang.org');
expect(context.normalize('file:///..'), 'file://');
expect(context.normalize('/..'), '/');
expect(context.normalize('http://dartlang.org/../../..'),
@@ -395,10 +398,10 @@
test('does not walk before root on absolute paths', () {
expect(context.normalize('..'), '..');
expect(context.normalize('../'), '..');
- expect(context.normalize('http://dartlang.org/..'),
- 'http://dartlang.org');
+ expect(
+ context.normalize('http://dartlang.org/..'), 'http://dartlang.org');
expect(context.normalize('http://dartlang.org/../a'),
- 'http://dartlang.org/a');
+ 'http://dartlang.org/a');
expect(context.normalize('file:///..'), 'file://');
expect(context.normalize('file:///../a'), 'file:///a');
expect(context.normalize('/..'), '/');
@@ -441,8 +444,8 @@
expect(context.relative('http://dartlang.org/root/path/a/b.txt'),
'a/b.txt');
expect(context.relative('/root/path/a/b.txt'), 'a/b.txt');
- expect(context.relative('http://dartlang.org/root/a/b.txt'),
- '../a/b.txt');
+ expect(
+ context.relative('http://dartlang.org/root/a/b.txt'), '../a/b.txt');
expect(context.relative('/root/a/b.txt'), '../a/b.txt');
});
@@ -455,15 +458,14 @@
'a/b.txt');
expect(context.relative('http://dartlang.org/root/path/a/b.txt'),
'a/b.txt');
- expect(context.relative('http://dartlang.org/root/a/b.txt'),
- '../a/b.txt');
+ expect(
+ context.relative('http://dartlang.org/root/a/b.txt'), '../a/b.txt');
});
test('given absolute path with different hostname/protocol', () {
expect(context.relative(r'http://google.com/a/b'),
r'http://google.com/a/b');
- expect(context.relative(r'file:///a/b'),
- r'file:///a/b');
+ expect(context.relative(r'file:///a/b'), r'file:///a/b');
});
test('given relative path', () {
@@ -480,11 +482,9 @@
// Regression
test('from root-only path', () {
expect(context.relative('http://dartlang.org',
- from: 'http://dartlang.org'),
- '.');
+ from: 'http://dartlang.org'), '.');
expect(context.relative('http://dartlang.org/root/path',
- from: 'http://dartlang.org'),
- 'root/path');
+ from: 'http://dartlang.org'), 'root/path');
});
});
@@ -552,15 +552,12 @@
context.relative('http://dartlang.org/foo/bar/baz', from: '/foo/bar'),
equals('baz'));
expect(context.relative('http://dartlang.org/foo/bar/baz',
- from: 'file:///foo/bar'),
- equals('http://dartlang.org/foo/bar/baz'));
+ from: 'file:///foo/bar'), equals('http://dartlang.org/foo/bar/baz'));
expect(context.relative('http://dartlang.org/foo/bar/baz',
from: 'http://dartlang.org/foo/bar'), equals('baz'));
- expect(
- context.relative('/foo/bar/baz', from: 'file:///foo/bar'),
+ expect(context.relative('/foo/bar/baz', from: 'file:///foo/bar'),
equals('http://dartlang.org/foo/bar/baz'));
- expect(
- context.relative('file:///foo/bar/baz', from: '/foo/bar'),
+ expect(context.relative('file:///foo/bar/baz', from: '/foo/bar'),
equals('file:///foo/bar/baz'));
expect(context.relative('..', from: '/foo/bar'), equals('../../root'));
@@ -570,8 +567,8 @@
equals('http://dartlang.org/root'));
expect(context.relative('..', from: '/foo/bar'), equals('../../root'));
- expect(context.relative('http://dartlang.org/foo/bar/baz',
- from: 'foo/bar'),
+ expect(
+ context.relative('http://dartlang.org/foo/bar/baz', from: 'foo/bar'),
equals('../../../../foo/bar/baz'));
expect(context.relative('file:///foo/bar/baz', from: 'foo/bar'),
equals('file:///foo/bar/baz'));
@@ -584,15 +581,12 @@
test('with a root parameter and a relative root', () {
var r = new path.Context(style: path.Style.url, current: 'relative/root');
expect(r.relative('/foo/bar/baz', from: '/foo/bar'), equals('baz'));
- expect(
- r.relative('/foo/bar/baz', from: 'http://dartlang.org/foo/bar'),
+ expect(r.relative('/foo/bar/baz', from: 'http://dartlang.org/foo/bar'),
equals('/foo/bar/baz'));
- expect(
- r.relative('http://dartlang.org/foo/bar/baz', from: '/foo/bar'),
+ expect(r.relative('http://dartlang.org/foo/bar/baz', from: '/foo/bar'),
equals('http://dartlang.org/foo/bar/baz'));
expect(r.relative('http://dartlang.org/foo/bar/baz',
- from: 'file:///foo/bar'),
- equals('http://dartlang.org/foo/bar/baz'));
+ from: 'file:///foo/bar'), equals('http://dartlang.org/foo/bar/baz'));
expect(r.relative('http://dartlang.org/foo/bar/baz',
from: 'http://dartlang.org/foo/bar'), equals('baz'));
@@ -600,8 +594,8 @@
equals('http://dartlang.org/foo/bar/baz'));
expect(r.relative('file:///foo/bar/baz', from: 'foo/bar'),
equals('file:///foo/bar/baz'));
- expect(r.relative('/foo/bar/baz', from: 'foo/bar'),
- equals('/foo/bar/baz'));
+ expect(
+ r.relative('/foo/bar/baz', from: 'foo/bar'), equals('/foo/bar/baz'));
expect(r.relative('..', from: 'foo/bar'), equals('../../..'));
});
@@ -623,11 +617,9 @@
expect(context.isWithin('foo/bar', 'foo/baz'), isFalse);
expect(context.isWithin('foo/bar', '../path/foo/bar/baz'), isTrue);
expect(context.isWithin(
- 'http://dartlang.org', 'http://dartlang.org/foo/bar'),
- isTrue);
+ 'http://dartlang.org', 'http://dartlang.org/foo/bar'), isTrue);
expect(context.isWithin(
- 'http://dartlang.org', 'http://pub.dartlang.org/foo/bar'),
- isFalse);
+ 'http://dartlang.org', 'http://pub.dartlang.org/foo/bar'), isFalse);
expect(context.isWithin('http://dartlang.org', '/foo/bar'), isTrue);
expect(context.isWithin('http://dartlang.org/foo', '/foo/bar'), isTrue);
expect(context.isWithin('http://dartlang.org/foo', '/bar/baz'), isFalse);
@@ -642,8 +634,8 @@
expect(r.isWithin('.', 'a/b/c'), isTrue);
expect(r.isWithin('.', '../a/b/c'), isFalse);
expect(r.isWithin('.', '../../a/foo/b/c'), isFalse);
- expect(r.isWithin(
- 'http://dartlang.org/', 'http://dartlang.org/baz/bang'), isTrue);
+ expect(r.isWithin('http://dartlang.org/', 'http://dartlang.org/baz/bang'),
+ isTrue);
expect(r.isWithin('.', 'http://dartlang.org/baz/bang'), isFalse);
});
});
@@ -667,8 +659,8 @@
test('does not add separator if a part ends in one', () {
expect(context.absolute('a/', 'b', 'c/', 'd'),
'http://dartlang.org/root/path/a/b/c/d');
- expect(context.absolute(r'a\', 'b'),
- r'http://dartlang.org/root/path/a\/b');
+ expect(
+ context.absolute(r'a\', 'b'), r'http://dartlang.org/root/path/a\/b');
});
test('ignores parts before an absolute path', () {
@@ -709,8 +701,8 @@
expect(context.fromUri(Uri.parse('file:///path/to/foo')),
'file:///path/to/foo');
expect(context.fromUri(Uri.parse('foo/bar')), 'foo/bar');
- expect(context.fromUri(
- Uri.parse('http://dartlang.org/path/to/foo%23bar')),
+ expect(
+ context.fromUri(Uri.parse('http://dartlang.org/path/to/foo%23bar')),
'http://dartlang.org/path/to/foo%23bar');
// Since the resulting "path" is also a URL, special characters should
// remain percent-encoded in the result.
@@ -729,8 +721,8 @@
Uri.parse('http://dartlang.org/path/to/foo'));
expect(context.toUri('http://dartlang.org/path/to/foo/'),
Uri.parse('http://dartlang.org/path/to/foo/'));
- expect(context.toUri('file:///path/to/foo'),
- Uri.parse('file:///path/to/foo'));
+ expect(
+ context.toUri('file:///path/to/foo'), Uri.parse('file:///path/to/foo'));
expect(context.toUri('foo/bar'), Uri.parse('foo/bar'));
expect(context.toUri('http://dartlang.org/path/to/foo%23bar'),
Uri.parse('http://dartlang.org/path/to/foo%23bar'));
@@ -755,8 +747,7 @@
'http://dartlang.org/other/path/a/b');
expect(context.prettyUri('http://pub.dartlang.org/root/path'),
'http://pub.dartlang.org/root/path');
- expect(context.prettyUri('http://dartlang.org/root/other'),
- '../other');
+ expect(context.prettyUri('http://dartlang.org/root/other'), '../other');
});
test('with a relative URI', () {
diff --git a/test/windows_test.dart b/test/windows_test.dart
index 1f5dc38..a174305 100644
--- a/test/windows_test.dart
+++ b/test/windows_test.dart
@@ -10,8 +10,8 @@
import 'utils.dart';
main() {
- var context = new path.Context(style: path.Style.windows,
- current: r'C:\root\path');
+ var context =
+ new path.Context(style: path.Style.windows, current: r'C:\root\path');
group('separator', () {
expect(context.separator, '\\');
@@ -247,7 +247,7 @@
test('join does not modify internal ., .., or trailing separators', () {
expect(context.join('a/', 'b/c/'), 'a/b/c/');
expect(context.join(r'a\b\./c\..\\', r'd\..\.\..\\e\f\\'),
- r'a\b\./c\..\\d\..\.\..\\e\f\\');
+ r'a\b\./c\..\\d\..\.\..\\e\f\\');
expect(context.join(r'a\b', r'c\..\..\..\..'), r'a\b\c\..\..\..\..');
expect(context.join(r'a', 'b${context.separator}'), r'a\b\');
});
@@ -301,8 +301,8 @@
equals([r'\\server\share', 'foo', 'bar', 'baz']));
expect(context.split(r'\\server\share'), equals([r'\\server\share']));
- expect(context.split(r'\foo\bar\baz'),
- equals([r'\', 'foo', 'bar', 'baz']));
+ expect(
+ context.split(r'\foo\bar\baz'), equals([r'\', 'foo', 'bar', 'baz']));
expect(context.split(r'\'), equals([r'\']));
});
});
@@ -321,7 +321,7 @@
expect(context.normalize(r'C:\'), r'C:\');
expect(context.normalize(r'\\server\share'), r'\\server\share');
expect(context.normalize('a\\.\\\xc5\u0bf8-;\u{1f085}\u{00}\\c\\d\\..\\'),
- 'a\\\xc5\u0bf8-;\u{1f085}\u{00}\x5cc');
+ 'a\\\xc5\u0bf8-;\u{1f085}\u{00}\x5cc');
});
test('collapses redundant separators', () {
@@ -350,8 +350,8 @@
expect(context.normalize(r'..\..\..'), r'..\..\..');
expect(context.normalize(r'../..\..\'), r'..\..\..');
expect(context.normalize(r'\\server\share\..'), r'\\server\share');
- expect(context.normalize(r'\\server\share\..\../..\a'),
- r'\\server\share\a');
+ expect(
+ context.normalize(r'\\server\share\..\../..\a'), r'\\server\share\a');
expect(context.normalize(r'c:\..'), r'c:\');
expect(context.normalize(r'A:/..\..\..'), r'A:\');
expect(context.normalize(r'b:\..\..\..\a'), r'b:\a');
@@ -483,16 +483,16 @@
});
test('from a root with extension', () {
- var r = new path.Context(
- style: path.Style.windows, current: r'C:\dir.ext');
+ var r =
+ new path.Context(style: path.Style.windows, current: r'C:\dir.ext');
expect(r.relative(r'C:\dir.ext\file'), 'file');
});
test('with a root parameter', () {
expect(context.relative(r'C:\foo\bar\baz', from: r'C:\foo\bar'),
equals('baz'));
- expect(context.relative('..', from: r'C:\foo\bar'),
- equals(r'..\..\root'));
+ expect(
+ context.relative('..', from: r'C:\foo\bar'), equals(r'..\..\root'));
expect(context.relative('..', from: r'D:\foo\bar'), equals(r'C:\root'));
expect(context.relative(r'C:\foo\bar\baz', from: r'foo\bar'),
equals(r'..\..\..\..\foo\bar\baz'));
@@ -553,8 +553,8 @@
expect(context.absolute('a', 'b'), r'C:\root\path\a\b');
expect(context.absolute('a', 'b', 'c'), r'C:\root\path\a\b\c');
expect(context.absolute('a', 'b', 'c', 'd'), r'C:\root\path\a\b\c\d');
- expect(context.absolute('a', 'b', 'c', 'd', 'e'),
- r'C:\root\path\a\b\c\d\e');
+ expect(
+ context.absolute('a', 'b', 'c', 'd', 'e'), r'C:\root\path\a\b\c\d\e');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f'),
r'C:\root\path\a\b\c\d\e\f');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g'),
@@ -600,18 +600,18 @@
expect(context.fromUri(Uri.parse('file://server/share/path/to/foo')),
r'\\server\share\path\to\foo');
expect(context.fromUri(Uri.parse('file:///C:/')), r'C:\');
- expect(context.fromUri(Uri.parse('file://server/share')),
- r'\\server\share');
+ expect(
+ context.fromUri(Uri.parse('file://server/share')), r'\\server\share');
expect(context.fromUri(Uri.parse('foo/bar')), r'foo\bar');
expect(context.fromUri(Uri.parse('/C:/path/to/foo')), r'C:\path\to\foo');
- expect(context.fromUri(Uri.parse('///C:/path/to/foo')),
- r'C:\path\to\foo');
+ expect(
+ context.fromUri(Uri.parse('///C:/path/to/foo')), r'C:\path\to\foo');
expect(context.fromUri(Uri.parse('//server/share/path/to/foo')),
r'\\server\share\path\to\foo');
expect(context.fromUri(Uri.parse('file:///C:/path/to/foo%23bar')),
r'C:\path\to\foo#bar');
- expect(context.fromUri(
- Uri.parse('file://server/share/path/to/foo%23bar')),
+ expect(
+ context.fromUri(Uri.parse('file://server/share/path/to/foo%23bar')),
r'\\server\share\path\to\foo#bar');
expect(context.fromUri(Uri.parse('_%7B_%7D_%60_%5E_%20_%22_%25_')),
r'_{_}_`_^_ _"_%_');
@@ -625,14 +625,14 @@
});
test('toUri', () {
- expect(context.toUri(r'C:\path\to\foo'),
- Uri.parse('file:///C:/path/to/foo'));
+ expect(
+ context.toUri(r'C:\path\to\foo'), Uri.parse('file:///C:/path/to/foo'));
expect(context.toUri(r'C:\path\to\foo\'),
Uri.parse('file:///C:/path/to/foo/'));
expect(context.toUri(r'C:\'), Uri.parse('file:///C:/'));
expect(context.toUri(r'\\server\share'), Uri.parse('file://server/share'));
- expect(context.toUri(r'\\server\share\'),
- Uri.parse('file://server/share/'));
+ expect(
+ context.toUri(r'\\server\share\'), Uri.parse('file://server/share/'));
expect(context.toUri(r'foo\bar'), Uri.parse('foo/bar'));
expect(context.toUri(r'C:\path\to\foo#bar'),
Uri.parse('file:///C:/path/to/foo%23bar'));
@@ -648,12 +648,11 @@
test('with a file: URI', () {
expect(context.prettyUri('file:///C:/root/path/a/b'), r'a\b');
expect(context.prettyUri('file:///C:/root/path/a/../b'), r'b');
- expect(context.prettyUri('file:///C:/other/path/a/b'),
- r'C:\other\path\a\b');
- expect(context.prettyUri('file:///D:/root/path/a/b'),
- r'D:\root\path\a\b');
- expect(context.prettyUri('file:///C:/root/other'),
- r'..\other');
+ expect(
+ context.prettyUri('file:///C:/other/path/a/b'), r'C:\other\path\a\b');
+ expect(
+ context.prettyUri('file:///D:/root/path/a/b'), r'D:\root\path\a\b');
+ expect(context.prettyUri('file:///C:/root/other'), r'..\other');
});
test('with an http: URI', () {