carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package release
2
3import "testing"
4
5func TestParseSemVer(t *testing.T) {
6 good := map[string]SemVer{
7 "0.5.0": {0, 5, 0},
8 "1.0.0": {1, 0, 0},
9 "10.2.33": {10, 2, 33},
10 }
11 for s, want := range good {
12 got, ok := ParseSemVer(s)
13 if !ok || got != want {
14 t.Errorf("ParseSemVer(%q) = %v, %v; want %v, true", s, got, ok, want)
15 }
16 }
17 bad := []string{"", "0.5", "0.5.0.1", "v0.5.0", "0.05.0", "01.0.0", "0.5.0-3", "0.5.x", "-1.0.0", "0.5.0 "}
18 for _, s := range bad {
19 if _, ok := ParseSemVer(s); ok {
20 t.Errorf("ParseSemVer(%q) accepted; want refused", s)
21 }
22 }
23}
24
25func TestSemVerCompareAndNext(t *testing.T) {
26 if c := (SemVer{0, 5, 0}).Compare(SemVer{0, 5, 1}); c >= 0 {
27 t.Errorf("0.5.0 vs 0.5.1 = %d; want < 0", c)
28 }
29 if c := (SemVer{1, 0, 0}).Compare(SemVer{0, 9, 9}); c <= 0 {
30 t.Errorf("1.0.0 vs 0.9.9 = %d; want > 0", c)
31 }
32 if c := (SemVer{0, 5, 0}).Compare(SemVer{0, 5, 0}); c != 0 {
33 t.Errorf("equal compare = %d; want 0", c)
34 }
35 if got := (SemVer{0, 5, 0}).NextPatch(); got != (SemVer{0, 5, 1}) {
36 t.Errorf("NextPatch = %v; want 0.5.1", got)
37 }
38 if got := (SemVer{0, 5, 0}).String(); got != "0.5.0" {
39 t.Errorf("String = %q; want 0.5.0", got)
40 }
41}
42
43func TestSplitIteration(t *testing.T) {
44 tgt, n, ok := SplitIteration("0.5.0-3")
45 if !ok || tgt != (SemVer{0, 5, 0}) || n != 3 {
46 t.Fatalf("SplitIteration(0.5.0-3) = %v, %d, %v", tgt, n, ok)
47 }
48 if got := IterationVersion(SemVer{0, 5, 0}, 4); got != "0.5.0-4" {
49 t.Errorf("IterationVersion = %q; want 0.5.0-4", got)
50 }
51 bad := []string{"de2766f8", "0.5.0", "0.5.0-0", "0.5.0-03", "0.5.0-x", "0.5.0-3-4", "0.5.0-", ""}
52 for _, s := range bad {
53 if _, _, ok := SplitIteration(s); ok {
54 t.Errorf("SplitIteration(%q) accepted; want refused", s)
55 }
56 }
57}
58