57 lines
2.5 KiB
Go
57 lines
2.5 KiB
Go
package membank
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
|
||
"textmachine/backend/internal/lang"
|
||
)
|
||
|
||
// render_test.go: the injection RENDERER fixtures — the exact bytes the bank puts on the wire for
|
||
// each role. ruTX is the ru target wire-text (pair-14 §2: the strings live in lang/data/injection.txt).
|
||
|
||
func ruTX() lang.InjectionTexts { return lang.InjectionTextsFor("ru") }
|
||
|
||
func TestRenderGlossaryBlock(t *testing.T) {
|
||
confirmed := PickedEntry{entry: &entry{src: "阿Q", dst: "А-кью", status: "approved"}, Disp: Confirmed}
|
||
ambiguous := PickedEntry{entry: &entry{src: "小D", dst: "Малыш Дэ", status: "auto"}, Disp: Ambiguous}
|
||
emptyDst := PickedEntry{entry: &entry{src: "鈴木", dst: "", status: "auto"}, Disp: Ambiguous}
|
||
|
||
block := RenderGlossaryBlock([]PickedEntry{confirmed, ambiguous, emptyDst}, ruTX())
|
||
if !strings.Contains(block, "阿Q → А-кью") {
|
||
t.Errorf("confirmed line missing: %q", block)
|
||
}
|
||
if !strings.Contains(block, "小D → Малыш Дэ ⟨проверить⟩") {
|
||
t.Errorf("ambiguous line missing its unverified tag: %q", block)
|
||
}
|
||
if strings.Contains(block, "鈴木") {
|
||
t.Errorf("empty-dst candidate should be skipped (nothing to inject): %q", block)
|
||
}
|
||
// Nothing to inject → empty block (better nothing).
|
||
if RenderGlossaryBlock(nil, ruTX()) != "" {
|
||
t.Error("empty selection must render an empty block")
|
||
}
|
||
if RenderGlossaryBlock([]PickedEntry{emptyDst}, ruTX()) != "" {
|
||
t.Error("only-empty-dst selection must render an empty block")
|
||
}
|
||
}
|
||
|
||
// TestDC3GenderInjection pins the DC3 gender constraint annotation on the editor block (WS5 §5(б)): a
|
||
// gendered CONFIRMED term carries a gender directive; a genderless term does not (byte-identical line).
|
||
func TestDC3GenderInjection(t *testing.T) {
|
||
mk := func(gender string) []PickedEntry {
|
||
return []PickedEntry{{entry: &entry{src: "方源", dst: "Фан Юань", status: "approved", gender: gender}, Via: "方源", Disp: Confirmed}}
|
||
}
|
||
male := RenderEditorConstraintBlock(mk("male"), ruTX())
|
||
if !strings.Contains(male, "方源 → «Фан Юань» (муж.") {
|
||
t.Fatalf("male term must carry a masculine directive, got:\n%s", male)
|
||
}
|
||
hidden := RenderEditorConstraintBlock(mk("hidden"), ruTX())
|
||
if !strings.Contains(hidden, "пол СКРЫТ") {
|
||
t.Fatalf("hidden term must carry the gender-avoidance mandate, got:\n%s", hidden)
|
||
}
|
||
none := RenderEditorConstraintBlock(mk(""), ruTX())
|
||
if !strings.HasSuffix(none, "«Фан Юань»") {
|
||
t.Fatalf("a genderless term must have NO gender note (line ends at the dst), got:\n%s", none)
|
||
}
|
||
}
|