Make the dictionary startup line report rows, not capabilities
It logged dictionary.Langs(), which is a compile-time constant of the languages DreamDict *supports*. The database deployed until today supported Spanish and contained none of it, so the line printed a confident "[en fr pt-PT es zh]" over a file where every Spanish lookup came back empty — the exact failure the line exists to catch, reported as success. Contents() counts rows per language instead. For a file somebody has to copy onto the box by hand, "what is in it" is the only question worth asking, and the answer is now en=136615 es=102971 fr=56096 pt-PT=136300 zh=120883. Claude-Session: https://claude.ai/code/session_016y6gyuHkQXPiEuW8RGQyua
This commit is contained in:
@@ -519,3 +519,25 @@ func TestHandlerDecodesPunctuatedWords(t *testing.T) {
|
||||
t.Errorf("Word = %q, want the decoded word", res.Word)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContentsCountsRowsNotSupportedLanguages(t *testing.T) {
|
||||
// The fixture is seeded with English and pt-PT only. DreamDict *supports*
|
||||
// French, Spanish and Chinese too — and a startup line that reported the
|
||||
// supported set would have named all five while every French lookup came
|
||||
// back empty. That is the failure this log line exists to catch, so it must
|
||||
// count rows.
|
||||
got := NewSet(openFixture(t))
|
||||
summary := got.Contents()
|
||||
if !strings.Contains(summary, "en=") || !strings.Contains(summary, "pt-PT=") {
|
||||
t.Errorf("Contents = %q, want the languages the fixture actually holds", summary)
|
||||
}
|
||||
for _, absent := range []string{"fr=", "es=", "zh="} {
|
||||
if strings.Contains(summary, absent) {
|
||||
t.Errorf("Contents = %q, must not name %q — no rows exist for it", summary, absent)
|
||||
}
|
||||
}
|
||||
// No dictionary at all still has to answer something printable.
|
||||
if s := NewSet(nil).Contents(); s == "" {
|
||||
t.Error("Contents with no dictionary must still say something")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user