textmachine/backend/internal/membank/memnorm_test.go

27 lines
1.2 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 membank
import (
"testing"
"textmachine/backend/internal/store"
"textmachine/backend/internal/text"
)
// TestApostropheFold covers the Task-6 re-audit finding: a typographic apostrophe (U+2019,
// smart-quote editors) folds to ASCII on BOTH sides, so a source key O'Brien matches either
// spelling (no silently empty) and the post-check does not false-MISS a д'Артаньян. Reverting the
// isApostropheVariant folds breaks these.
func TestApostropheFold(t *testing.T) {
if text.NormalizeSourceKey("OBrien") != text.NormalizeSourceKey("O'Brien") {
t.Error("source: typographic and ASCII apostrophe must normalize identically")
}
if text.NormalizeTargetForm("д’Артаньян") != text.NormalizeTargetForm("д'Артаньян") {
t.Error("target: typographic and ASCII apostrophe must normalize identically")
}
// End-to-end: an ASCII-apostrophe key matches a chunk written with a typographic apostrophe.
e := gl("o'brien", "О'Брайен", "", "approved")
b := bankFrom([]store.GlossaryEntry{e})
if _, ok := injMap(b.Select("mr obrien arrived.", 1, nil, 0))["o'brien"]; !ok {
t.Error("typographic apostrophe in the chunk must match the ASCII-apostrophe key")
}
}