@@ -409,4 +409,102 @@ describe('PullRequestGenerator', () => {
409
409
expect ( generator . generateTitle ( updateWithoutMetadata ) ) . toBeDefined ( )
410
410
} )
411
411
} )
412
+
413
+ describe ( 'formatVersionChange' , ( ) => {
414
+ // Access the private method for testing
415
+ const formatVersionChange = ( generator as any ) . formatVersionChange . bind ( generator )
416
+
417
+ describe ( 'constraint prefixes' , ( ) => {
418
+ it ( 'should preserve caret constraint prefix' , ( ) => {
419
+ const result = formatVersionChange ( '^3.0' , '3.0.0' )
420
+ expect ( result ) . toBe ( '`^3.0` → `^3.0.0`' )
421
+ } )
422
+
423
+ it ( 'should preserve tilde constraint prefix' , ( ) => {
424
+ const result = formatVersionChange ( '~2.1' , '2.1.5' )
425
+ expect ( result ) . toBe ( '`~2.1` → `~2.1.5`' )
426
+ } )
427
+
428
+ it ( 'should preserve greater than or equal constraint prefix' , ( ) => {
429
+ const result = formatVersionChange ( '>=1.5.0' , '1.6.0' )
430
+ expect ( result ) . toBe ( '`>=1.5.0` → `>=1.6.0`' )
431
+ } )
432
+
433
+ it ( 'should preserve less than constraint prefix' , ( ) => {
434
+ const result = formatVersionChange ( '<2.0.0' , '1.9.0' )
435
+ expect ( result ) . toBe ( '`<2.0.0` → `<1.9.0`' )
436
+ } )
437
+
438
+ it ( 'should preserve multiple character constraint prefix' , ( ) => {
439
+ const result = formatVersionChange ( '<=4.2.1' , '4.1.0' )
440
+ expect ( result ) . toBe ( '`<=4.2.1` → `<=4.1.0`' )
441
+ } )
442
+
443
+ it ( 'should handle complex constraint with version prefix' , ( ) => {
444
+ const result = formatVersionChange ( '^v1.2.3' , 'v1.2.4' )
445
+ expect ( result ) . toBe ( '`^v1.2.3` → `^v1.2.4`' )
446
+ } )
447
+ } )
448
+
449
+ describe ( 'no constraint prefix' , ( ) => {
450
+ it ( 'should handle versions without constraint prefix' , ( ) => {
451
+ const result = formatVersionChange ( '1.0.0' , '1.0.1' )
452
+ expect ( result ) . toBe ( '`1.0.0` → `1.0.1`' )
453
+ } )
454
+
455
+ it ( 'should handle semantic versions without prefix' , ( ) => {
456
+ const result = formatVersionChange ( '2.15.4' , '2.16.0' )
457
+ expect ( result ) . toBe ( '`2.15.4` → `2.16.0`' )
458
+ } )
459
+
460
+ it ( 'should handle version with v prefix but no constraint' , ( ) => {
461
+ const result = formatVersionChange ( 'v3.1.0' , 'v3.2.0' )
462
+ expect ( result ) . toBe ( '`v3.1.0` → `v3.2.0`' )
463
+ } )
464
+ } )
465
+
466
+ describe ( 'edge cases' , ( ) => {
467
+ it ( 'should handle empty versions gracefully' , ( ) => {
468
+ const result = formatVersionChange ( '' , '' )
469
+ expect ( result ) . toBe ( '`` → ``' )
470
+ } )
471
+
472
+ it ( 'should handle mixed constraint formats' , ( ) => {
473
+ const result = formatVersionChange ( '^6.0' , '6.0.0' )
474
+ expect ( result ) . toBe ( '`^6.0` → `^6.0.0`' )
475
+ } )
476
+
477
+ it ( 'should handle pre-release versions with constraints' , ( ) => {
478
+ const result = formatVersionChange ( '^1.0.0-alpha' , '1.0.0-beta' )
479
+ expect ( result ) . toBe ( '`^1.0.0-alpha` → `^1.0.0-beta`' )
480
+ } )
481
+
482
+ it ( 'should handle complex version identifiers' , ( ) => {
483
+ const result = formatVersionChange ( '~2.1.0-rc.1' , '2.1.0-rc.2' )
484
+ expect ( result ) . toBe ( '`~2.1.0-rc.1` → `~2.1.0-rc.2`' )
485
+ } )
486
+
487
+ it ( 'should handle npm range constraints' , ( ) => {
488
+ const result = formatVersionChange ( '^18.0.0 || ^19.0.0' , '19.1.0' )
489
+ expect ( result ) . toBe ( '`^18.0.0 || ^19.0.0` → `^19.1.0`' )
490
+ } )
491
+ } )
492
+
493
+ describe ( 'real-world examples from issue' , ( ) => {
494
+ it ( 'should correctly format zip package constraint update' , ( ) => {
495
+ const result = formatVersionChange ( '^3.0' , '3.0.0' )
496
+ expect ( result ) . toBe ( '`^3.0` → `^3.0.0`' )
497
+ } )
498
+
499
+ it ( 'should correctly format unzip package constraint update' , ( ) => {
500
+ const result = formatVersionChange ( '^6.0' , '6.0.0' )
501
+ expect ( result ) . toBe ( '`^6.0` → `^6.0.0`' )
502
+ } )
503
+
504
+ it ( 'should handle info-zip.org packages correctly' , ( ) => {
505
+ const result = formatVersionChange ( '^6.0' , '6.0.0' )
506
+ expect ( result ) . toBe ( '`^6.0` → `^6.0.0`' )
507
+ } )
508
+ } )
509
+ } )
412
510
} )
0 commit comments