We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 00f0a74 commit 9c5642fCopy full SHA for 9c5642f
text/gstr/gstr_version.go
@@ -24,10 +24,10 @@ import (
24
// 10.2.0
25
// etc.
26
func CompareVersion(a, b string) int {
27
- if a[0] == 'v' {
+ if a != "" && a[0] == 'v' {
28
a = a[1:]
29
}
30
- if b[0] == 'v' {
+ if b != "" && b[0] == 'v' {
31
b = b[1:]
32
33
var (
@@ -71,10 +71,10 @@ func CompareVersion(a, b string) int {
71
// v4.20.0+incompatible
72
73
func CompareVersionGo(a, b string) int {
74
75
76
77
78
79
80
if Count(a, "-") > 1 {
text/gstr/gstr_z_unit_version_test.go
@@ -17,6 +17,9 @@ import (
17
18
func Test_CompareVersion(t *testing.T) {
19
gtest.C(t, func(t *gtest.T) {
20
+ t.AssertEQ(gstr.CompareVersion("1", ""), 1)
21
+ t.AssertEQ(gstr.CompareVersion("", ""), 0)
22
+ t.AssertEQ(gstr.CompareVersion("", "v0.1"), -1)
23
t.AssertEQ(gstr.CompareVersion("1", "v0.99"), 1)
t.AssertEQ(gstr.CompareVersion("v1.0", "v0.99"), 1)
t.AssertEQ(gstr.CompareVersion("v1.0.1", "v1.1.0"), -1)
@@ -28,6 +31,9 @@ func Test_CompareVersion(t *testing.T) {
func Test_CompareVersionGo(t *testing.T) {
34
+ t.AssertEQ(gstr.CompareVersionGo("1", ""), 1)
35
+ t.AssertEQ(gstr.CompareVersionGo("", ""), 0)
36
+ t.AssertEQ(gstr.CompareVersionGo("", "v0.1"), -1)
37
t.AssertEQ(gstr.CompareVersionGo("v1.0.1", "v1.1.0"), -1)
38
t.AssertEQ(gstr.CompareVersionGo("1.0.1", "v1.1.0"), -1)
39
t.AssertEQ(gstr.CompareVersionGo("1.0.0", "v0.1.0"), 1)
0 commit comments