Skip to content

Commit

Permalink
Supports more arguments in path.join API
Browse files Browse the repository at this point in the history
  • Loading branch information
hellohuanlin committed Nov 11, 2022
1 parent 58ba22c commit fd0a68f
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 21 deletions.
26 changes: 22 additions & 4 deletions lib/path.dart
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,
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
20 changes: 18 additions & 2 deletions lib/src/context.dart
Expand Up @@ -228,7 +228,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 +245,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
42 changes: 37 additions & 5 deletions test/posix_test.dart
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,22 @@ 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 +209,9 @@ 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 +509,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 +519,22 @@ 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
42 changes: 37 additions & 5 deletions test/url_test.dart
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,22 @@ 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 +301,9 @@ 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 +779,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 +792,22 @@ 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', 'j'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j/k');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j/k/l');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j/k/l/m');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j/k/l/m/n');
expect(context.absolute('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'o'),
'https://dart.dev/root/path/a/b/c/d/e/f/g/h/j/k/l/m/n/o');
});

test('does not add separator if a part ends in one', () {
Expand Down
42 changes: 37 additions & 5 deletions test/windows_test.dart
Expand Up @@ -205,7 +205,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'), r'a\b');
expect(context.join('a', 'b', 'c'), r'a\b\c');
Expand All @@ -215,6 +215,22 @@ void main() {
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g'), r'a\b\c\d\e\f\g');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'),
r'a\b\c\d\e\f\g\h');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'),
r'a\b\c\d\e\f\g\h\i');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'),
r'a\b\c\d\e\f\g\h\i\j');
expect(context.join('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'),
r'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'),
r'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'),
r'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'),
r'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'),
r'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'),
r'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 or begins in one', () {
Expand Down Expand Up @@ -258,9 +274,9 @@ void main() {
});

group('joinAll', () {
test('allows more than eight parts', () {
expect(context.joinAll(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']),
r'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']),
r'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 or begins in one', () {
Expand Down Expand Up @@ -644,7 +660,7 @@ void main() {
});

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

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

0 comments on commit fd0a68f

Please sign in to comment.