File: version_test.go

package info (click to toggle)
sia 1.3.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,340 kB
  • sloc: makefile: 80; sh: 52
file content (53 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package build

import (
	"testing"
)

// TestVersionCmp checks that in all cases, VersionCmp returns the correct
// result.
func TestVersionCmp(t *testing.T) {
	versionTests := []struct {
		a, b string
		exp  int
	}{
		{"0.1", "0.0.9", 1},
		{"0.1", "0.1", 0},
		{"0.1", "0.1.1", -1},
		{"0.1", "0.1.0", -1},
		{"0.1", "1.1", -1},
		{"0.1.1.0", "0.1.1", 1},
	}

	for _, test := range versionTests {
		if actual := VersionCmp(test.a, test.b); actual != test.exp {
			t.Errorf("Comparing %v to %v should return %v (got %v)", test.a, test.b, test.exp, actual)
		}
	}
}

// TestIsVersion tests the IsVersion function.
func TestIsVersion(t *testing.T) {
	versionTests := []struct {
		str string
		exp bool
	}{
		{"1.0", true},
		{"1", true},
		{"0.1.2.3.4.5", true},

		{"foo", false},
		{".1", false},
		{"1.", false},
		{"a.b", false},
		{"1.o", false},
		{".", false},
		{"", false},
	}

	for _, test := range versionTests {
		if IsVersion(test.str) != test.exp {
			t.Errorf("IsVersion(%v) should return %v", test.str, test.exp)
		}
	}
}