1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func TestCompare(t *testing.T) { test2(t, compareTests, "Compare", Compare) }
14 var compareTests = []testCase2[string, string, int]{
22 {"1.19", "1.19.0", 0},
23 {"1.19rc1", "1.19", -1},
24 {"1.20", "1.20.0", 0},
25 {"1.20rc1", "1.20", -1},
26 {"1.21", "1.21.0", -1},
27 {"1.21", "1.21rc1", -1},
28 {"1.21rc1", "1.21.0", -1},
30 {"1.19", "1.19.1", -1},
31 {"1.19rc1", "1.19", -1},
32 {"1.19rc1", "1.19.1", -1},
33 {"1.19rc1", "1.19rc2", -1},
34 {"1.19.0", "1.19.1", -1},
35 {"1.19rc1", "1.19.0", -1},
36 {"1.19alpha3", "1.19beta2", -1},
37 {"1.19beta2", "1.19rc1", -1},
38 {"1.1", "1.99999999999999998", -1},
39 {"1.99999999999999998", "1.99999999999999999", -1},
42 func TestLang(t *testing.T) { test1(t, langTests, "Lang", Lang) }
44 var langTests = []testCase1[string, string]{
49 {"1.999testmod", "1.999"},
52 func TestIsLang(t *testing.T) { test1(t, isLangTests, "IsLang", IsLang) }
54 var isLangTests = []testCase1[string, bool]{
57 {"1.999testmod", false},
60 {"1.20", false}, // == 1.20.0
61 {"1.19", false}, // == 1.20.0
62 {"1.3", false}, // == 1.3.0
63 {"1.2", false}, // == 1.2.0
64 {"1", false}, // == 1.0.0
67 func TestPrev(t *testing.T) { test1(t, prevTests, "Prev", Prev) }
69 var prevTests = []testCase1[string, string]{
76 {"1.99999999999999999", "1.99999999999999998"},
77 {"1.40000000000000000", "1.39999999999999999"},
80 func TestIsValid(t *testing.T) { test1(t, isValidTests, "IsValid", IsValid) }
82 var isValidTests = []testCase1[string, bool]{
85 {"1.999testmod", true},
86 {"1.600+auto", false},
99 type testCase1[In, Out any] struct {
104 type testCase2[In1, In2, Out any] struct {
110 type testCase3[In1, In2, In3, Out any] struct {
117 func test1[In, Out any](t *testing.T, tests []testCase1[In, Out], name string, f func(In) Out) {
119 for _, tt := range tests {
120 if out := f(tt.in); !reflect.DeepEqual(out, tt.out) {
121 t.Errorf("%s(%v) = %v, want %v", name, tt.in, out, tt.out)
126 func test2[In1, In2, Out any](t *testing.T, tests []testCase2[In1, In2, Out], name string, f func(In1, In2) Out) {
128 for _, tt := range tests {
129 if out := f(tt.in1, tt.in2); !reflect.DeepEqual(out, tt.out) {
130 t.Errorf("%s(%+v, %+v) = %+v, want %+v", name, tt.in1, tt.in2, out, tt.out)
135 func test3[In1, In2, In3, Out any](t *testing.T, tests []testCase3[In1, In2, In3, Out], name string, f func(In1, In2, In3) Out) {
137 for _, tt := range tests {
138 if out := f(tt.in1, tt.in2, tt.in3); !reflect.DeepEqual(out, tt.out) {
139 t.Errorf("%s(%+v, %+v, %+v) = %+v, want %+v", name, tt.in1, tt.in2, tt.in3, out, tt.out)