@@ -61,6 +61,27 @@ public function test_parse(): void
6161 'int ' => 999999000201 ,
6262 'normalized ' => '1.0.0 '
6363 ),
64+ array (
65+ 'label ' => 'With beta tag, numbered 2, with dot separator ' ,
66+ 'version ' => '1.0.0-beta.2 ' ,
67+ 'expected ' => 999999.000201 ,
68+ 'int ' => 999999000201 ,
69+ 'normalized ' => '1.0.0 '
70+ ),
71+ array (
72+ 'label ' => 'With beta tag, numbered 2, with hyphen separator ' ,
73+ 'version ' => '1.0.0-beta-2 ' ,
74+ 'expected ' => 999999.000201 ,
75+ 'int ' => 999999000201 ,
76+ 'normalized ' => '1.0.0 '
77+ ),
78+ array (
79+ 'label ' => 'With beta tag, numbered 2, with underscore separator ' ,
80+ 'version ' => '1.0.0-beta_2 ' ,
81+ 'expected ' => 999999.000201 ,
82+ 'int ' => 999999000201 ,
83+ 'normalized ' => '1.0.0 '
84+ ),
6485 array (
6586 'label ' => 'With alpha tag ' ,
6687 'version ' => '1.0.0-alpha ' ,
@@ -101,7 +122,7 @@ public function test_parse(): void
101122 foreach ($ tests as $ test ) {
102123 $ version = VersionParser::create ($ test ['version ' ]);
103124
104- $ this ->assertEquals ($ test ['expected ' ], $ version ->getBuildNumber (), $ test ['label ' ]);
125+ $ this ->assertEquals ($ test ['expected ' ], $ version ->getBuildNumber (), $ test ['label ' ]. print_r ( $ version -> toArray (), true ) );
105126 $ this ->assertEquals ($ test ['int ' ], $ version ->getBuildNumberInt (), $ test ['label ' ]);
106127 $ this ->assertEquals ($ test ['normalized ' ], $ version ->getVersion (), $ test ['label ' ]);
107128 }
@@ -203,7 +224,7 @@ public function test_getTag(): void
203224 foreach ($ tests as $ test ) {
204225 $ version = VersionParser::create ($ test ['version ' ]);
205226
206- $ label = $ test ['label ' ] . ' ( ' . $ test ['version ' ] . ') ' ;
227+ $ label = $ test ['label ' ]. ' ( ' . $ test ['version ' ]. ') ' . PHP_EOL . print_r ( $ version -> toArray (), true ) ;
207228
208229 $ this ->assertEquals ($ test ['expected ' ], $ version ->getTag (), $ label );
209230 $ this ->assertEquals ($ test ['type ' ], $ version ->getTagType (), $ label );
@@ -215,23 +236,25 @@ public function test_no_tag(): void
215236 {
216237 $ version = VersionParser::create ('1.0 ' );
217238
218- $ this ->assertFalse ($ version ->isAlpha ());
219- $ this ->assertFalse ($ version ->isBeta ());
220- $ this ->assertFalse ($ version ->isReleaseCandidate ());
221239 $ this ->assertFalse ($ version ->hasTag ());
222- $ this ->assertFalse ($ version ->isSnapshot ());
223240 }
224241
225- public function test_tag_beta () : void
242+ public function test_tag_info () : void
226243 {
227- $ version = VersionParser::create ('1.0-beta2 ' );
244+ $ version = VersionParser::create ('1.0-beta11 ' );
228245
229- $ this ->assertTrue ($ version ->isBeta ());
230- $ this ->assertFalse ($ version ->isAlpha ());
231- $ this ->assertFalse ($ version ->isReleaseCandidate ());
246+ $ tag = $ version ->getTagInfo ();
247+ $ this ->assertNotNull ($ tag );
248+
249+ $ testLabel = print_r ($ version ->toArray (), true );
250+
251+ $ this ->assertTrue ($ tag ->isBeta (), $ testLabel );
252+ $ this ->assertFalse ($ tag ->isAlpha (), $ testLabel );
253+ $ this ->assertFalse ($ tag ->isReleaseCandidate (), $ testLabel );
254+ $ this ->assertSame (11 , $ tag ->getNumber (), $ testLabel );
232255 }
233256
234- public function test_tag_alpha (): void
257+ public function test_tag_alpha () : void
235258 {
236259 $ version = VersionParser::create ('1.0-alpha2 ' );
237260
@@ -264,7 +287,54 @@ public function test_tag_hyphen(): void
264287 $ this ->assertEquals ('rc2 ' , $ version ->getTag ());
265288 }
266289
267- public function test_tooManyDots (): void
290+ public function test_tag_dot () : void
291+ {
292+ $ version = VersionParser::create ('1.0-rc.2 ' );
293+
294+ $ this ->assertTrue ($ version ->isReleaseCandidate ());
295+ $ this ->assertEquals ('rc2 ' , $ version ->getTag ());
296+ }
297+
298+ public function test_tag_underscore () : void
299+ {
300+ $ version = VersionParser::create ('1.0-rc_2 ' );
301+
302+ $ this ->assertTrue ($ version ->isReleaseCandidate ());
303+ $ this ->assertEquals ('rc2 ' , $ version ->getTag ());
304+ }
305+
306+ public function test_tag_and_branch () : void
307+ {
308+ $ version = VersionParser::create ('1.0-BranchName-RC ' );
309+
310+ $ this ->assertTrue ($ version ->isReleaseCandidate ());
311+ $ this ->assertEquals ('BranchName-rc ' , $ version ->getTag ());
312+ $ this ->assertEquals ('BranchName ' , $ version ->getBranchName (), print_r ($ version ->toArray (), true ));
313+ }
314+
315+ public function test_branchCanS0tartWithNumber () : void
316+ {
317+ $ version = VersionParser::create ('1.0-42BranchName-RC ' );
318+
319+ $ testLabel = print_r ($ version ->toArray (), true );
320+
321+ $ this ->assertEquals ('1.0.0 ' , $ version ->getVersion (), $ testLabel );
322+ $ this ->assertTrue ($ version ->isReleaseCandidate (), $ testLabel );
323+ $ this ->assertEquals ('42BranchName-rc ' , $ version ->getTag (), $ testLabel );
324+ $ this ->assertEquals ('42BranchName ' , $ version ->getBranchName (), $ testLabel );
325+ }
326+
327+ public function test_branchCanContainSpecialChars () : void
328+ {
329+ $ version = VersionParser::create ('1.5.2 "Foobar/42" ' );
330+
331+ $ testLabel = print_r ($ version ->toArray (), true );
332+
333+ $ this ->assertEquals ('1.5.2 ' , $ version ->getVersion (), $ testLabel );
334+ $ this ->assertEquals ('Foobar/42 ' , $ version ->getBranchName (), $ testLabel );
335+ }
336+
337+ public function test_tooManyDots () : void
268338 {
269339 $ version = VersionParser::create ('1.2.3.4 ' );
270340
@@ -279,6 +349,63 @@ public function test_stripSpaces(): void
279349 $ this ->assertEquals ('1.2.3 ' , $ version ->getVersion ());
280350 }
281351
352+ public function test_preserveSpacesInTag (): void
353+ {
354+ $ version = VersionParser::create ('1 . 2 . 3 BranchName RC ' );
355+
356+ $ testLabel = print_r ($ version ->toArray (), true );
357+
358+ $ this ->assertEquals ('1.2.3 ' , $ version ->getVersion (), $ testLabel );
359+ $ this ->assertEquals ('BranchName ' , $ version ->getBranchName (), $ testLabel );
360+ $ this ->assertEquals ('rc ' , $ version ->getTagType (), $ testLabel );
361+ }
362+
363+ public function test_stripSpecialChars () : void
364+ {
365+ $ version = VersionParser::create ('1.2 (BranchName) / Alpha2 ' );
366+
367+ $ testLabel = print_r ($ version ->toArray (), true );
368+
369+ $ this ->assertEquals ('1.2.0 ' , $ version ->getVersion (), $ testLabel );
370+ $ this ->assertEquals ('BranchName ' , $ version ->getBranchName (), $ testLabel );
371+ $ this ->assertEquals ('alpha ' , $ version ->getTagType (), $ testLabel );
372+ }
373+
374+ public function test_preserveOriginalCharsInBranch () : void
375+ {
376+ $ version = VersionParser::create ('1.2 "Super:branch" ' );
377+
378+ $ testLabel = print_r ($ version ->toArray (), true );
379+
380+ $ this ->assertEquals ('1.2.0 ' , $ version ->getVersion (), $ testLabel );
381+ $ this ->assertEquals ('Super:branch ' , $ version ->getBranchName (), $ testLabel );
382+ }
383+
384+ public function test_branchNameAfterTag () : void
385+ {
386+ $ version = VersionParser::create ('1.2-beta2 "Super branch" ' );
387+
388+ $ testLabel = print_r ($ version ->toArray (), true );
389+
390+ $ this ->assertEquals ('1.2.0 ' , $ version ->getVersion (), $ testLabel );
391+ $ this ->assertEquals ('beta ' , $ version ->getTagType (), $ testLabel );
392+ $ this ->assertEquals ('Super branch ' , $ version ->getBranchName (), $ testLabel );
393+ }
394+
395+ public function test_branchNameBeforeAndAfterTag () : void
396+ {
397+ $ version = VersionParser::create ('1.2 Super beta branch ' );
398+
399+ $ testLabel = print_r ($ version ->toArray (), true );
400+
401+ $ this ->assertEquals ('1.2.0 ' , $ version ->getVersion (), $ testLabel );
402+ $ this ->assertEquals ('beta ' , $ version ->getTagType (), $ testLabel );
403+
404+ // This cannot be resolved back to the original branch name,
405+ // because the tag qualifier is in the middle of it.
406+ $ this ->assertEquals ('Super-branch ' , $ version ->getBranchName (), $ testLabel );
407+ }
408+
282409 public function test_getBranchName (): void
283410 {
284411 $ tests = array (
@@ -305,7 +432,7 @@ public function test_getBranchName(): void
305432 foreach ($ tests as $ test ) {
306433 $ version = VersionParser::create ($ test ['version ' ]);
307434
308- $ label = $ test ['label ' ] . ' ( ' . $ test ['version ' ] . ') ' ;
435+ $ label = $ test ['label ' ]. ' ( ' . $ test ['version ' ]. ') ' . PHP_EOL . print_r ( $ version -> toArray (), true ) ;
309436
310437 $ this ->assertEquals ($ test ['name ' ], $ version ->getBranchName (), $ label );
311438 $ this ->assertEquals ($ test ['hasBranch ' ], $ version ->hasBranch (), $ label );
@@ -357,7 +484,7 @@ public function test_normalizeUppercase(): void
357484 {
358485 $ version = VersionParser::create ('1-BranchName-beta ' );
359486
360- $ this ->assertEquals ('1.0.0-BranchName-BETA ' , $ version ->setUppercase ()->getTagVersion ());
487+ $ this ->assertEquals ('1.0.0-BranchName-BETA ' , $ version ->setTagUppercase ()->getTagVersion (), print_r ( $ version -> toArray (), true ));
361488 }
362489
363490 public function test_setSeparator (): void
0 commit comments