image search test

This commit is contained in:
2026-09-16 11:52:35 +05:30
parent 42ea007fe7
commit 28af3e05f2
5 changed files with 181 additions and 6 deletions

View File

@@ -63,3 +63,42 @@ func TestSearchTokens(t *testing.T) {
t.Error("pack sizes alone are not searchable")
}
}
// A single letter is often the whole product name in this catalogue, so it
// survives when it follows a word — but not when it stands alone, and not
// when it is the multiplier in a pack size.
func TestSearchTokensKeepsALetterThatFollowsAWord(t *testing.T) {
for _, tc := range []struct {
label string
want []string
}{
{"Parle G", []string{"parle", "g"}},
{"Parle-G", []string{"parle", "g"}},
{"Special K Original", []string{"special", "k", "original"}},
{"G", nil}, // a letter alone is not a search
{"2 x 50gm", nil}, // multiplier and pack size, no words
{"Milk Bikis 100g, Britannia (2 x 50gm)", []string{"milk", "bikis", "britannia"}},
} {
got := SearchTokens(tc.label)
if len(got) != len(tc.want) {
t.Fatalf("%q: got %v want %v", tc.label, got, tc.want)
}
for i := range tc.want {
if got[i] != tc.want[i] {
t.Fatalf("%q: got %v want %v", tc.label, got, tc.want)
}
}
}
}
func TestFoldAndTightenSeparators(t *testing.T) {
if got := FoldSeparators("Parle-G Original"); got != "parle g original" {
t.Fatalf("fold: got %q", got)
}
if FoldSeparators("Parle-G") != FoldSeparators("Parle G") {
t.Error("a hyphen and a space are the same separator to us")
}
if got := TightenLabel("Parle-G"); got != "parleg" {
t.Fatalf("tighten: got %q", got)
}
}