generated from gopherdojo/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
66 lines (58 loc) · 1.18 KB
/
main_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
package main
import (
"bytes"
"path/filepath"
"reflect"
"testing"
)
func TestInput(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{
name: "match input channel",
in: "hoge",
want: "hoge",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
stdin := bytes.NewBufferString(test.in)
inc, _ := input(stdin)
select {
case in := <-inc:
if in != test.want {
t.Errorf(`want="%v" actual="%v"`, test.want, in)
}
}
})
}
}
func TestImportWords(t *testing.T) {
tests := []struct {
name string
filepath string
want []string
}{
{
name: "import testfile1",
filepath: filepath.Join("testdata", "words1.txt"),
want: []string{"gopher", "golang", "goroutines"},
},
{
name: "import testfile2",
filepath: filepath.Join("testdata", "words2.txt"),
want: []string{"java", "php", "erlang", "elixir"},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
got, _ := importWords(test.filepath)
if !reflect.DeepEqual(got, test.want) {
t.Errorf(`filepath="%v" want="%v" actual="%v"`, test.filepath, test.want, got)
}
})
}
}