-
Notifications
You must be signed in to change notification settings - Fork 0
/
minicard_test.go
73 lines (62 loc) · 1.4 KB
/
minicard_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
67
68
69
70
71
72
73
package lingvo
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
"github.com/kylelemons/godebug/pretty"
)
func TestGetMinicard(t *testing.T) {
setup()
defer teardown()
// To make reflect.DeepEqual happy
testMinicard.client = client
mux.HandleFunc("/"+endpointMinicard, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"text": "冬",
"srcLang": Ch.code(),
"dstLang": Ru.code(),
})
fmt.Fprintf(w, testMinicardJSON)
})
s, err := client.GetMinicard(context.Background(), "冬", Ch, Ru)
if err != nil {
t.Errorf("unexpected error '%v'", err)
}
if got, want := s, testMinicard; !reflect.DeepEqual(got, want) {
diff := pretty.Compare(got, want)
t.Errorf("unexpected result, diff = %s", diff)
}
}
var testMinicard = &Minicard{
SourceLanguage: Ch,
TargetLanguage: Ru,
Heading: "冬",
Translation: Word{
Heading: "冬",
Translation: "зима́; зи́мний",
Dictionary: "Universal (Ch-Ru)",
Sound: "",
Type: ExactWord,
OriginalWord: "",
},
SeeAlso: []string{},
}
var testMinicardJSON = `
{
"SourceLanguage": 1028,
"TargetLanguage": 1049,
"Heading": "冬",
"Translation": {
"Heading": "冬",
"Translation": "зима́; зи́мний",
"DictionaryName": "Universal (Ch-Ru)",
"SoundName": "",
"Type": 1,
"OriginalWord": ""
},
"SeeAlso": []
}
`