@@ -218,21 +218,65 @@ public function testYarnExampleArray()
218
218
}
219
219
220
220
/**
221
- * Scoped packages names should not be split at the first '@'
221
+ * The parser should split the package name and version parts
222
+ *
223
+ * Scoped packages names (prefixed with @) and Git version references should be detected properly.
224
+ *
225
+ * @param string $versionString
226
+ * @param array{string, string} $expectedResult
227
+ * @dataProvider provideVersionsForSplitting
228
+ * @return void
222
229
*/
223
- public function testVersionSplitting ()
230
+ public function testVersionSplitting ($ versionString , array $ expectedResult )
224
231
{
225
- static ::assertSame (
226
- ['gulp-sourcemaps ' , '2.6.4 ' ],
227
- Parser::
splitVersionString (
'[email protected] ' )
228
- );
232
+ self ::assertSame ($ expectedResult , Parser::splitVersionString ($ versionString ));
233
+ }
229
234
230
- static ::assertSame (
231
- ['@gulp-sourcemaps/identity-map ' , '1.X ' ],
232
- Parser::
splitVersionString (
'@gulp-sourcemaps/[email protected] ' )
233
- );
235
+ /**
236
+ * @return array<string, array{
237
+ * versionString: string,
238
+ * expectedResult: array{string, string}
239
+ * }>
240
+ */
241
+ public static function provideVersionsForSplitting (): array
242
+ {
243
+ return [
244
+ 'simple package, simple version ' => [
245
+ 'versionString ' =>
'[email protected] ' ,
246
+ 'expectedResult ' => ['gulp-sourcemaps ' , '2.6.4 ' ],
247
+ ],
248
+ 'namespaced package, simple version ' => [
249
+ 'versionString ' =>
'@gulp-sourcemaps/[email protected] ' ,
250
+ 'expectedResult ' => ['@gulp-sourcemaps/identity-map ' , '1.X ' ],
251
+ ],
252
+ 'simple package, Git semver reference ' => [
253
+ 'versionString ' => 'foo-bar@git+ssh://user@host:1234/foo/bar#semver:^1.2.3 ' ,
254
+ 'expectedResult ' => ['foo-bar ' , 'git+ssh://user@host:1234/foo/bar#semver:^1.2.3 ' ],
255
+ ],
256
+ 'namespaced package, Git semver reference ' => [
257
+ 'versionString ' => '@foo/bar@git+ssh://user@host:1234/foo/bar#semver:^1.2.3 ' ,
258
+ 'expectedResult ' => ['@foo/bar ' , 'git+ssh://user@host:1234/foo/bar#semver:^1.2.3 ' ],
259
+ ],
260
+ 'simple package, Git tag reference ' => [
261
+ 'versionString ' => 'foo-bar@git://user@host/foo/bar.git#v1.2.3 ' ,
262
+ 'expectedResult ' => ['foo-bar ' , 'git://user@host/foo/bar.git#v1.2.3 ' ],
263
+ ],
264
+ 'namespaced package, Git tag reference ' => [
265
+ 'versionString ' => '@foo/bar@git://user@host/foo/bar.git#v1.2.3 ' ,
266
+ 'expectedResult ' => ['@foo/bar ' , 'git://user@host/foo/bar.git#v1.2.3 ' ],
267
+ ],
268
+ 'simple package, file reference ' => [
269
+ 'versionString ' => 'foo-bar@file:vendor/foo/bar ' ,
270
+ 'expectedResult ' => ['foo-bar ' , 'file:vendor/foo/bar ' ],
271
+ ],
272
+ 'namespaced package, file reference ' => [
273
+ 'versionString ' => '@foo/bar@file:vendor/foo/bar ' ,
274
+ 'expectedResult ' => ['@foo/bar ' , 'file:vendor/foo/bar ' ],
275
+ ],
276
+ ];
234
277
}
235
278
279
+
236
280
/**
237
281
* Single-value keys should not be split at spaces if they are surrounded with quotes
238
282
* @throws ParserException
0 commit comments