-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate_parse_test.go
More file actions
48 lines (42 loc) · 1.38 KB
/
translate_parse_test.go
File metadata and controls
48 lines (42 loc) · 1.38 KB
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 (
"gopkg.in/jdkato/prose.v2"
"testing"
)
func TestTranslateTextWithParse(t *testing.T) {
golds := []struct {
text string
translatedText string
}{
{"Homer Simpson.", "Homer Simpson."},
{"test1 27", "a1[alt:a2] 27"},
}
for i, gold := range golds {
translatedText := TranslateTextWithParse("NL", "EN", gold.text, 3)
if gold.translatedText != translatedText {
t.Fatalf("Failed case %d. Expected translation '%s' but actual was '%s'", i, gold.translatedText, translatedText)
}
}
}
func TestSplitToSequences(t *testing.T) {
golds := []struct {
tokens []prose.Token
expectedSequences []string
}{
0: {[]prose.Token{{Tag: "(", Text: "("}, {Tag: "JJ", Text: "Something"}, {Tag: ")", Text: ")"}},
[]string{"(", "Something", ")"}},
1: {[]prose.Token{{Tag: "PERSON", Text: "Homer Simpson"}, {Tag: ".", Text: "."}},
[]string{"Homer Simpson", "."}},
2: {[]prose.Token{{Tag: "NN", Text: "http://google.com"}, {Tag: "SYM", Text: ":D"}},
[]string{"http://google.com", ":D"}},
3: {[]prose.Token{{Tag: "JJ", Text: "test1"}, {Tag: "SYM", Text: ":)"}},
[]string{"test1", ":)"}},
}
for i, gold := range golds {
for j, seq := range splitToSequences(gold.tokens) {
if seq != gold.expectedSequences[j] {
t.Fatalf("Failed case %d. Expected sequence:'%s' but splitted was:'%s'", i, gold.expectedSequences[j], seq)
}
}
}
}