z_mirror/fmm

git clone https://git.raiguard.me/z_mirror/fmm

Caleb HeuerConsider a nil version to be equal8f22b8d

predep-parsing
1.3 KiB52 linesraw
1package main
2
3import "testing"
4
5func TestVersion(t *testing.T) {
6	tests := []struct {
7		input           string
8		output          string
9		outputWithBuild string
10		p0, p1, p2, p3  uint16
11	}{
12		{"1.0", "1.0.0", "1.0.0.0", 1, 0, 0, 0},
13		{"1.1.15", "1.1.15", "1.1.15.0", 1, 1, 15, 0},
14		{"2.3.4.5", "2.3.4", "2.3.4.5", 2, 3, 4, 5},
15		{"010.001.0100.0000001", "10.1.100", "10.1.100.1", 10, 1, 100, 1},
16	}
17	for _, test := range tests {
18		ver, err := newVersion(test.input)
19		if err != nil {
20			t.Error(err)
21		}
22		if ver[0] != test.p0 || ver[1] != test.p1 || ver[2] != test.p2 || ver[3] != test.p3 {
23			t.Error("Version parse mismatch:", test.input, ver)
24		}
25		verStr := ver.toString(false)
26		if verStr != test.output {
27			t.Error("Version string mismatch:", test.input, verStr)
28		}
29		verStrWithBuild := ver.toString(true)
30		if verStrWithBuild != test.outputWithBuild {
31			t.Error("Version string mismatch:", test.input, verStr)
32		}
33	}
34}
35
36func TestVersionCmp(t *testing.T) {
37	tests := []struct {
38		v1  Version
39		v2  Version
40		res VersionCmpRes
41	}{
42		{Version{1, 3, 1}, Version{2, 0}, VersionLt},
43		{Version{1, 5, 3}, Version{1, 5, 2}, VersionGt},
44		{Version{1, 5}, Version{1, 5, 0, 0}, VersionEq},
45	}
46	for _, test := range tests {
47		res := test.v1.cmp(&test.v2)
48		if res != test.res {
49			t.Error("Version comparison failure:", test.v1, test.v2, test.res, res)
50		}
51	}
52}