173 lines
3.6 KiB
Go
173 lines
3.6 KiB
Go
package trans_test
|
|
|
|
import (
|
|
"testing"
|
|
"."
|
|
"reflect"
|
|
"os"
|
|
)
|
|
|
|
|
|
type transTestData struct {
|
|
word string
|
|
fromLang string
|
|
toLang string
|
|
transOutput string
|
|
expectedResults []string
|
|
}
|
|
|
|
func TestTranslate(t *testing.T) {
|
|
cases := []transTestData{
|
|
transTestData{
|
|
"actuator", "en", "hu",
|
|
`működtető
|
|
|
|
noun
|
|
indítókar
|
|
actuator, starting lever
|
|
|
|
actuator
|
|
működtető, beavatkozó, hajtómű, aktuátor, hajtás
|
|
`,
|
|
[]string{"működtető", "indítókar", "beavatkozó", "hajtómű", "aktuátor", "hajtás"},
|
|
},
|
|
transTestData{
|
|
"szaxofon", "hu", "en",
|
|
`saxophone
|
|
|
|
szaxofon
|
|
saxophone
|
|
`,
|
|
[]string{"saxophone"},
|
|
},
|
|
transTestData{
|
|
"cat", "en", "hu",
|
|
`macska
|
|
|
|
noun
|
|
macska
|
|
cat, pussy
|
|
pletykás nő
|
|
cat
|
|
|
|
verb
|
|
felvon
|
|
hoist, cat
|
|
|
|
cat
|
|
macska, cica
|
|
`,
|
|
[]string{"macska", "pletykás nő", "felvon", "cica"},
|
|
},
|
|
transTestData{
|
|
"méltányosság", "hu", "en",
|
|
`equity
|
|
|
|
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
|
|
`,
|
|
[]string{"equity", "fairness", "justness"},
|
|
},
|
|
}
|
|
|
|
for _, data := range cases {
|
|
tr := trans.New(data.word)
|
|
tr.Language = data.fromLang
|
|
if _, ok := os.LookupEnv("NOMOCK"); !ok {
|
|
tr.Translator = func(string, string, string) (string, error) {
|
|
return data.transOutput, nil
|
|
}
|
|
}
|
|
r := tr.Translate(data.toLang)
|
|
if (!reflect.DeepEqual(r, data.expectedResults)) {
|
|
t.Errorf("\nExpected: '%v'\nActual: '%v'", data.expectedResults, r)
|
|
}
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|