-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
48 lines (42 loc) · 1.08 KB
/
utils_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
package main
import (
"os"
"sort"
"strings"
"testing"
)
func TestNotIn(t *testing.T) {
notInTests := [][][]string{
{ { "abc", "xyz", "123" }, { "abc", "xyz", "123" }, {} },
{ { "abc", "123" }, { "xyz", "123" }, { "abc" } },
{ { "xyz", "123" }, { "abc", "123" }, { "xyz" } },
{ { "abc", "xyz" }, {}, { "abc", "xyz" } },
{ {}, { "abc", "xyz" }, {} },
}
for _, v := range notInTests {
for i := range v {
// v[1], v[2] MUST be sorted for binary search
sort.Strings(v[i])
}
r := notIn(v[0], v[1])
if strings.Join(r, "\n") != strings.Join(v[2], "\n") {
t.Errorf("Expected %v, got %v", v[2], r)
}
}
}
func TestAskConfirm(t *testing.T) {
askTests := map[bool][]string{
true: { "y", "Y", "yes", "Yes", "YES" },
false: { "n", "N", "no", "No", "NO", "1", "0", "A", "*", "z" },
}
for result := range askTests {
for _, v := range askTests[result] {
tmpFile(t, v, func(in *os.File){
r := askConfirm(in)
if r != result {
t.Errorf("Expected %v, got %v", result, r)
}
})
}
}
}