File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -991,7 +991,7 @@ func trimGoVersion(v string) string {
991991 return ""
992992 }
993993
994- exp := regexp .MustCompile (`(\d\.\d+)\.\d+` )
994+ exp := regexp .MustCompile (`(\d\.\d+)(?: \.\d+|[a-z]+\d) ` )
995995
996996 if exp .MatchString (v ) {
997997 return exp .FindStringSubmatch (v )[1 ]
Original file line number Diff line number Diff line change 1+ package lintersdb
2+
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
8+
9+ func Test_trimGoVersion (t * testing.T ) {
10+ testCases := []struct {
11+ desc string
12+ version string
13+ expected string
14+ }{
15+ {
16+ desc : "patched version" ,
17+ version : "1.22.0" ,
18+ expected : "1.22" ,
19+ },
20+ {
21+ desc : "minor version" ,
22+ version : "1.22" ,
23+ expected : "1.22" ,
24+ },
25+ {
26+ desc : "RC version" ,
27+ version : "1.22rc1" ,
28+ expected : "1.22" ,
29+ },
30+ {
31+ desc : "alpha version" ,
32+ version : "1.22alpha1" ,
33+ expected : "1.22" ,
34+ },
35+ {
36+ desc : "beta version" ,
37+ version : "1.22beta1" ,
38+ expected : "1.22" ,
39+ },
40+ {
41+ desc : "semver RC version" ,
42+ version : "1.22.0-rc1" ,
43+ expected : "1.22" ,
44+ },
45+ }
46+
47+ for _ , test := range testCases {
48+ test := test
49+ t .Run (test .desc , func (t * testing.T ) {
50+ t .Parallel ()
51+
52+ version := trimGoVersion (test .version )
53+ assert .Equal (t , test .expected , version )
54+ })
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments