Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports more arguments in path.join API #130

Merged
merged 4 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -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 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,
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
49 changes: 44 additions & 5 deletions lib/src/context.dart
Expand Up @@ -80,9 +80,32 @@ class Context {
String? part4,
String? part5,
String? part6,
String? part7]) {
_validateArgList(
'absolute', [part1, part2, part3, part4, part5, part6, part7]);
String? part7,
String? part8,
hellohuanlin marked this conversation as resolved.
Show resolved Hide resolved
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)`.
Expand Down Expand Up @@ -228,7 +251,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 +268,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 pubspec.yaml
@@ -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 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,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
80 changes: 75 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,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,30 @@ 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