generated from cunicu/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
version_test.go
68 lines (59 loc) · 1.32 KB
/
version_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-FileCopyrightText: 2023-2024 Steffen Vogel <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package iso7816_test
import (
"testing"
"github.com/stretchr/testify/require"
iso "cunicu.li/go-iso7816"
)
func TestParseVersion(t *testing.T) {
tests := map[string]iso.Version{
"1": {1, -1, -1},
"1.0": {1, 0, -1},
"1.0.0": {1, 0, 0},
"": {-1, -1, -1},
}
for strVer, expVer := range tests {
t.Run(strVer, func(t *testing.T) {
ver, err := iso.ParseVersion(strVer)
require.NoError(t, err)
require.Equal(t, expVer, ver)
})
}
}
func TestParseVersionError(t *testing.T) {
tests := []string{
"-1",
"a",
"a.1",
"1.2.3.4",
}
for _, strVer := range tests {
t.Run(strVer, func(t *testing.T) {
_, err := iso.ParseVersion(strVer)
require.Error(t, err)
})
}
}
func TestVersionLess(t *testing.T) {
tests := []struct {
a string
b string
less bool
}{
{"1.2.4", "1.2.4", false},
{"1.2.4", "1.2.3", true},
{"1.2.3", "1.2.4", false},
{"1", "1", false},
{"1", "2", false},
{"1", "0", true},
{"0", "1", false},
}
for _, test := range tests {
a, err := iso.ParseVersion(test.a)
require.NoError(t, err)
b, err := iso.ParseVersion(test.b)
require.NoError(t, err)
require.True(t, a.Less(b) == test.less, "%s > %s == %t", test.a, test.b, test.less)
}
}