Files
notarius/internal/modules/dnd/shared/matching_test.go

52 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package shared
import "testing"
func TestComparisonKeyNormalizesDNDText(t *testing.T) {
if TextComparisonPolicy != "dnd.text_comparison.v1" {
t.Fatalf("TextComparisonPolicy = %q", TextComparisonPolicy)
}
for _, test := range []struct {
name string
input string
want string
}{
{name: "case", input: "Captain Vale", want: "captain vale"},
{name: "compatibility", input: "", want: "ally"},
{name: "whitespace", input: " Mira\u2003Thorn ", want: "mira thorn"},
{name: "apostrophes", input: "ORin and OʼRin", want: "o'rin and o'rin"},
{name: "unicode composition", input: " Cafe\u0301\u2003dOr ", want: "café d'or"},
} {
t.Run(test.name, func(t *testing.T) {
if got := ComparisonKey(test.input); got != test.want {
t.Fatalf("ComparisonKey(%q) = %q, want %q", test.input, got, test.want)
}
})
}
if ComparisonKey("Mira Thorn") == ComparisonKey("Mira Thorne") {
t.Fatal("different names received the same comparison key")
}
}
func TestContainsTokenSequence(t *testing.T) {
tests := []struct {
name string
value string
query string
want bool
}{
{name: "unicode apostrophe and case", value: "OrIn\u2003ThOrN advances", query: "o'rin thorn", want: true},
{name: "multiword sequence", value: "Mira Thorn watches", query: "mira thorn", want: true},
{name: "nonconsecutive words", value: "Mira watches Thorn", query: "mira thorn", want: false},
{name: "short name is not substring", value: "A cart rolls past", query: "art", want: false},
{name: "empty query", value: "anything", query: " ", want: false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := ContainsTokenSequence(test.value, test.query); got != test.want {
t.Fatalf("ContainsTokenSequence(%q, %q) = %t, want %t", test.value, test.query, got, test.want)
}
})
}
}