From 0e6830dfc0c4271a3dbd64b75a62120962270eb7 Mon Sep 17 00:00:00 2001 From: hellohuanlin <41930132+hellohuanlin@users.noreply.github.com> Date: Mon, 14 Nov 2022 12:21:27 -0800 Subject: [PATCH] Support more arguments in path.join API (dart-lang/path#130) Add additional optional positional arguments to some methods. --- pkgs/path/CHANGELOG.md | 4 ++ pkgs/path/lib/path.dart | 26 ++++++++-- pkgs/path/lib/src/context.dart | 52 +++++++++++++++++--- pkgs/path/pubspec.yaml | 2 +- pkgs/path/test/posix_test.dart | 82 ++++++++++++++++++++++++++++++-- pkgs/path/test/url_test.dart | 82 ++++++++++++++++++++++++++++++-- pkgs/path/test/windows_test.dart | 82 ++++++++++++++++++++++++++++++-- 7 files changed, 304 insertions(+), 26 deletions(-) diff --git a/pkgs/path/CHANGELOG.md b/pkgs/path/CHANGELOG.md index 2cf8eaea..13c285b5 100644 --- a/pkgs/path/CHANGELOG.md +++ b/pkgs/path/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. diff --git a/pkgs/path/lib/path.dart b/pkgs/path/lib/path.dart index 57f87650..98b63d8c 100644 --- a/pkgs/path/lib/path.dart +++ b/pkgs/path/lib/path.dart @@ -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. /// @@ -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: diff --git a/pkgs/path/lib/src/context.dart b/pkgs/path/lib/src/context.dart index 45376b68..3b2cc59f 100644 --- a/pkgs/path/lib/src/context.dart +++ b/pkgs/path/lib/src/context.dart @@ -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, + 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)`. @@ -90,7 +113,8 @@ class Context { 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 @@ -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 = [ part1, part2, @@ -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()); diff --git a/pkgs/path/pubspec.yaml b/pkgs/path/pubspec.yaml index 78d3cc05..7afd2d35 100644 --- a/pkgs/path/pubspec.yaml +++ b/pkgs/path/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 diff --git a/pkgs/path/test/posix_test.dart b/pkgs/path/test/posix_test.dart index cc64a541..7f1a552f 100644 --- a/pkgs/path/test/posix_test.dart +++ b/pkgs/path/test/posix_test.dart @@ -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'); @@ -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', () { @@ -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', () { @@ -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'); @@ -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', () { diff --git a/pkgs/path/test/url_test.dart b/pkgs/path/test/url_test.dart index e0b59030..53a24047 100644 --- a/pkgs/path/test/url_test.dart +++ b/pkgs/path/test/url_test.dart @@ -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'); @@ -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', () { @@ -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', () { @@ -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( @@ -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', () { diff --git a/pkgs/path/test/windows_test.dart b/pkgs/path/test/windows_test.dart index be9a790f..4036fc66 100644 --- a/pkgs/path/test/windows_test.dart +++ b/pkgs/path/test/windows_test.dart @@ -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'); @@ -215,6 +215,33 @@ 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', () { @@ -258,9 +285,28 @@ 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', () { @@ -644,7 +690,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'); @@ -655,6 +701,32 @@ 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', 'i', 'j'), + r'C:\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'), + r'C:\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'), + r'C:\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'), + r'C:\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'), + r'C:\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'), + r'C:\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', () {