87 lines
2.1 KiB
Go
87 lines
2.1 KiB
Go
package identify_test
|
|
|
|
import (
|
|
"testing"
|
|
"."
|
|
"os"
|
|
)
|
|
|
|
|
|
type testData struct {
|
|
word string
|
|
identifyOutput string
|
|
expectedCode string
|
|
}
|
|
|
|
func TestIdentify(t *testing.T) {
|
|
cases := []testData{
|
|
testData{
|
|
"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",
|
|
},
|
|
testData{
|
|
"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",
|
|
},
|
|
testData{
|
|
"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",
|
|
},
|
|
testData{
|
|
"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 := identify.New(data.word)
|
|
if _, ok := os.LookupEnv("NOMOCK"); !ok {
|
|
id.Identifier = func(i *identify.Indetification) (string, error) {
|
|
return data.identifyOutput, nil
|
|
}
|
|
}
|
|
if id.Identify() != data.expectedCode {
|
|
t.Errorf("Word '%s' should identify to '%s'!", data.word, data.expectedCode)
|
|
}
|
|
}
|
|
}
|