예제 #1
0
func ExampleCompare() {
	v1, _ := semver.New("1.6.0")
	v2, _ := semver.New("1.5.0")
	// do something with error
	if v1.Compare(v2) > 0 {
		fmt.Println("v1 is larger")
	}
	// Output: v1 is larger
}
예제 #2
0
func BenchmarkCompareComplex(b *testing.B) {
	const VERSION = "0.0.1-alpha.preview+123.456"
	const VERSION2 = "0.0.1-alpha.preview+123.456"
	v, _ := semver.New(VERSION)
	v2, _ := semver.New(VERSION2)

	b.ReportAllocs()
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		v.Compare(v2)
	}
}
예제 #3
0
func TestCorrectFormat(t *testing.T) {
	for _, version := range correctVersions {
		_, err := semver.New(version)
		if err != nil {
			t.Errorf("New(%q) => %v, want <nil>", version, err)
		}
	}
}
예제 #4
0
func handleOperator(p *parser) node {
	var set nodeSet
	for {
		i := p.next()

		switch i.typ {
		case itemVersion:
			ver1, _ := semver.New(i.val)
			if i = p.next(); i.typ == itemAdvanced {
				if i.val == string(operatorHY) {
					i = p.next()
					ver2, _ := semver.New(i.val)
					nc := hy2op(ver1, ver2)
					set = append(set, nc)
					return set
				}
			}
			p.backup()
			nc := nodeSet{nodeComparison{eq, ver1}}
			set = append(set, nc)
			return set
		case itemAdvanced:
			if i.val == string(operatorTR) {
				i := p.next()
				if i.typ != itemError {
					nc := tld2op(i)
					set = append(set, nc)
					return set
				}

			}
		case itemXRange:
			nc := xr2op(i)
			set = append(set, nc)
			return set
		default:
			v := p.next()
			ver, _ := semver.New(v.val)
			nc := nodeSet{nodeComparison{comparators[i.val], ver}}
			set = append(set, nc...)
			return set
		}

	}
}
예제 #5
0
func BenchmarkParseAverage(b *testing.B) {
	l := len(correctVersions)

	b.ReportAllocs()
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		semver.New(correctVersions[n%l])
	}
}
예제 #6
0
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++ {
		semver.New(VERSION)
	}
}
예제 #7
0
func BenchmarkParseSimple(b *testing.B) {
	const VERSION = "0.0.1"

	b.ReportAllocs()
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		semver.New(VERSION)
	}
}
예제 #8
0
func BenchmarkCompareSimple(b *testing.B) {
	const VERSION = "0.0.1"
	v, _ := semver.New(VERSION)

	b.ReportAllocs()
	b.ResetTimer()
	for n := 0; n < b.N; n++ {
		v.Compare(v)
	}
}
예제 #9
0
func TestBadFormat(t *testing.T) {
	for _, version := range badVersions {
		_, err := semver.New(version)
		if err == nil {
			// TODO: Set up error types
			t.Errorf("New(%q) => %v, want Error", version, err)
		}

	}
}
예제 #10
0
func tld2op(i item) node {
	if i.typ == itemXRange {
		return xr2op(i)
	}
	v1, _ := semver.New(i.val)
	v2 := *v1
	v2.IncrementMinor()
	v2.SetPatch(0)
	return nodeSet{
		nodeComparison{gte, v1},
		nodeComparison{lt, &v2},
	}
}
예제 #11
0
func TestNew(t *testing.T) {
	expected := "1.0.3-alpha.1+35.45"

	ver, err := semver.New(expected)
	if err != nil {
		t.Errorf(fmt.Sprint(err))
	}

	result := fmt.Sprint(ver)
	if result != expected {
		t.Errorf("Stringer() => %q, want %q", result, expected)
	}

}