From c2e5432dacae04fdcfe67c55a3d7de4adc3656ae Mon Sep 17 00:00:00 2001 From: Jens Hatlak Date: Fri, 25 Oct 2024 13:30:16 +0200 Subject: [PATCH] Add more non-namespaced package test cases --- tests/src/Unit/ParserTest.php | 75 ++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/tests/src/Unit/ParserTest.php b/tests/src/Unit/ParserTest.php index 3db6083..edc245f 100644 --- a/tests/src/Unit/ParserTest.php +++ b/tests/src/Unit/ParserTest.php @@ -221,35 +221,62 @@ public function testYarnExampleArray() * The parser should split the package name and version parts * * Scoped packages names (prefixed with @) and Git version references should be detected properly. + * + * @param string $versionString + * @param array{string, string} $expectedResult + * @dataProvider provideVersionsForSplitting + * @return void */ - public function testVersionSplitting() + public function testVersionSplitting($versionString, array $expectedResult) { - static::assertSame( - ['gulp-sourcemaps', '2.6.4'], - Parser::splitVersionString('gulp-sourcemaps@2.6.4') - ); - - static::assertSame( - ['@gulp-sourcemaps/identity-map', '1.X'], - Parser::splitVersionString('@gulp-sourcemaps/identity-map@1.X') - ); - - static::assertSame( - ['@foo/bar', 'git+ssh://user@host:1234/foo/bar#semver:^1.2.3'], - Parser::splitVersionString('@foo/bar@git+ssh://user@host:1234/foo/bar#semver:^1.2.3') - ); - - static::assertSame( - ['@foo/bar', 'git://user@host/foo/bar.git#v1.2.3'], - Parser::splitVersionString('@foo/bar@git://user@host/foo/bar.git#v1.2.3') - ); + self::assertSame($expectedResult, Parser::splitVersionString($versionString)); + } - static::assertSame( - ['@foo/bar', 'file:vendor/foo/bar'], - Parser::splitVersionString('@foo/bar@file:vendor/foo/bar') - ); + /** + * @return array + */ + public static function provideVersionsForSplitting(): array + { + return [ + 'simple package, simple version' => [ + 'versionString' => 'gulp-sourcemaps@2.6.4', + 'expectedResult' => ['gulp-sourcemaps', '2.6.4'], + ], + 'namespaced package, simple version' => [ + 'versionString' => '@gulp-sourcemaps/identity-map@1.X', + 'expectedResult' => ['@gulp-sourcemaps/identity-map', '1.X'], + ], + 'simple package, Git semver reference' => [ + 'versionString' => 'foo-bar@git+ssh://user@host:1234/foo/bar#semver:^1.2.3', + 'expectedResult' => ['foo-bar', 'git+ssh://user@host:1234/foo/bar#semver:^1.2.3'], + ], + 'namespaced package, Git semver reference' => [ + 'versionString' => '@foo/bar@git+ssh://user@host:1234/foo/bar#semver:^1.2.3', + 'expectedResult' => ['@foo/bar', 'git+ssh://user@host:1234/foo/bar#semver:^1.2.3'], + ], + 'simple package, Git tag reference' => [ + 'versionString' => 'foo-bar@git://user@host/foo/bar.git#v1.2.3', + 'expectedResult' => ['foo-bar', 'git://user@host/foo/bar.git#v1.2.3'], + ], + 'namespaced package, Git tag reference' => [ + 'versionString' => '@foo/bar@git://user@host/foo/bar.git#v1.2.3', + 'expectedResult' => ['@foo/bar', 'git://user@host/foo/bar.git#v1.2.3'], + ], + 'simple package, file reference' => [ + 'versionString' => 'foo-bar@file:vendor/foo/bar', + 'expectedResult' => ['foo-bar', 'file:vendor/foo/bar'], + ], + 'namespaced package, file reference' => [ + 'versionString' => '@foo/bar@file:vendor/foo/bar', + 'expectedResult' => ['@foo/bar', 'file:vendor/foo/bar'], + ], + ]; } + /** * Single-value keys should not be split at spaces if they are surrounded with quotes * @throws ParserException