-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwordlist_test.go
65 lines (55 loc) · 1.17 KB
/
wordlist_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
package sonar
import (
"io/ioutil"
"strings"
"testing"
)
type TestCase struct {
In []string
Out []string
}
var testCases = []TestCase{
TestCase{In: []string{}, Out: []string{}},
TestCase{In: []string{""}, Out: []string{""}},
TestCase{In: []string{"one", "two", "three"}, Out: []string{"one", "two", "three"}},
}
func TestInternal(t *testing.T) {
for _, testCase := range testCases {
wordlist := NewInternal(testCase.In)
c := wordlist.GetChannel()
for _, expected := range testCase.Out {
word := <-c
if expected != word {
t.Fail()
}
}
// make sure we have nothing left
if _, ok := <-c; ok {
t.Fail()
}
}
}
func TestFile(t *testing.T) {
for _, testCase := range testCases {
file := func(data []string) string {
ret := make([]string, len(data))
for i, value := range data {
ret[i] = value + "\n"
}
return strings.Join(ret, "")
}(testCase.In)
fp := ioutil.NopCloser(strings.NewReader(file))
wordlist := NewFile(fp)
c := wordlist.GetChannel()
for _, expected := range testCase.Out {
word := <-c
if expected != word {
t.Fail()
}
}
// make sure we have nothing left
if _, ok := <-c; ok {
t.Fail()
}
}
}