- PUBSUB CHANNELS glob pattern matching - Implement SELECT + max DB validation (0-15) (default db max is 16), for perl clients - CLIENT KILL ID (single/range) + MAXAGE - CLIENT INFO events + resp fields - PUBSUB SHARDCHANNELS/SHARDNUMSUB stubs
70 lines
1.6 KiB
Go
70 lines
1.6 KiB
Go
// @tag glob
|
|
// @tag test
|
|
package glob
|
|
|
|
import "testing"
|
|
|
|
func TestMatch(t *testing.T) {
|
|
tests := []struct {
|
|
pattern string
|
|
s string
|
|
want bool
|
|
}{
|
|
{"", "", true},
|
|
{"", "foo", false},
|
|
{"*", "", true},
|
|
{"*", "foo", true},
|
|
{"*", "foo/bar", true},
|
|
{"foo", "foo", true},
|
|
{"foo", "bar", false},
|
|
{"foo*", "foo", true},
|
|
{"foo*", "foobar", true},
|
|
{"foo*", "fo", false},
|
|
{"*foo", "foo", true},
|
|
{"*foo", "barfoo", true},
|
|
{"*foo", "bar", false},
|
|
{"foo*bar", "foobar", true},
|
|
{"foo*bar", "foobazbar", true},
|
|
{"foo*bar", "foobaz", false},
|
|
{"foo?bar", "fooXbar", true},
|
|
{"foo?bar", "fooXXbar", false},
|
|
{"foo??bar", "fooXXbar", true},
|
|
{"?", "a", true},
|
|
{"?", "", false},
|
|
{"a?c", "abc", true},
|
|
{"a?c", "ac", false},
|
|
{"foo?*bar", "fooabcbar", true},
|
|
{"foo?*bar", "foobar", false},
|
|
{"*foo*bar*", "ahellofoocherrybarb", true},
|
|
{"ch*", "channel", true},
|
|
{"ch*", "ch", true},
|
|
{"ch*", "c", false},
|
|
{"*", "*", true},
|
|
{"**", "*", true},
|
|
{"*a*b", "aXb", true},
|
|
{"a*b*c", "aXbYc", true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.pattern+"/"+tt.s, func(t *testing.T) {
|
|
if got := Match(tt.pattern, tt.s); got != tt.want {
|
|
t.Errorf("Match(%q, %q) = %v, want %v", tt.pattern, tt.s, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkMatch(b *testing.B) {
|
|
patterns := []string{"*", "ch*", "foo*bar", "???", "*channel*"}
|
|
strings := []string{"channel", "channel123", "foobar", "abc", "somechannelname"}
|
|
|
|
b.ReportAllocs()
|
|
for i := 0; i < b.N; i++ {
|
|
for _, p := range patterns {
|
|
for _, s := range strings {
|
|
Match(p, s)
|
|
}
|
|
}
|
|
}
|
|
}
|