2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2020-05-16 00:10:12 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
// go test *.go -bench=".*"
|
|
|
|
|
|
|
|
package gstr_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/gogf/gf/test/gtest"
|
|
|
|
"github.com/gogf/gf/text/gstr"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_CompareVersion(t *testing.T) {
|
|
|
|
gtest.C(t, func(t *gtest.T) {
|
|
|
|
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)
|
|
|
|
t.AssertEQ(gstr.CompareVersion("1.0.1", "v1.1.0"), -1)
|
|
|
|
t.AssertEQ(gstr.CompareVersion("1.0.0", "v0.1.0"), 1)
|
|
|
|
t.AssertEQ(gstr.CompareVersion("1.0.0", "v1.0.0"), 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-16 00:11:08 +08:00
|
|
|
func Test_CompareVersionGo(t *testing.T) {
|
2020-05-16 00:10:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2020-05-16 00:11:08 +08:00
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v1.0.1", "v1.1.0"), -1)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("1.0.1", "v1.1.0"), -1)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("1.0.0", "v0.1.0"), 1)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("1.0.0", "v1.0.0"), 0)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v0.0.0-20190626092158-b2ccc519800e", "0.0.0-20190626092158"), 0)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v0.0.0-20190626092159-b2ccc519800e", "0.0.0-20190626092158"), 1)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v4.20.0+incompatible", "4.20.0"), 0)
|
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v4.20.0+incompatible", "4.20.1"), -1)
|
2020-05-16 00:10:12 +08:00
|
|
|
// Note that this comparison a < b.
|
2020-05-16 00:11:08 +08:00
|
|
|
t.AssertEQ(gstr.CompareVersionGo("v1.12.2-0.20200413154443-b17e3a6804fa", "v1.12.2"), -1)
|
2020-05-16 00:10:12 +08:00
|
|
|
})
|
|
|
|
}
|