-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain_test.go
61 lines (53 loc) · 1.22 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
package main
import (
"flag"
"os"
"testing"
)
func TestTranslate(t *testing.T) {
t.Run("translate test", func(t *testing.T) {
tests := []struct {
source string
target string
text string
want string
}{
{"ja", "en", "お腹が空いた", "I am hungry"},
{"en", "ja", "I'm hungry", "お腹が空きました"},
}
for _, test := range tests {
result, err := translate(test.text, test.source, test.target)
if err != nil {
t.Errorf("cannnot translate %s", err)
}
if result != test.want {
t.Errorf("result is wrong. want=%s, actual=%s", test.want, result)
}
}
})
t.Run("run test", func(t *testing.T) {
tests := []struct {
text string
args []string
endpoint string
want int
}{
{"", []string{}, "", -1},
{"", []string{"hello"}, "", 0},
{"hello", []string{}, "", 0},
{"hello", []string{}, "invalid_endpoint", -1},
}
for i, test := range tests {
if test.endpoint != "" {
os.Setenv("GTRAN_ENDPOINT", test.endpoint)
}
if test.text != "" {
flag.CommandLine.Set("text", test.text)
}
result := run(test.args)
if test.want != result {
t.Errorf(" %d result is wrong. want=%d, actual=%d", i, test.want, result)
}
}
})
}