func detectLanguage(str string) string { lang, err := guesslanguage.Guess(str) if err != nil { lang = "en" } return lang }
func BenchmarkGL32k(b *testing.B) { for _, t := range tests { reader := NewReader(t.fn) buf := new(bytes.Buffer) io.CopyN(buf, reader, 32*1024) for n := 0; n < b.N; n++ { _, err := guesslanguage.Guess(buf.String()) if err != nil { b.Error(err) } } } }
func BenchmarkGL8k(b *testing.B) { for _, t := range tests { // in fixtures/30232-0.txt: Input string contains invalid UTF-8-encoded runes if t.fn == "fixtures/30232-0.txt" { continue } reader := NewReader(t.fn) buf := new(bytes.Buffer) io.CopyN(buf, reader, 8*1024) for n := 0; n < b.N; n++ { _, err := guesslanguage.Guess(buf.String()) if err != nil { b.Errorf("%s: %s", t.fn, err) } } } }
func TestGL(t *testing.T) { for _, c := range tests { // in fixtures/30232-0.txt: Input string contains invalid UTF-8-encoded runes if c.fn == "fixtures/30232-0.txt" { continue } reader := NewReader(c.fn) buf := new(bytes.Buffer) for _, size := range []int64{8192, 32768} { io.CopyN(buf, reader, size) result, err := guesslanguage.Guess(buf.String()) if err != nil { t.Error(err) } if !stringInSlice(result, c.lang) { t.Errorf("%s: got %s, want one of %+v", c.fn, result, c.lang) } } } }