29 lines
1.2 KiB
Go
29 lines
1.2 KiB
Go
package qso
|
|
|
|
import "testing"
|
|
|
|
// The search box is the one place an operator types a callsign fragment, and
|
|
// the three shapes below are what they expect from every other logger. A plain
|
|
// word is a PREFIX: it used to be an unconditional contains-match, so asking
|
|
// for "calls starting with 4S" was impossible.
|
|
func TestQuickCallsignLike(t *testing.T) {
|
|
for _, tc := range []struct{ in, want, why string }{
|
|
{"4S", "4S%", "plain text is a prefix"},
|
|
{"*4S", "%4S", "a leading star means ends-with"},
|
|
{"*4S*", "%4S%", "stars both ends mean contains"},
|
|
{"4S*", "4S%", "a trailing star is the same prefix, written out"},
|
|
{"4S?", "4S_", "? is exactly one character"},
|
|
{"*", "%", "a lone star matches everything"},
|
|
{" 4S ", "4S%", "surrounding space is not part of the call"},
|
|
// Escaping: a LIKE metacharacter the operator typed is a literal.
|
|
{"A_B", "A!_B%", "_ typed by hand is a literal underscore"},
|
|
{"50%", "50!%%", "% typed by hand is a literal percent"},
|
|
{"A!B", "A!!B%", "the escape character escapes itself"},
|
|
{"*A_B*", "%A!_B%", "escaping still applies inside a wildcard pattern"},
|
|
} {
|
|
if got := quickCallsignLike(tc.in); got != tc.want {
|
|
t.Errorf("quickCallsignLike(%q) = %q, want %q — %s", tc.in, got, tc.want, tc.why)
|
|
}
|
|
}
|
|
}
|