vendor: remove dep and use vndr
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
16f44674a4
commit
148e72d81e
16131 changed files with 73815 additions and 4235138 deletions
1
vendor/github.com/blang/semver/.gx/lastpubver
generated
vendored
1
vendor/github.com/blang/semver/.gx/lastpubver
generated
vendored
|
@ -1 +0,0 @@
|
|||
3.4.0: QmZTgGMg34JKEvF1hjr7wwYESvFhg9Khv2WFibDAi5dhno
|
83
vendor/github.com/blang/semver/examples/main.go
generated
vendored
83
vendor/github.com/blang/semver/examples/main.go
generated
vendored
|
@ -1,83 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/blang/semver"
|
||||
)
|
||||
|
||||
func main() {
|
||||
v, err := semver.Parse("0.0.1-alpha.preview.222+123.github")
|
||||
if err != nil {
|
||||
fmt.Printf("Error while parsing (not valid): %q", err)
|
||||
}
|
||||
fmt.Printf("Version to string: %q\n", v)
|
||||
|
||||
fmt.Printf("Major: %d\n", v.Major)
|
||||
fmt.Printf("Minor: %d\n", v.Minor)
|
||||
fmt.Printf("Patch: %d\n", v.Patch)
|
||||
|
||||
// Prerelease versions
|
||||
if len(v.Pre) > 0 {
|
||||
fmt.Println("Prerelease versions:")
|
||||
for i, pre := range v.Pre {
|
||||
fmt.Printf("%d: %q\n", i, pre)
|
||||
}
|
||||
}
|
||||
|
||||
// Build meta data
|
||||
if len(v.Build) > 0 {
|
||||
fmt.Println("Build meta data:")
|
||||
for i, build := range v.Build {
|
||||
fmt.Printf("%d: %q\n", i, build)
|
||||
}
|
||||
}
|
||||
|
||||
// Make == Parse (Value), New for Pointer
|
||||
v001, err := semver.Make("0.0.1")
|
||||
|
||||
fmt.Println("\nUse Version.Compare for comparisons (-1, 0, 1):")
|
||||
fmt.Printf("%q is greater than %q: Compare == %d\n", v001, v, v001.Compare(v))
|
||||
fmt.Printf("%q is less than %q: Compare == %d\n", v, v001, v.Compare(v001))
|
||||
fmt.Printf("%q is equal to %q: Compare == %d\n", v, v, v.Compare(v))
|
||||
|
||||
fmt.Println("\nUse comparison helpers returning booleans:")
|
||||
fmt.Printf("%q is greater than %q: %t\n", v001, v, v001.GT(v))
|
||||
fmt.Printf("%q is greater than equal %q: %t\n", v001, v, v001.GTE(v))
|
||||
fmt.Printf("%q is greater than equal %q: %t\n", v, v, v.GTE(v))
|
||||
fmt.Printf("%q is less than %q: %t\n", v, v001, v.LT(v001))
|
||||
fmt.Printf("%q is less than equal %q: %t\n", v, v001, v.LTE(v001))
|
||||
fmt.Printf("%q is less than equal %q: %t\n", v, v, v.LTE(v))
|
||||
|
||||
fmt.Println("\nManipulate Version in place:")
|
||||
v.Pre[0], err = semver.NewPRVersion("beta")
|
||||
if err != nil {
|
||||
fmt.Printf("Error parsing pre release version: %q", err)
|
||||
}
|
||||
fmt.Printf("Version to string: %q\n", v)
|
||||
|
||||
fmt.Println("\nCompare Prerelease versions:")
|
||||
pre1, _ := semver.NewPRVersion("123")
|
||||
pre2, _ := semver.NewPRVersion("alpha")
|
||||
pre3, _ := semver.NewPRVersion("124")
|
||||
fmt.Printf("%q is less than %q: Compare == %d\n", pre1, pre2, pre1.Compare(pre2))
|
||||
fmt.Printf("%q is greater than %q: Compare == %d\n", pre3, pre1, pre3.Compare(pre1))
|
||||
fmt.Printf("%q is equal to %q: Compare == %d\n", pre1, pre1, pre1.Compare(pre1))
|
||||
|
||||
fmt.Println("\nValidate versions:")
|
||||
v.Build[0] = "?"
|
||||
|
||||
err = v.Validate()
|
||||
if err != nil {
|
||||
fmt.Printf("Validation failed: %s\n", err)
|
||||
}
|
||||
|
||||
fmt.Println("Create valid build meta data:")
|
||||
b1, _ := semver.NewBuildVersion("build123")
|
||||
v.Build[0] = b1
|
||||
fmt.Printf("Version with new build version %q\n", v)
|
||||
|
||||
_, err = semver.NewBuildVersion("build?123")
|
||||
if err != nil {
|
||||
fmt.Printf("Create build version failed: %s\n", err)
|
||||
}
|
||||
}
|
49
vendor/github.com/blang/semver/json_test.go
generated
vendored
49
vendor/github.com/blang/semver/json_test.go
generated
vendored
|
@ -1,49 +0,0 @@
|
|||
package semver
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestJSONMarshal(t *testing.T) {
|
||||
versionString := "3.1.4-alpha.1.5.9+build.2.6.5"
|
||||
v, err := Parse(versionString)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
versionJSON, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
quotedVersionString := strconv.Quote(versionString)
|
||||
|
||||
if string(versionJSON) != quotedVersionString {
|
||||
t.Fatalf("JSON marshaled semantic version not equal: expected %q, got %q", quotedVersionString, string(versionJSON))
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONUnmarshal(t *testing.T) {
|
||||
versionString := "3.1.4-alpha.1.5.9+build.2.6.5"
|
||||
quotedVersionString := strconv.Quote(versionString)
|
||||
|
||||
var v Version
|
||||
if err := json.Unmarshal([]byte(quotedVersionString), &v); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if v.String() != versionString {
|
||||
t.Fatalf("JSON unmarshaled semantic version not equal: expected %q, got %q", versionString, v.String())
|
||||
}
|
||||
|
||||
badVersionString := strconv.Quote("3.1.4.1.5.9.2.6.5-other-digits-of-pi")
|
||||
if err := json.Unmarshal([]byte(badVersionString), &v); err == nil {
|
||||
t.Fatal("expected JSON unmarshal error, got nil")
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte("3.1"), &v); err == nil {
|
||||
t.Fatal("expected JSON unmarshal error, got nil")
|
||||
}
|
||||
}
|
17
vendor/github.com/blang/semver/package.json
generated
vendored
17
vendor/github.com/blang/semver/package.json
generated
vendored
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"author": "blang",
|
||||
"bugs": {
|
||||
"URL": "https://github.com/blang/semver/issues",
|
||||
"url": "https://github.com/blang/semver/issues"
|
||||
},
|
||||
"gx": {
|
||||
"dvcsimport": "github.com/blang/semver"
|
||||
},
|
||||
"gxVersion": "0.10.0",
|
||||
"language": "go",
|
||||
"license": "MIT",
|
||||
"name": "semver",
|
||||
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
|
||||
"version": "3.4.0"
|
||||
}
|
||||
|
581
vendor/github.com/blang/semver/range_test.go
generated
vendored
581
vendor/github.com/blang/semver/range_test.go
generated
vendored
|
@ -1,581 +0,0 @@
|
|||
package semver
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type wildcardTypeTest struct {
|
||||
input string
|
||||
wildcardType wildcardType
|
||||
}
|
||||
|
||||
type comparatorTest struct {
|
||||
input string
|
||||
comparator func(comparator) bool
|
||||
}
|
||||
|
||||
func TestParseComparator(t *testing.T) {
|
||||
compatorTests := []comparatorTest{
|
||||
{">", testGT},
|
||||
{">=", testGE},
|
||||
{"<", testLT},
|
||||
{"<=", testLE},
|
||||
{"", testEQ},
|
||||
{"=", testEQ},
|
||||
{"==", testEQ},
|
||||
{"!=", testNE},
|
||||
{"!", testNE},
|
||||
{"-", nil},
|
||||
{"<==", nil},
|
||||
{"<<", nil},
|
||||
{">>", nil},
|
||||
}
|
||||
|
||||
for _, tc := range compatorTests {
|
||||
if c := parseComparator(tc.input); c == nil {
|
||||
if tc.comparator != nil {
|
||||
t.Errorf("Comparator nil for case %q\n", tc.input)
|
||||
}
|
||||
} else if !tc.comparator(c) {
|
||||
t.Errorf("Invalid comparator for case %q\n", tc.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
v1 = MustParse("1.2.2")
|
||||
v2 = MustParse("1.2.3")
|
||||
v3 = MustParse("1.2.4")
|
||||
)
|
||||
|
||||
func testEQ(f comparator) bool {
|
||||
return f(v1, v1) && !f(v1, v2)
|
||||
}
|
||||
|
||||
func testNE(f comparator) bool {
|
||||
return !f(v1, v1) && f(v1, v2)
|
||||
}
|
||||
|
||||
func testGT(f comparator) bool {
|
||||
return f(v2, v1) && f(v3, v2) && !f(v1, v2) && !f(v1, v1)
|
||||
}
|
||||
|
||||
func testGE(f comparator) bool {
|
||||
return f(v2, v1) && f(v3, v2) && !f(v1, v2)
|
||||
}
|
||||
|
||||
func testLT(f comparator) bool {
|
||||
return f(v1, v2) && f(v2, v3) && !f(v2, v1) && !f(v1, v1)
|
||||
}
|
||||
|
||||
func testLE(f comparator) bool {
|
||||
return f(v1, v2) && f(v2, v3) && !f(v2, v1)
|
||||
}
|
||||
|
||||
func TestSplitAndTrim(t *testing.T) {
|
||||
tests := []struct {
|
||||
i string
|
||||
s []string
|
||||
}{
|
||||
{"1.2.3 1.2.3", []string{"1.2.3", "1.2.3"}},
|
||||
{" 1.2.3 1.2.3 ", []string{"1.2.3", "1.2.3"}}, // Spaces
|
||||
{" >= 1.2.3 <= 1.2.3 ", []string{">=1.2.3", "<=1.2.3"}}, // Spaces between operator and version
|
||||
{"1.2.3 || >=1.2.3 <1.2.3", []string{"1.2.3", "||", ">=1.2.3", "<1.2.3"}},
|
||||
{" 1.2.3 || >=1.2.3 <1.2.3 ", []string{"1.2.3", "||", ">=1.2.3", "<1.2.3"}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
p := splitAndTrim(tc.i)
|
||||
if !reflect.DeepEqual(p, tc.s) {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.s, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitComparatorVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
i string
|
||||
p []string
|
||||
}{
|
||||
{">1.2.3", []string{">", "1.2.3"}},
|
||||
{">=1.2.3", []string{">=", "1.2.3"}},
|
||||
{"<1.2.3", []string{"<", "1.2.3"}},
|
||||
{"<=1.2.3", []string{"<=", "1.2.3"}},
|
||||
{"1.2.3", []string{"", "1.2.3"}},
|
||||
{"=1.2.3", []string{"=", "1.2.3"}},
|
||||
{"==1.2.3", []string{"==", "1.2.3"}},
|
||||
{"!=1.2.3", []string{"!=", "1.2.3"}},
|
||||
{"!1.2.3", []string{"!", "1.2.3"}},
|
||||
{"error", nil},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
if op, v, err := splitComparatorVersion(tc.i); err != nil {
|
||||
if tc.p != nil {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got error %q", tc.i, tc.p, err)
|
||||
}
|
||||
} else if op != tc.p[0] {
|
||||
t.Errorf("Invalid operator for case %q: Expected %q, got: %q", tc.i, tc.p[0], op)
|
||||
} else if v != tc.p[1] {
|
||||
t.Errorf("Invalid version for case %q: Expected %q, got: %q", tc.i, tc.p[1], v)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildVersionRange(t *testing.T) {
|
||||
tests := []struct {
|
||||
opStr string
|
||||
vStr string
|
||||
c func(comparator) bool
|
||||
v string
|
||||
}{
|
||||
{">", "1.2.3", testGT, "1.2.3"},
|
||||
{">=", "1.2.3", testGE, "1.2.3"},
|
||||
{"<", "1.2.3", testLT, "1.2.3"},
|
||||
{"<=", "1.2.3", testLE, "1.2.3"},
|
||||
{"", "1.2.3", testEQ, "1.2.3"},
|
||||
{"=", "1.2.3", testEQ, "1.2.3"},
|
||||
{"==", "1.2.3", testEQ, "1.2.3"},
|
||||
{"!=", "1.2.3", testNE, "1.2.3"},
|
||||
{"!", "1.2.3", testNE, "1.2.3"},
|
||||
{">>", "1.2.3", nil, ""}, // Invalid comparator
|
||||
{"=", "invalid", nil, ""}, // Invalid version
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
if r, err := buildVersionRange(tc.opStr, tc.vStr); err != nil {
|
||||
if tc.c != nil {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got error %q", strings.Join([]string{tc.opStr, tc.vStr}, ""), tc.v, err)
|
||||
}
|
||||
} else if r == nil {
|
||||
t.Errorf("Invalid for case %q: got nil", strings.Join([]string{tc.opStr, tc.vStr}, ""))
|
||||
} else {
|
||||
// test version
|
||||
if tv := MustParse(tc.v); !r.v.EQ(tv) {
|
||||
t.Errorf("Invalid for case %q: Expected version %q, got: %q", strings.Join([]string{tc.opStr, tc.vStr}, ""), tv, r.v)
|
||||
}
|
||||
// test comparator
|
||||
if r.c == nil {
|
||||
t.Errorf("Invalid for case %q: got nil comparator", strings.Join([]string{tc.opStr, tc.vStr}, ""))
|
||||
continue
|
||||
}
|
||||
if !tc.c(r.c) {
|
||||
t.Errorf("Invalid comparator for case %q\n", strings.Join([]string{tc.opStr, tc.vStr}, ""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestSplitORParts(t *testing.T) {
|
||||
tests := []struct {
|
||||
i []string
|
||||
o [][]string
|
||||
}{
|
||||
{[]string{">1.2.3", "||", "<1.2.3", "||", "=1.2.3"}, [][]string{
|
||||
[]string{">1.2.3"},
|
||||
[]string{"<1.2.3"},
|
||||
[]string{"=1.2.3"},
|
||||
}},
|
||||
{[]string{">1.2.3", "<1.2.3", "||", "=1.2.3"}, [][]string{
|
||||
[]string{">1.2.3", "<1.2.3"},
|
||||
[]string{"=1.2.3"},
|
||||
}},
|
||||
{[]string{">1.2.3", "||"}, nil},
|
||||
{[]string{"||", ">1.2.3"}, nil},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
o, err := splitORParts(tc.i)
|
||||
if err != nil && tc.o != nil {
|
||||
t.Errorf("Unexpected error for case %q: %s", tc.i, err)
|
||||
}
|
||||
if !reflect.DeepEqual(tc.o, o) {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.o, o)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetWildcardType(t *testing.T) {
|
||||
wildcardTypeTests := []wildcardTypeTest{
|
||||
{"x", majorWildcard},
|
||||
{"1.x", minorWildcard},
|
||||
{"1.2.x", patchWildcard},
|
||||
{"fo.o.b.ar", noneWildcard},
|
||||
}
|
||||
|
||||
for _, tc := range wildcardTypeTests {
|
||||
o := getWildcardType(tc.input)
|
||||
if o != tc.wildcardType {
|
||||
t.Errorf("Invalid for case: %q: Expected %q, got: %q", tc.input, tc.wildcardType, o)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateVersionFromWildcard(t *testing.T) {
|
||||
tests := []struct {
|
||||
i string
|
||||
s string
|
||||
}{
|
||||
{"1.2.x", "1.2.0"},
|
||||
{"1.x", "1.0.0"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
p := createVersionFromWildcard(tc.i)
|
||||
if p != tc.s {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.s, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncrementMajorVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
i string
|
||||
s string
|
||||
}{
|
||||
{"1.2.3", "2.2.3"},
|
||||
{"1.2", "2.2"},
|
||||
{"foo.bar", ""},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
p, _ := incrementMajorVersion(tc.i)
|
||||
if p != tc.s {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.s, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncrementMinorVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
i string
|
||||
s string
|
||||
}{
|
||||
{"1.2.3", "1.3.3"},
|
||||
{"1.2", "1.3"},
|
||||
{"foo.bar", ""},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
p, _ := incrementMinorVersion(tc.i)
|
||||
if p != tc.s {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.s, p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandWildcardVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
i [][]string
|
||||
o [][]string
|
||||
}{
|
||||
{[][]string{[]string{"foox"}}, nil},
|
||||
{[][]string{[]string{">=1.2.x"}}, [][]string{[]string{">=1.2.0"}}},
|
||||
{[][]string{[]string{"<=1.2.x"}}, [][]string{[]string{"<1.3.0"}}},
|
||||
{[][]string{[]string{">1.2.x"}}, [][]string{[]string{">=1.3.0"}}},
|
||||
{[][]string{[]string{"<1.2.x"}}, [][]string{[]string{"<1.2.0"}}},
|
||||
{[][]string{[]string{"!=1.2.x"}}, [][]string{[]string{"<1.2.0", ">=1.3.0"}}},
|
||||
{[][]string{[]string{">=1.x"}}, [][]string{[]string{">=1.0.0"}}},
|
||||
{[][]string{[]string{"<=1.x"}}, [][]string{[]string{"<2.0.0"}}},
|
||||
{[][]string{[]string{">1.x"}}, [][]string{[]string{">=2.0.0"}}},
|
||||
{[][]string{[]string{"<1.x"}}, [][]string{[]string{"<1.0.0"}}},
|
||||
{[][]string{[]string{"!=1.x"}}, [][]string{[]string{"<1.0.0", ">=2.0.0"}}},
|
||||
{[][]string{[]string{"1.2.x"}}, [][]string{[]string{">=1.2.0", "<1.3.0"}}},
|
||||
{[][]string{[]string{"1.x"}}, [][]string{[]string{">=1.0.0", "<2.0.0"}}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
o, _ := expandWildcardVersion(tc.i)
|
||||
if !reflect.DeepEqual(tc.o, o) {
|
||||
t.Errorf("Invalid for case %q: Expected %q, got: %q", tc.i, tc.o, o)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionRangeToRange(t *testing.T) {
|
||||
vr := versionRange{
|
||||
v: MustParse("1.2.3"),
|
||||
c: compLT,
|
||||
}
|
||||
rf := vr.rangeFunc()
|
||||
if !rf(MustParse("1.2.2")) || rf(MustParse("1.2.3")) {
|
||||
t.Errorf("Invalid conversion to range func")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRangeAND(t *testing.T) {
|
||||
v := MustParse("1.2.2")
|
||||
v1 := MustParse("1.2.1")
|
||||
v2 := MustParse("1.2.3")
|
||||
rf1 := Range(func(v Version) bool {
|
||||
return v.GT(v1)
|
||||
})
|
||||
rf2 := Range(func(v Version) bool {
|
||||
return v.LT(v2)
|
||||
})
|
||||
rf := rf1.AND(rf2)
|
||||
if rf(v1) {
|
||||
t.Errorf("Invalid rangefunc, accepted: %s", v1)
|
||||
}
|
||||
if rf(v2) {
|
||||
t.Errorf("Invalid rangefunc, accepted: %s", v2)
|
||||
}
|
||||
if !rf(v) {
|
||||
t.Errorf("Invalid rangefunc, did not accept: %s", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRangeOR(t *testing.T) {
|
||||
tests := []struct {
|
||||
v Version
|
||||
b bool
|
||||
}{
|
||||
{MustParse("1.2.0"), true},
|
||||
{MustParse("1.2.2"), false},
|
||||
{MustParse("1.2.4"), true},
|
||||
}
|
||||
v1 := MustParse("1.2.1")
|
||||
v2 := MustParse("1.2.3")
|
||||
rf1 := Range(func(v Version) bool {
|
||||
return v.LT(v1)
|
||||
})
|
||||
rf2 := Range(func(v Version) bool {
|
||||
return v.GT(v2)
|
||||
})
|
||||
rf := rf1.OR(rf2)
|
||||
for _, tc := range tests {
|
||||
if r := rf(tc.v); r != tc.b {
|
||||
t.Errorf("Invalid for case %q: Expected %t, got %t", tc.v, tc.b, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRange(t *testing.T) {
|
||||
type tv struct {
|
||||
v string
|
||||
b bool
|
||||
}
|
||||
tests := []struct {
|
||||
i string
|
||||
t []tv
|
||||
}{
|
||||
// Simple expressions
|
||||
{">1.2.3", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", true},
|
||||
}},
|
||||
{">=1.2.3", []tv{
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", true},
|
||||
{"1.2.2", false},
|
||||
}},
|
||||
{"<1.2.3", []tv{
|
||||
{"1.2.2", true},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"<=1.2.3", []tv{
|
||||
{"1.2.2", true},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"1.2.3", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"=1.2.3", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"==1.2.3", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"!=1.2.3", []tv{
|
||||
{"1.2.2", true},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", true},
|
||||
}},
|
||||
{"!1.2.3", []tv{
|
||||
{"1.2.2", true},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", true},
|
||||
}},
|
||||
// Simple Expression errors
|
||||
{">>1.2.3", nil},
|
||||
{"!1.2.3", nil},
|
||||
{"1.0", nil},
|
||||
{"string", nil},
|
||||
{"", nil},
|
||||
{"fo.ob.ar.x", nil},
|
||||
// AND Expressions
|
||||
{">1.2.2 <1.2.4", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{"<1.2.2 <1.2.4", []tv{
|
||||
{"1.2.1", true},
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
{">1.2.2 <1.2.5 !=1.2.4", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
{"1.2.5", false},
|
||||
}},
|
||||
{">1.2.2 <1.2.5 !1.2.4", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
{"1.2.5", false},
|
||||
}},
|
||||
// OR Expressions
|
||||
{">1.2.2 || <1.2.4", []tv{
|
||||
{"1.2.2", true},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", true},
|
||||
}},
|
||||
{"<1.2.2 || >1.2.4", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", false},
|
||||
{"1.2.4", false},
|
||||
}},
|
||||
// Wildcard expressions
|
||||
{">1.x", []tv{
|
||||
{"0.1.9", false},
|
||||
{"1.2.6", false},
|
||||
{"1.9.0", false},
|
||||
{"2.0.0", true},
|
||||
}},
|
||||
{">1.2.x", []tv{
|
||||
{"1.1.9", false},
|
||||
{"1.2.6", false},
|
||||
{"1.3.0", true},
|
||||
}},
|
||||
// Combined Expressions
|
||||
{">1.2.2 <1.2.4 || >=2.0.0", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
{"2.0.0", true},
|
||||
{"2.0.1", true},
|
||||
}},
|
||||
{"1.x || >=2.0.x <2.2.x", []tv{
|
||||
{"0.9.2", false},
|
||||
{"1.2.2", true},
|
||||
{"2.0.0", true},
|
||||
{"2.1.8", true},
|
||||
{"2.2.0", false},
|
||||
}},
|
||||
{">1.2.2 <1.2.4 || >=2.0.0 <3.0.0", []tv{
|
||||
{"1.2.2", false},
|
||||
{"1.2.3", true},
|
||||
{"1.2.4", false},
|
||||
{"2.0.0", true},
|
||||
{"2.0.1", true},
|
||||
{"2.9.9", true},
|
||||
{"3.0.0", false},
|
||||
}},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
r, err := ParseRange(tc.i)
|
||||
if err != nil && tc.t != nil {
|
||||
t.Errorf("Error parsing range %q: %s", tc.i, err)
|
||||
continue
|
||||
}
|
||||
for _, tvc := range tc.t {
|
||||
v := MustParse(tvc.v)
|
||||
if res := r(v); res != tvc.b {
|
||||
t.Errorf("Invalid for case %q matching %q: Expected %t, got: %t", tc.i, tvc.v, tvc.b, res)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func TestMustParseRange(t *testing.T) {
|
||||
testCase := ">1.2.2 <1.2.4 || >=2.0.0 <3.0.0"
|
||||
r := MustParseRange(testCase)
|
||||
if !r(MustParse("1.2.3")) {
|
||||
t.Errorf("Unexpected range behavior on MustParseRange")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMustParseRange_panic(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Errorf("Should have panicked")
|
||||
}
|
||||
}()
|
||||
_ = MustParseRange("invalid version")
|
||||
}
|
||||
|
||||
func BenchmarkRangeParseSimple(b *testing.B) {
|
||||
const VERSION = ">1.0.0"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
ParseRange(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRangeParseAverage(b *testing.B) {
|
||||
const VERSION = ">=1.0.0 <2.0.0"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
ParseRange(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRangeParseComplex(b *testing.B) {
|
||||
const VERSION = ">=1.0.0 <2.0.0 || >=3.0.1 <4.0.0 !=3.0.3 || >=5.0.0"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
ParseRange(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRangeMatchSimple(b *testing.B) {
|
||||
const VERSION = ">1.0.0"
|
||||
r, _ := ParseRange(VERSION)
|
||||
v := MustParse("2.0.0")
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
r(v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRangeMatchAverage(b *testing.B) {
|
||||
const VERSION = ">=1.0.0 <2.0.0"
|
||||
r, _ := ParseRange(VERSION)
|
||||
v := MustParse("1.2.3")
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
r(v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRangeMatchComplex(b *testing.B) {
|
||||
const VERSION = ">=1.0.0 <2.0.0 || >=3.0.1 <4.0.0 !=3.0.3 || >=5.0.0"
|
||||
r, _ := ParseRange(VERSION)
|
||||
v := MustParse("5.0.1")
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
r(v)
|
||||
}
|
||||
}
|
458
vendor/github.com/blang/semver/semver_test.go
generated
vendored
458
vendor/github.com/blang/semver/semver_test.go
generated
vendored
|
@ -1,458 +0,0 @@
|
|||
package semver
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func prstr(s string) PRVersion {
|
||||
return PRVersion{s, 0, false}
|
||||
}
|
||||
|
||||
func prnum(i uint64) PRVersion {
|
||||
return PRVersion{"", i, true}
|
||||
}
|
||||
|
||||
type formatTest struct {
|
||||
v Version
|
||||
result string
|
||||
}
|
||||
|
||||
var formatTests = []formatTest{
|
||||
{Version{1, 2, 3, nil, nil}, "1.2.3"},
|
||||
{Version{0, 0, 1, nil, nil}, "0.0.1"},
|
||||
{Version{0, 0, 1, []PRVersion{prstr("alpha"), prstr("preview")}, []string{"123", "456"}}, "0.0.1-alpha.preview+123.456"},
|
||||
{Version{1, 2, 3, []PRVersion{prstr("alpha"), prnum(1)}, []string{"123", "456"}}, "1.2.3-alpha.1+123.456"},
|
||||
{Version{1, 2, 3, []PRVersion{prstr("alpha"), prnum(1)}, nil}, "1.2.3-alpha.1"},
|
||||
{Version{1, 2, 3, nil, []string{"123", "456"}}, "1.2.3+123.456"},
|
||||
// Prereleases and build metadata hyphens
|
||||
{Version{1, 2, 3, []PRVersion{prstr("alpha"), prstr("b-eta")}, []string{"123", "b-uild"}}, "1.2.3-alpha.b-eta+123.b-uild"},
|
||||
{Version{1, 2, 3, nil, []string{"123", "b-uild"}}, "1.2.3+123.b-uild"},
|
||||
{Version{1, 2, 3, []PRVersion{prstr("alpha"), prstr("b-eta")}, nil}, "1.2.3-alpha.b-eta"},
|
||||
}
|
||||
|
||||
var tolerantFormatTests = []formatTest{
|
||||
{Version{1, 2, 3, nil, nil}, "v1.2.3"},
|
||||
{Version{1, 2, 3, nil, nil}, " 1.2.3 "},
|
||||
{Version{1, 2, 0, nil, nil}, "1.2"},
|
||||
{Version{1, 0, 0, nil, nil}, "1"},
|
||||
}
|
||||
|
||||
func TestStringer(t *testing.T) {
|
||||
for _, test := range formatTests {
|
||||
if res := test.v.String(); res != test.result {
|
||||
t.Errorf("Stringer, expected %q but got %q", test.result, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
for _, test := range formatTests {
|
||||
if v, err := Parse(test.result); err != nil {
|
||||
t.Errorf("Error parsing %q: %q", test.result, err)
|
||||
} else if comp := v.Compare(test.v); comp != 0 {
|
||||
t.Errorf("Parsing, expected %q but got %q, comp: %d ", test.v, v, comp)
|
||||
} else if err := v.Validate(); err != nil {
|
||||
t.Errorf("Error validating parsed version %q: %q", test.v, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseTolerant(t *testing.T) {
|
||||
for _, test := range tolerantFormatTests {
|
||||
if v, err := ParseTolerant(test.result); err != nil {
|
||||
t.Errorf("Error parsing %q: %q", test.result, err)
|
||||
} else if comp := v.Compare(test.v); comp != 0 {
|
||||
t.Errorf("Parsing, expected %q but got %q, comp: %d ", test.v, v, comp)
|
||||
} else if err := v.Validate(); err != nil {
|
||||
t.Errorf("Error validating parsed version %q: %q", test.v, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMustParse(t *testing.T) {
|
||||
_ = MustParse("32.2.1-alpha")
|
||||
}
|
||||
|
||||
func TestMustParse_panic(t *testing.T) {
|
||||
defer func() {
|
||||
if recover() == nil {
|
||||
t.Errorf("Should have panicked")
|
||||
}
|
||||
}()
|
||||
_ = MustParse("invalid version")
|
||||
}
|
||||
|
||||
func TestValidate(t *testing.T) {
|
||||
for _, test := range formatTests {
|
||||
if err := test.v.Validate(); err != nil {
|
||||
t.Errorf("Error validating %q: %q", test.v, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type compareTest struct {
|
||||
v1 Version
|
||||
v2 Version
|
||||
result int
|
||||
}
|
||||
|
||||
var compareTests = []compareTest{
|
||||
{Version{1, 0, 0, nil, nil}, Version{1, 0, 0, nil, nil}, 0},
|
||||
{Version{2, 0, 0, nil, nil}, Version{1, 0, 0, nil, nil}, 1},
|
||||
{Version{0, 1, 0, nil, nil}, Version{0, 1, 0, nil, nil}, 0},
|
||||
{Version{0, 2, 0, nil, nil}, Version{0, 1, 0, nil, nil}, 1},
|
||||
{Version{0, 0, 1, nil, nil}, Version{0, 0, 1, nil, nil}, 0},
|
||||
{Version{0, 0, 2, nil, nil}, Version{0, 0, 1, nil, nil}, 1},
|
||||
{Version{1, 2, 3, nil, nil}, Version{1, 2, 3, nil, nil}, 0},
|
||||
{Version{2, 2, 4, nil, nil}, Version{1, 2, 4, nil, nil}, 1},
|
||||
{Version{1, 3, 3, nil, nil}, Version{1, 2, 3, nil, nil}, 1},
|
||||
{Version{1, 2, 4, nil, nil}, Version{1, 2, 3, nil, nil}, 1},
|
||||
|
||||
// Spec Examples #11
|
||||
{Version{1, 0, 0, nil, nil}, Version{2, 0, 0, nil, nil}, -1},
|
||||
{Version{2, 0, 0, nil, nil}, Version{2, 1, 0, nil, nil}, -1},
|
||||
{Version{2, 1, 0, nil, nil}, Version{2, 1, 1, nil, nil}, -1},
|
||||
|
||||
// Spec Examples #9
|
||||
{Version{1, 0, 0, nil, nil}, Version{1, 0, 0, []PRVersion{prstr("alpha")}, nil}, 1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("alpha")}, nil}, Version{1, 0, 0, []PRVersion{prstr("alpha"), prnum(1)}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("alpha"), prnum(1)}, nil}, Version{1, 0, 0, []PRVersion{prstr("alpha"), prstr("beta")}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("alpha"), prstr("beta")}, nil}, Version{1, 0, 0, []PRVersion{prstr("beta")}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("beta")}, nil}, Version{1, 0, 0, []PRVersion{prstr("beta"), prnum(2)}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("beta"), prnum(2)}, nil}, Version{1, 0, 0, []PRVersion{prstr("beta"), prnum(11)}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("beta"), prnum(11)}, nil}, Version{1, 0, 0, []PRVersion{prstr("rc"), prnum(1)}, nil}, -1},
|
||||
{Version{1, 0, 0, []PRVersion{prstr("rc"), prnum(1)}, nil}, Version{1, 0, 0, nil, nil}, -1},
|
||||
|
||||
// Ignore Build metadata
|
||||
{Version{1, 0, 0, nil, []string{"1", "2", "3"}}, Version{1, 0, 0, nil, nil}, 0},
|
||||
}
|
||||
|
||||
func TestCompare(t *testing.T) {
|
||||
for _, test := range compareTests {
|
||||
if res := test.v1.Compare(test.v2); res != test.result {
|
||||
t.Errorf("Comparing %q : %q, expected %d but got %d", test.v1, test.v2, test.result, res)
|
||||
}
|
||||
//Test counterpart
|
||||
if res := test.v2.Compare(test.v1); res != -test.result {
|
||||
t.Errorf("Comparing %q : %q, expected %d but got %d", test.v2, test.v1, -test.result, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type wrongformatTest struct {
|
||||
v *Version
|
||||
str string
|
||||
}
|
||||
|
||||
var wrongformatTests = []wrongformatTest{
|
||||
{nil, ""},
|
||||
{nil, "."},
|
||||
{nil, "1."},
|
||||
{nil, ".1"},
|
||||
{nil, "a.b.c"},
|
||||
{nil, "1.a.b"},
|
||||
{nil, "1.1.a"},
|
||||
{nil, "1.a.1"},
|
||||
{nil, "a.1.1"},
|
||||
{nil, ".."},
|
||||
{nil, "1.."},
|
||||
{nil, "1.1."},
|
||||
{nil, "1..1"},
|
||||
{nil, "1.1.+123"},
|
||||
{nil, "1.1.-beta"},
|
||||
{nil, "-1.1.1"},
|
||||
{nil, "1.-1.1"},
|
||||
{nil, "1.1.-1"},
|
||||
// giant numbers
|
||||
{nil, "20000000000000000000.1.1"},
|
||||
{nil, "1.20000000000000000000.1"},
|
||||
{nil, "1.1.20000000000000000000"},
|
||||
{nil, "1.1.1-20000000000000000000"},
|
||||
// Leading zeroes
|
||||
{nil, "01.1.1"},
|
||||
{nil, "001.1.1"},
|
||||
{nil, "1.01.1"},
|
||||
{nil, "1.001.1"},
|
||||
{nil, "1.1.01"},
|
||||
{nil, "1.1.001"},
|
||||
{nil, "1.1.1-01"},
|
||||
{nil, "1.1.1-001"},
|
||||
{nil, "1.1.1-beta.01"},
|
||||
{nil, "1.1.1-beta.001"},
|
||||
{&Version{0, 0, 0, []PRVersion{prstr("!")}, nil}, "0.0.0-!"},
|
||||
{&Version{0, 0, 0, nil, []string{"!"}}, "0.0.0+!"},
|
||||
// empty prversion
|
||||
{&Version{0, 0, 0, []PRVersion{prstr(""), prstr("alpha")}, nil}, "0.0.0-.alpha"},
|
||||
// empty build meta data
|
||||
{&Version{0, 0, 0, []PRVersion{prstr("alpha")}, []string{""}}, "0.0.0-alpha+"},
|
||||
{&Version{0, 0, 0, []PRVersion{prstr("alpha")}, []string{"test", ""}}, "0.0.0-alpha+test."},
|
||||
}
|
||||
|
||||
func TestWrongFormat(t *testing.T) {
|
||||
for _, test := range wrongformatTests {
|
||||
|
||||
if res, err := Parse(test.str); err == nil {
|
||||
t.Errorf("Parsing wrong format version %q, expected error but got %q", test.str, res)
|
||||
}
|
||||
|
||||
if test.v != nil {
|
||||
if err := test.v.Validate(); err == nil {
|
||||
t.Errorf("Validating wrong format version %q (%q), expected error", test.v, test.str)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var wrongTolerantFormatTests = []wrongformatTest{
|
||||
{nil, "1.0+abc"},
|
||||
{nil, "1.0-rc.1"},
|
||||
}
|
||||
|
||||
func TestWrongTolerantFormat(t *testing.T) {
|
||||
for _, test := range wrongTolerantFormatTests {
|
||||
if res, err := ParseTolerant(test.str); err == nil {
|
||||
t.Errorf("Parsing wrong format version %q, expected error but got %q", test.str, res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareHelper(t *testing.T) {
|
||||
v := Version{1, 0, 0, []PRVersion{prstr("alpha")}, nil}
|
||||
v1 := Version{1, 0, 0, nil, nil}
|
||||
if !v.EQ(v) {
|
||||
t.Errorf("%q should be equal to %q", v, v)
|
||||
}
|
||||
if !v.Equals(v) {
|
||||
t.Errorf("%q should be equal to %q", v, v)
|
||||
}
|
||||
if !v1.NE(v) {
|
||||
t.Errorf("%q should not be equal to %q", v1, v)
|
||||
}
|
||||
if !v.GTE(v) {
|
||||
t.Errorf("%q should be greater than or equal to %q", v, v)
|
||||
}
|
||||
if !v.LTE(v) {
|
||||
t.Errorf("%q should be less than or equal to %q", v, v)
|
||||
}
|
||||
if !v.LT(v1) {
|
||||
t.Errorf("%q should be less than %q", v, v1)
|
||||
}
|
||||
if !v.LTE(v1) {
|
||||
t.Errorf("%q should be less than or equal %q", v, v1)
|
||||
}
|
||||
if !v.LE(v1) {
|
||||
t.Errorf("%q should be less than or equal %q", v, v1)
|
||||
}
|
||||
if !v1.GT(v) {
|
||||
t.Errorf("%q should be greater than %q", v1, v)
|
||||
}
|
||||
if !v1.GTE(v) {
|
||||
t.Errorf("%q should be greater than or equal %q", v1, v)
|
||||
}
|
||||
if !v1.GE(v) {
|
||||
t.Errorf("%q should be greater than or equal %q", v1, v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreReleaseVersions(t *testing.T) {
|
||||
p1, err := NewPRVersion("123")
|
||||
if !p1.IsNumeric() {
|
||||
t.Errorf("Expected numeric prversion, got %q", p1)
|
||||
}
|
||||
if p1.VersionNum != 123 {
|
||||
t.Error("Wrong prversion number")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error %q", err)
|
||||
}
|
||||
p2, err := NewPRVersion("alpha")
|
||||
if p2.IsNumeric() {
|
||||
t.Errorf("Expected non-numeric prversion, got %q", p2)
|
||||
}
|
||||
if p2.VersionStr != "alpha" {
|
||||
t.Error("Wrong prversion string")
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMetaDataVersions(t *testing.T) {
|
||||
_, err := NewBuildVersion("123")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %q", err)
|
||||
}
|
||||
|
||||
_, err = NewBuildVersion("build")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %q", err)
|
||||
}
|
||||
|
||||
_, err = NewBuildVersion("test?")
|
||||
if err == nil {
|
||||
t.Error("Expected error, got none")
|
||||
}
|
||||
|
||||
_, err = NewBuildVersion("")
|
||||
if err == nil {
|
||||
t.Error("Expected error, got none")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewHelper(t *testing.T) {
|
||||
v, err := New("1.2.3")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %q", err)
|
||||
}
|
||||
|
||||
// New returns pointer
|
||||
if v == nil {
|
||||
t.Fatal("Version is nil")
|
||||
}
|
||||
if v.Compare(Version{1, 2, 3, nil, nil}) != 0 {
|
||||
t.Fatal("Unexpected comparison problem")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeHelper(t *testing.T) {
|
||||
v, err := Make("1.2.3")
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error %q", err)
|
||||
}
|
||||
if v.Compare(Version{1, 2, 3, nil, nil}) != 0 {
|
||||
t.Fatal("Unexpected comparison problem")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseSimple(b *testing.B) {
|
||||
const VERSION = "0.0.1"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Parse(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseComplex(b *testing.B) {
|
||||
const VERSION = "0.0.1-alpha.preview+123.456"
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Parse(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseAverage(b *testing.B) {
|
||||
l := len(formatTests)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Parse(formatTests[n%l].result)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseTolerantAverage(b *testing.B) {
|
||||
l := len(tolerantFormatTests)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
ParseTolerant(tolerantFormatTests[n%l].result)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringSimple(b *testing.B) {
|
||||
const VERSION = "0.0.1"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.String()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringLarger(b *testing.B) {
|
||||
const VERSION = "11.15.2012"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.String()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringComplex(b *testing.B) {
|
||||
const VERSION = "0.0.1-alpha.preview+123.456"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.String()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringAverage(b *testing.B) {
|
||||
l := len(formatTests)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
formatTests[n%l].v.String()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkValidateSimple(b *testing.B) {
|
||||
const VERSION = "0.0.1"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.Validate()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkValidateComplex(b *testing.B) {
|
||||
const VERSION = "0.0.1-alpha.preview+123.456"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.Validate()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkValidateAverage(b *testing.B) {
|
||||
l := len(formatTests)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
formatTests[n%l].v.Validate()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompareSimple(b *testing.B) {
|
||||
const VERSION = "0.0.1"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.Compare(v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompareComplex(b *testing.B) {
|
||||
const VERSION = "0.0.1-alpha.preview+123.456"
|
||||
v, _ := Parse(VERSION)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
v.Compare(v)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompareAverage(b *testing.B) {
|
||||
l := len(compareTests)
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
compareTests[n%l].v1.Compare((compareTests[n%l].v2))
|
||||
}
|
||||
}
|
30
vendor/github.com/blang/semver/sort_test.go
generated
vendored
30
vendor/github.com/blang/semver/sort_test.go
generated
vendored
|
@ -1,30 +0,0 @@
|
|||
package semver
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSort(t *testing.T) {
|
||||
v100, _ := Parse("1.0.0")
|
||||
v010, _ := Parse("0.1.0")
|
||||
v001, _ := Parse("0.0.1")
|
||||
versions := []Version{v010, v100, v001}
|
||||
Sort(versions)
|
||||
|
||||
correct := []Version{v001, v010, v100}
|
||||
if !reflect.DeepEqual(versions, correct) {
|
||||
t.Fatalf("Sort returned wrong order: %s", versions)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkSort(b *testing.B) {
|
||||
v100, _ := Parse("1.0.0")
|
||||
v010, _ := Parse("0.1.0")
|
||||
v001, _ := Parse("0.0.1")
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for n := 0; n < b.N; n++ {
|
||||
Sort([]Version{v010, v100, v001})
|
||||
}
|
||||
}
|
38
vendor/github.com/blang/semver/sql_test.go
generated
vendored
38
vendor/github.com/blang/semver/sql_test.go
generated
vendored
|
@ -1,38 +0,0 @@
|
|||
package semver
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
type scanTest struct {
|
||||
val interface{}
|
||||
shouldError bool
|
||||
expected string
|
||||
}
|
||||
|
||||
var scanTests = []scanTest{
|
||||
{"1.2.3", false, "1.2.3"},
|
||||
{[]byte("1.2.3"), false, "1.2.3"},
|
||||
{7, true, ""},
|
||||
{7e4, true, ""},
|
||||
{true, true, ""},
|
||||
}
|
||||
|
||||
func TestScanString(t *testing.T) {
|
||||
for _, tc := range scanTests {
|
||||
s := &Version{}
|
||||
err := s.Scan(tc.val)
|
||||
if tc.shouldError {
|
||||
if err == nil {
|
||||
t.Fatalf("Scan did not return an error on %v (%T)", tc.val, tc.val)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Fatalf("Scan returned an unexpected error: %s (%T) on %v (%T)", tc.val, tc.val, tc.val, tc.val)
|
||||
}
|
||||
if val, _ := s.Value(); val != tc.expected {
|
||||
t.Errorf("Wrong Value returned, expected %q, got %q", tc.expected, val)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue