package glob import "testing" func TestMatch(t *testing.T) { cases := []struct { pattern, s string want bool }{ {"*LIDL*", "CARD PAYMENT LIDL 1234 SOFIA", true}, {"*LIDL*", "lidl", true}, {"*lidl*", "CARD PAYMENT LIDL", true}, {"LIDL", "LIDL", true}, {"LIDL", "LIDL SOFIA", false}, {"LIDL*", "LIDL SOFIA", true}, {"*SOFIA", "LIDL SOFIA", true}, {"*SOFIA", "LIDL SOFIA 1", false}, {"", "", true}, {"", "x", false}, {"*", "", true}, {"**", "anything", true}, {"?", "a", true}, {"?", "ab", false}, {"a?c", "abc", true}, {"a?c", "ac", false}, {"*A*B*C*", "xxAyyBzzCww", true}, {"*A*B*C*", "xxAyyCzzBww", false}, {"*TO SAVINGS*", "TRANSFER TO SAVINGS ACC", true}, {"*a*a*a*", "aaaaaaaaaaaaaaaaaaaaaaaaaaaab", true}, // Pathological for naive recursion: must return quickly, not hang. {"a*a*a*a*a*a*a*a*b", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false}, } for _, c := range cases { if got := Match(c.pattern, c.s); got != c.want { t.Errorf("Match(%q, %q) = %v, want %v", c.pattern, c.s, got, c.want) } } } func TestMatchUnicode(t *testing.T) { if !Match("*КАУФЛАНД*", "плащане кауфланд софия") { t.Error("expected case-insensitive unicode match") } if !Match("ка?фланд", "КАУФЛАНД") { t.Error("expected '?' to match one rune, not one byte") } }