@@ -2,6 +2,7 @@ package semantic_test
22
33import (
44 "github.com/g-rath/osv-detector/pkg/semantic"
5+ "math/big"
56 "testing"
67)
78
@@ -42,7 +43,13 @@ func expectCompareResult(
4243}
4344
4445func buildlessVersion (build string , components ... int ) semantic.Version {
45- return semantic.Version {Components : components , Build : build }
46+ comps := make ([]* big.Int , 0 , len (components ))
47+
48+ for _ , i := range components {
49+ comps = append (comps , big .NewInt (int64 (i )))
50+ }
51+
52+ return semantic.Version {Components : comps , Build : build }
4653}
4754
4855func TestVersion_Compare_BasicEqual (t * testing.T ) {
@@ -426,32 +433,57 @@ func TestVersion_Compare_BasicWithLeadingV(t *testing.T) {
426433 t .Parallel ()
427434
428435 expectCompareResult (t ,
429- semantic.Version {LeadingV : false , Components : []int { 1 }, Build : "" },
430- semantic.Version {LeadingV : false , Components : []int { 1 }, Build : "" },
436+ semantic.Version {LeadingV : false , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
437+ semantic.Version {LeadingV : false , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
431438 0 ,
432439 )
433440
434441 expectCompareResult (t ,
435- semantic.Version {LeadingV : true , Components : []int { 1 }, Build : "" },
436- semantic.Version {LeadingV : false , Components : []int { 1 }, Build : "" },
442+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
443+ semantic.Version {LeadingV : false , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
437444 0 ,
438445 )
439446
440447 expectCompareResult (t ,
441- semantic.Version {LeadingV : false , Components : []int { 1 }, Build : "" },
442- semantic.Version {LeadingV : true , Components : []int { 1 }, Build : "" },
448+ semantic.Version {LeadingV : false , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
449+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
443450 0 ,
444451 )
445452
446453 expectCompareResult (t ,
447- semantic.Version {LeadingV : true , Components : []int { 1 }, Build : "" },
448- semantic.Version {LeadingV : true , Components : []int { 1 }, Build : "" },
454+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
455+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
449456 0 ,
450457 )
451458
452459 expectCompareResult (t ,
453- semantic.Version {LeadingV : true , Components : []int { 2 }, Build : "" },
454- semantic.Version {LeadingV : true , Components : []int { 1 }, Build : "" },
460+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 2 ) }, Build : "" },
461+ semantic.Version {LeadingV : true , Components : []* big. Int { big . NewInt ( 1 ) }, Build : "" },
455462 1 ,
456463 )
457464}
465+
466+ func TestVersion_Compare_BasicWithBigComponents (t * testing.T ) {
467+ t .Parallel ()
468+
469+ big1 , _ := new (big.Int ).SetString ("9999999999999999999999999999999999999999999999999999999999999999" , 10 )
470+ big2 , _ := new (big.Int ).SetString ("9999999999999999999999999999999999999999999999999999999999999998" , 10 )
471+
472+ expectCompareResult (t ,
473+ semantic.Version {Components : []* big.Int {big1 }},
474+ semantic.Version {Components : []* big.Int {big1 }},
475+ 0 ,
476+ )
477+
478+ expectCompareResult (t ,
479+ semantic.Version {Components : []* big.Int {big1 }},
480+ semantic.Version {Components : []* big.Int {big2 }},
481+ 1 ,
482+ )
483+
484+ expectCompareResult (t ,
485+ semantic.Version {Components : []* big.Int {big1 , big1 , big1 , big2 }},
486+ semantic.Version {Components : []* big.Int {big1 , big1 , big1 , big1 }},
487+ - 1 ,
488+ )
489+ }
0 commit comments