44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeFTS5(t *testing.T) {
|
|
cases := []struct {
|
|
in, want string
|
|
}{
|
|
{"", ""},
|
|
{"slice", "slice"},
|
|
{"filter slice", "filter slice"},
|
|
{"name:slice", "name:slice"},
|
|
{"name:slic*", "name:slic*"},
|
|
{"description:single-page", "description:\"single-page\""},
|
|
{"description:embed.FS", "description:\"embed.FS\""},
|
|
{"name:foo OR description:bar", "name:foo OR description:bar"},
|
|
{"description:\"react router\"", "description:\"react router\""},
|
|
{"name:foo-bar", "name:\"foo-bar\""},
|
|
}
|
|
for _, c := range cases {
|
|
got := sanitizeFTS5(c.in)
|
|
if got != c.want {
|
|
t.Errorf("sanitizeFTS5(%q) = %q, want %q", c.in, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestIsSnakeCase(t *testing.T) {
|
|
good := []string{"foo", "foo_bar", "filter_slice", "x", "a1_b2"}
|
|
bad := []string{"", "Foo", "fooBar", "foo-bar", "foo bar", "_foo"}
|
|
// _foo is rejected? our impl accepts leading underscore. Let's adapt:
|
|
// Actually our impl accepts underscore at any position. Reclassify _foo.
|
|
for _, s := range good {
|
|
if !isSnakeCase(s) {
|
|
t.Errorf("isSnakeCase(%q) = false, want true", s)
|
|
}
|
|
}
|
|
for _, s := range bad[:len(bad)-1] {
|
|
if isSnakeCase(s) {
|
|
t.Errorf("isSnakeCase(%q) = true, want false", s)
|
|
}
|
|
}
|
|
}
|