2019-10-09 19:05:12 +00:00
|
|
|
package trans_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"."
|
|
|
|
"reflect"
|
2019-10-11 20:40:02 +00:00
|
|
|
"os"
|
2019-10-09 19:05:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-10-13 15:51:30 +00:00
|
|
|
type transTestData struct {
|
2019-10-13 15:05:27 +00:00
|
|
|
word string
|
|
|
|
fromLang string
|
|
|
|
toLang string
|
2019-10-11 20:08:06 +00:00
|
|
|
transOutput string
|
2019-10-09 19:05:12 +00:00
|
|
|
expectedResults []string
|
|
|
|
}
|
|
|
|
|
2019-10-13 15:51:30 +00:00
|
|
|
func TestTranslate(t *testing.T) {
|
|
|
|
cases := []transTestData{
|
|
|
|
transTestData{
|
2019-10-13 15:05:27 +00:00
|
|
|
"actuator", "en", "hu",
|
2019-10-11 20:08:06 +00:00
|
|
|
`működtető
|
2019-10-09 19:58:25 +00:00
|
|
|
|
|
|
|
noun
|
|
|
|
indítókar
|
|
|
|
actuator, starting lever
|
2019-10-09 19:05:12 +00:00
|
|
|
|
|
|
|
actuator
|
2019-10-09 19:58:25 +00:00
|
|
|
működtető, beavatkozó, hajtómű, aktuátor, hajtás
|
2019-10-11 20:08:06 +00:00
|
|
|
`,
|
2019-10-09 19:58:25 +00:00
|
|
|
[]string{"működtető", "indítókar", "beavatkozó", "hajtómű", "aktuátor", "hajtás"},
|
|
|
|
},
|
2019-10-13 15:51:30 +00:00
|
|
|
transTestData{
|
2019-10-13 15:05:27 +00:00
|
|
|
"szaxofon", "hu", "en",
|
2019-10-11 20:08:06 +00:00
|
|
|
`saxophone
|
2019-10-09 19:58:25 +00:00
|
|
|
|
|
|
|
szaxofon
|
|
|
|
saxophone
|
2019-10-11 20:08:06 +00:00
|
|
|
`,
|
2019-10-09 19:58:25 +00:00
|
|
|
[]string{"saxophone"},
|
|
|
|
},
|
2019-10-13 15:51:30 +00:00
|
|
|
transTestData{
|
2019-10-13 15:05:27 +00:00
|
|
|
"cat", "en", "hu",
|
2019-10-11 20:08:06 +00:00
|
|
|
`macska
|
2019-10-09 19:58:25 +00:00
|
|
|
|
|
|
|
noun
|
|
|
|
macska
|
|
|
|
cat, pussy
|
|
|
|
pletykás nő
|
|
|
|
cat
|
|
|
|
|
|
|
|
verb
|
|
|
|
felvon
|
|
|
|
hoist, cat
|
|
|
|
|
|
|
|
cat
|
|
|
|
macska, cica
|
2019-10-11 20:08:06 +00:00
|
|
|
`,
|
2019-10-09 19:58:25 +00:00
|
|
|
[]string{"macska", "pletykás nő", "felvon", "cica"},
|
|
|
|
},
|
2019-10-13 15:51:30 +00:00
|
|
|
transTestData{
|
2019-10-13 15:05:27 +00:00
|
|
|
"méltányosság", "hu", "en",
|
2019-10-11 20:08:06 +00:00
|
|
|
`equity
|
2019-10-09 19:58:25 +00:00
|
|
|
|
|
|
|
noun
|
|
|
|
equity
|
|
|
|
méltányosság, jogosság
|
|
|
|
fairness
|
|
|
|
méltányosság, szőkeség
|
|
|
|
justness
|
|
|
|
jogosság, méltányosság
|
|
|
|
|
|
|
|
méltányosság
|
|
|
|
equity, fairness
|
2019-10-11 20:08:06 +00:00
|
|
|
`,
|
2019-10-09 19:58:25 +00:00
|
|
|
[]string{"equity", "fairness", "justness"},
|
2019-10-09 19:05:12 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, data := range cases {
|
2019-10-13 15:05:27 +00:00
|
|
|
tr := trans.New(data.word)
|
|
|
|
tr.Language = data.fromLang
|
2019-10-11 20:40:02 +00:00
|
|
|
if _, ok := os.LookupEnv("NOMOCK"); !ok {
|
2019-10-13 15:05:27 +00:00
|
|
|
tr.Translator = func(string, string, string) (string, error) {
|
2019-10-11 20:40:02 +00:00
|
|
|
return data.transOutput, nil
|
|
|
|
}
|
2019-10-09 19:05:12 +00:00
|
|
|
}
|
2019-10-13 15:05:27 +00:00
|
|
|
r := tr.Translate(data.toLang)
|
2019-10-09 19:05:12 +00:00
|
|
|
if (!reflect.DeepEqual(r, data.expectedResults)) {
|
2019-10-09 19:58:25 +00:00
|
|
|
t.Errorf("\nExpected: '%v'\nActual: '%v'", data.expectedResults, r)
|
2019-10-09 19:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-10-13 15:51:30 +00:00
|
|
|
|
|
|
|
type idTestData struct {
|
|
|
|
word string
|
|
|
|
identifyOutput string
|
|
|
|
expectedCode string
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIdentify(t *testing.T) {
|
|
|
|
cases := []idTestData{
|
|
|
|
idTestData{
|
|
|
|
"macska",
|
|
|
|
`Magyar
|
|
|
|
Name Hungarian
|
|
|
|
Family Uralic
|
|
|
|
Writing system Latin
|
|
|
|
Code hu
|
|
|
|
ISO 639-3 hun
|
|
|
|
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=hun
|
|
|
|
Glottolog http://glottolog.org/resource/languoid/id/hung1274
|
|
|
|
Wikipedia http://en.wikipedia.org/wiki/Hungarian_language
|
|
|
|
`,
|
|
|
|
"hu",
|
|
|
|
},
|
|
|
|
idTestData{
|
|
|
|
"cat",
|
|
|
|
`English
|
|
|
|
Name English
|
|
|
|
Family Indo-European
|
|
|
|
Writing system Latin
|
|
|
|
Code en
|
|
|
|
ISO 639-3 eng
|
|
|
|
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=eng
|
|
|
|
Glottolog http://glottolog.org/resource/languoid/id/stan1293
|
|
|
|
Wikipedia http://en.wikipedia.org/wiki/English_language
|
|
|
|
`,
|
|
|
|
"en",
|
|
|
|
},
|
|
|
|
idTestData{
|
|
|
|
"szofisztikált",
|
|
|
|
`Magyar
|
|
|
|
Name Hungarian
|
|
|
|
Family Uralic
|
|
|
|
Writing system Latin
|
|
|
|
Code hu
|
|
|
|
ISO 639-3 hun
|
|
|
|
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=hun
|
|
|
|
Glottolog http://glottolog.org/resource/languoid/id/hung1274
|
|
|
|
Wikipedia http://en.wikipedia.org/wiki/Hungarian_language
|
|
|
|
`,
|
|
|
|
"hu",
|
|
|
|
},
|
|
|
|
idTestData{
|
|
|
|
"distribute",
|
|
|
|
`English
|
|
|
|
Name English
|
|
|
|
Family Indo-European
|
|
|
|
Writing system Latin
|
|
|
|
Code en
|
|
|
|
ISO 639-3 eng
|
|
|
|
SIL http://www-01.sil.org/iso639-3/documentation.asp?id=eng
|
|
|
|
Glottolog http://glottolog.org/resource/languoid/id/stan1293
|
|
|
|
Wikipedia http://en.wikipedia.org/wiki/English_language
|
|
|
|
`,
|
|
|
|
"en",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, data := range cases {
|
|
|
|
id := trans.New(data.word)
|
|
|
|
if _, ok := os.LookupEnv("NOMOCK"); !ok {
|
|
|
|
id.Identifier = func(string) (string, error) {
|
|
|
|
return data.identifyOutput, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if id.Identify() != data.expectedCode {
|
|
|
|
t.Errorf("Word '%s' should identify to '%s'!", data.word, data.expectedCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|