-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmplfuncs_test.go
54 lines (48 loc) · 949 Bytes
/
tmplfuncs_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
package casper
import (
"fmt"
"testing"
)
func TestIsLastAndIsNotLast(t *testing.T) {
a := []int{1, 2, 3, 4}
testCases := []struct {
x int
isLast bool
}{
{-1, false},
{0, false},
{1, false},
{2, false},
{3, true},
{4, false},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("Case%v", i), func(t *testing.T) {
if isLast(tc.x, a) != tc.isLast {
t.Errorf("Got isLast=%v; want %v", isLast(tc.x, a), tc.isLast)
}
if isNotLast(tc.x, a) != !tc.isLast {
t.Errorf("Got isNotLast=%v; want %v", isNotLast(tc.x, a), !tc.isLast)
}
})
}
}
func TestQuote(t *testing.T) {
testCases := []struct {
a interface{}
q string
}{
{1, `"1"`},
{"", `""`},
{nil, `""`},
{"a", `"a"`},
{false, `"Unable to quote"`},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("Case%v", i), func(t *testing.T) {
if quote(tc.a) != tc.q {
t.Errorf("Got %v; want %v", quote(tc.a), tc.q)
}
})
}
}