textmachine/backend/internal/checks/latinguard_test.go

44 lines
2.3 KiB
Go

package checks
import (
"testing"
"textmachine/backend/internal/lang"
)
// latinguard_test.go: the SECOND half of the row-46 hole (13-tech-debt-anchors §Б-46). The Latin-residue
// detector reads a run of Latin words as an untranslated leak — true for a Cyrillic target, and exactly
// inverted for a Latin-written one, where it would drop every chunk of clean target prose. The doccomment
// two layers up declared that guard for years while the only place it actually stood was the repair path.
//
// ⚠ IT WAS UNPINNED AFTER BEING BUILT, which is how the acceptance found it: the guard's own mutation left
// the whole battery green. Both sides are asserted here, because a one-sided test would pass on a guard
// that never lets the class run at all.
func TestTheLatinResidueClassIsGatedOnTheTargetsOwnScript(t *testing.T) {
const leaked = "Он сказал: the quick brown fox jumps over the lazy dog and never came back."
// A NON-Latin target with data: the class is the point, and it must fire.
cyr := CompileCheckers(nil, lang.TargetChecksFor("ru"))
if !cyr.TargetScriptNonLatin() {
t.Fatal("premise broken: the ru target must declare a non-Latin word script, or this test proves nothing")
}
if got := cyr.SanitizeOutput(leaked); got.LatinInsert == 0 {
t.Fatalf("a Latin phrase inside Russian is the class this detector exists for: %+v", got)
}
// A target that does NOT declare a non-Latin word script: the class must not run at all. This is the
// standing of every target whose data nobody has authored (TargetChecksFor of an unknown target returns
// exactly this), and it is the standing a Latin-written target will have.
//
// ⚠ NARROWNESS, named rather than hidden: the repository ships `data/target-ru.txt` and nothing else, so
// there is no way to build a target that declares `word_script latin` from data — the case is reached
// here through an EMPTY declaration, which takes the same branch (wordScript == nil). The day a Latin
// target ships its file, this test should gain that row.
none := CompileCheckers(nil, lang.TargetChecks{})
if none.TargetScriptNonLatin() {
t.Fatal("a target that declares no word script is not a non-Latin target")
}
if got := none.SanitizeOutput(leaked); got.LatinInsert != 0 {
t.Fatalf("a target that does not write in a non-Latin script must not have its own prose read as a leak: %+v", got)
}
}