Harden item occurrence grounding
This commit is contained in:
@@ -9,10 +9,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/cases"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -52,17 +50,7 @@ func NormalizeDisplay(value string) string {
|
||||
|
||||
// ComparisonKey returns the stable key used for NPC identity comparisons.
|
||||
func ComparisonKey(value string) string {
|
||||
value = norm.NFKC.String(value)
|
||||
value = strings.Map(func(r rune) rune {
|
||||
switch r {
|
||||
case '\u2018', '\u2019', '\u02bc':
|
||||
return '\''
|
||||
default:
|
||||
return r
|
||||
}
|
||||
}, value)
|
||||
value = strings.Join(strings.Fields(value), " ")
|
||||
return cases.Fold().String(value)
|
||||
return shared.ComparisonKey(value)
|
||||
}
|
||||
|
||||
// DeriveID returns the deterministic ID for a canonical NPC name. Empty
|
||||
|
||||
@@ -9,30 +9,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
)
|
||||
|
||||
func TestComparisonKeyNormalizesSupportedEquivalences(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
left string
|
||||
right string
|
||||
}{
|
||||
{name: "case", left: "Captain Vale", right: "cAPtAiN vALE"},
|
||||
{name: "compatibility", left: "Ally", right: "Ally"},
|
||||
{name: "whitespace", left: " Mira\u2003Thorn ", right: "Mira Thorn"},
|
||||
{name: "apostrophe", left: "O’Rin", right: "o'Rin"},
|
||||
{name: "modifier apostrophe", left: "OʼRin", right: "o'Rin"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if ComparisonKey(test.left) != ComparisonKey(test.right) {
|
||||
t.Fatalf("ComparisonKey(%q) = %q, ComparisonKey(%q) = %q", test.left, ComparisonKey(test.left), test.right, ComparisonKey(test.right))
|
||||
}
|
||||
})
|
||||
}
|
||||
if ComparisonKey("Mira Thorn") == ComparisonKey("Mira Thorne") {
|
||||
t.Fatal("different names received the same comparison key")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeDisplayOnlyChangesWhitespace(t *testing.T) {
|
||||
if got := NormalizeDisplay(" O’Rin\u2003Thorn "); got != "O’Rin Thorn" {
|
||||
t.Fatalf("NormalizeDisplay() = %q", got)
|
||||
|
||||
Reference in New Issue
Block a user