Skip to content

Commit

Permalink
Support more arguments in path.join API (dart-lang/path#130)
Browse files Browse the repository at this point in the history
Add additional optional positional arguments to some methods.
  • Loading branch information
hellohuanlin authored Nov 14, 2022
1 parent d7052f4 commit 0e6830d
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 26 deletions.
4 changes: 4 additions & 0 deletions pkgs/path/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.8.3

* Support up to 16 arguments in join function and up to 15 arguments in absolute function.

## 1.8.2

* Enable the `avoid_dynamic_calls` lint.
Expand Down
26 changes: 22 additions & 4 deletions pkgs/path/lib/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,17 @@ String absolute(String part1,
String? part4,
String? part5,
String? part6,
String? part7]) =>
context.absolute(part1, part2, part3, part4, part5, part6, part7);
String? part7,
String? part8,
String? part9,
String? part10,
String? part11,
String? part12,
String? part13,
String? part14,
String? part15]) =>
context.absolute(part1, part2, part3, part4, part5, part6, part7, part8,
part9, part10, part11, part12, part13, part14, part15);

/// Gets the part of [path] after the last separator.
///
Expand Down Expand Up @@ -261,8 +270,17 @@ String join(String part1,
String? part5,
String? part6,
String? part7,
String? part8]) =>
context.join(part1, part2, part3, part4, part5, part6, part7, part8);
String? part8,
String? part9,
String? part10,
String? part11,
String? part12,
String? part13,
String? part14,
String? part15,
String? part16]) =>
context.join(part1, part2, part3, part4, part5, part6, part7, part8, part9,
part10, part11, part12, part13, part14, part15, part16);

/// Joins the given path parts into a single path using the current platform's
/// [separator]. Example:
Expand Down
52 changes: 46 additions & 6 deletions pkgs/path/lib/src/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,41 @@ class Context {
String? part4,
String? part5,
String? part6,
String? part7]) {
_validateArgList(
'absolute', [part1, part2, part3, part4, part5, part6, part7]);
String? part7,
String? part8,
String? part9,
String? part10,
String? part11,
String? part12,
String? part13,
String? part14,
String? part15]) {
_validateArgList('absolute', [
part1,
part2,
part3,
part4,
part5,
part6,
part7,
part8,
part9,
part10,
part11,
part12,
part13,
part14,
part15
]);

// If there's a single absolute path, just return it. This is a lot faster
// for the common case of `p.absolute(path)`.
if (part2 == null && isAbsolute(part1) && !isRootRelative(part1)) {
return part1;
}

return join(current, part1, part2, part3, part4, part5, part6, part7);
return join(current, part1, part2, part3, part4, part5, part6, part7, part8,
part9, part10, part11, part12, part13, part14, part15);
}

/// Gets the part of [path] after the last separator on the context's
Expand Down Expand Up @@ -228,7 +252,15 @@ class Context {
String? part5,
String? part6,
String? part7,
String? part8]) {
String? part8,
String? part9,
String? part10,
String? part11,
String? part12,
String? part13,
String? part14,
String? part15,
String? part16]) {
final parts = <String?>[
part1,
part2,
Expand All @@ -237,7 +269,15 @@ class Context {
part5,
part6,
part7,
part8
part8,
part9,
part10,
part11,
part12,
part13,
part14,
part15,
part16,
];
_validateArgList('join', parts);
return joinAll(parts.whereType<String>());
Expand Down
2 changes: 1 addition & 1 deletion pkgs/path/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: path
version: 1.8.2
version: 1.8.3
description: >-
A string-based path manipulation library. All of the path operations you know
and love, with solid support for Windows, POSIX (Linux and Mac OS X), and the
Expand Down
82 changes: 77 additions & 5 deletions pkgs/path/test/posix_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void main() {
});

group('join', () {
test('allows up to eight parts', () {
test('allows up to sixteen parts', () {
expect(context.join('a'), 'a');
expect(context.join('a', 'b'), 'a/b');
expect(context.join('a', 'b', 'c'), 'a/b/c');
Expand All @@ -152,6 +152,33 @@ void main() {
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), 'a/b/c/d/e/f/g');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
'a/b/c/d/e/f/g/h');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'),
'a/b/c/d/e/f/g/h/i');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
'a/b/c/d/e/f/g/h/i/j');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'),
'a/b/c/d/e/f/g/h/i/j/k');
expect(
context.join(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'),
'a/b/c/d/e/f/g/h/i/j/k/l');
expect(
context.join(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'),
'a/b/c/d/e/f/g/h/i/j/k/l/m');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p');
});

test('does not add separator if a part ends in one', () {
Expand Down Expand Up @@ -193,9 +220,28 @@ void main() {
});

group('joinAll', () {
test('allows more than eight parts', () {
expect(context.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']),
'a/b/c/d/e/f/g/h/i');
test('allows more than sixteen parts', () {
expect(
context.joinAll([
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q'
]),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q');
});

test('does not add separator if a part ends in one', () {
Expand Down Expand Up @@ -493,7 +539,7 @@ void main() {
});

group('absolute', () {
test('allows up to seven parts', () {
test('allows up to fifteen parts', () {
expect(context.absolute('a'), '/root/path/a');
expect(context.absolute('a', 'b'), '/root/path/a/b');
expect(context.absolute('a', 'b', 'c'), '/root/path/a/b/c');
Expand All @@ -503,6 +549,32 @@ void main() {
'/root/path/a/b/c/d/e/f');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g'),
'/root/path/a/b/c/d/e/f/g');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
'/root/path/a/b/c/d/e/f/g/h');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'),
'/root/path/a/b/c/d/e/f/g/h/i');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
'/root/path/a/b/c/d/e/f/g/h/i/j');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'),
'/root/path/a/b/c/d/e/f/g/h/i/j/k');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'),
'/root/path/a/b/c/d/e/f/g/h/i/j/k/l');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'),
'/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m');
expect(
context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n'),
'/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m/n');
expect(
context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o'),
'/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o');
});

test('does not add separator if a part ends in one', () {
Expand Down
82 changes: 77 additions & 5 deletions pkgs/path/test/url_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void main() {
});

group('join', () {
test('allows up to eight parts', () {
test('allows up to sixteen parts', () {
expect(context.join('a'), 'a');
expect(context.join('a', 'b'), 'a/b');
expect(context.join('a', 'b', 'c'), 'a/b/c');
Expand All @@ -205,6 +205,33 @@ void main() {
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), 'a/b/c/d/e/f/g');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
'a/b/c/d/e/f/g/h');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'),
'a/b/c/d/e/f/g/h/i');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
'a/b/c/d/e/f/g/h/i/j');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'),
'a/b/c/d/e/f/g/h/i/j/k');
expect(
context.join(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'),
'a/b/c/d/e/f/g/h/i/j/k/l');
expect(
context.join(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'),
'a/b/c/d/e/f/g/h/i/j/k/l/m');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o');
expect(
context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p'),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p');
});

test('does not add separator if a part ends in one', () {
Expand Down Expand Up @@ -285,9 +312,28 @@ void main() {
});

group('joinAll', () {
test('allows more than eight parts', () {
expect(context.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']),
'a/b/c/d/e/f/g/h/i');
test('allows more than sixteen parts', () {
expect(
context.joinAll([
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q'
]),
'a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q');
});

test('ignores parts before an absolute path', () {
Expand Down Expand Up @@ -763,7 +809,7 @@ void main() {
});

group('absolute', () {
test('allows up to seven parts', () {
test('allows up to fifteen parts', () {
expect(context.absolute('a'), 'https://dart.dev/root/path/a');
expect(context.absolute('a', 'b'), 'https://dart.dev/root/path/a/b');
expect(
Expand All @@ -776,6 +822,32 @@ void main() {
'https://dart.dev/root/path/a/b/c/d/e/f');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g'),
'https://dart.dev/root/path/a/b/c/d/e/f/g');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j/k');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j/k/l');
expect(
context.absolute(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m');
expect(
context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m/n');
expect(
context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o');
});

test('does not add separator if a part ends in one', () {
Expand Down
Loading

0 comments on commit 0e6830d

Please sign in to comment.