-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgnlib_test.go
46 lines (40 loc) · 912 Bytes
/
gnlib_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
package gnlib_test
import (
"strings"
"testing"
"github.com/gnames/gnlib"
"github.com/stretchr/testify/assert"
)
func TestMap(t *testing.T) {
assert := assert.New(t)
test := []string{"a", "b", "c"}
res := gnlib.Map(test, func(s string) string {
return strings.ToUpper(s)
})
assert.Equal([]string{"A", "B", "C"}, res)
}
func TestFilter(t *testing.T) {
assert := assert.New(t)
test := []string{"a", "b", "c"}
res := gnlib.FilterFunc(test, func(s string) bool {
return s != "b"
})
assert.Equal([]string{"a", "c"}, res)
}
func TestCmpVersion(t *testing.T) {
assert := assert.New(t)
tests := []struct {
ver1, ver2 string
res int
}{
{"v1.2.3", "v1.2.3", 0},
{"v2.0.0", "v1.55.3", 1},
{"v1.3.1", "v1.4.2", -1},
{"v1.6.0", "v1.6.0.3", -1},
{"v1.6.0", "v1.6.0.3b", 0},
}
for _, v := range tests {
res := gnlib.CmpVersion(v.ver1, v.ver2)
assert.Equal(v.res, res)
}
}