Skip to content

Commit

Permalink
Add more non-namespaced package test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jhatlak committed Oct 25, 2024
1 parent 3e6914a commit c2e5432
Showing 1 changed file with 51 additions and 24 deletions.
75 changes: 51 additions & 24 deletions tests/src/Unit/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]')
);

static::assertSame(
['@gulp-sourcemaps/identity-map', '1.X'],
Parser::splitVersionString('@gulp-sourcemaps/[email protected]')
);

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<string, array{
* versionString: string,
* expectedResult: array{string, string}
* }>
*/
public static function provideVersionsForSplitting(): array
{
return [
'simple package, simple version' => [
'versionString' => '[email protected]',
'expectedResult' => ['gulp-sourcemaps', '2.6.4'],
],
'namespaced package, simple version' => [
'versionString' => '@gulp-sourcemaps/[email protected]',
'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
Expand Down

0 comments on commit c2e5432

Please sign in to comment.