48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package membank
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// seedlint_test.go: WS3 (д) `tmctl seed-lint` — the dry-run of the REAL LoadGlossarySeed fail-louds over
|
|
// a seed YAML (the mined delta or a manual seed). Both directions: a clean seed lints OK; a defect fails
|
|
// loud; and the emitted mined delta (MinedDeltaYAML) round-trips through the real loader with 0 fails.
|
|
|
|
func TestSeedLintCleanPasses(t *testing.T) {
|
|
p := writeSeed(t, `
|
|
terms:
|
|
- src: 方源
|
|
dst: Фан Юань
|
|
type: name
|
|
status: approved
|
|
- src: 蛊
|
|
status: auto
|
|
`)
|
|
if err := SeedLint(p); err != nil {
|
|
t.Fatalf("a clean seed must lint OK, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSeedLintCatchesDefects(t *testing.T) {
|
|
cases := []struct {
|
|
name, yaml, want string
|
|
}{
|
|
{"approved without dst", "terms:\n - src: 方源\n status: approved\n", "non-empty dst"},
|
|
{"unknown status", "terms:\n - src: 方源\n dst: X\n status: bogus\n", "status must be"},
|
|
{"duplicate key", "terms:\n - src: 方源\n dst: A\n - src: 方源\n dst: B\n", "duplicate"},
|
|
{"shared-key collision", "terms:\n - src: 老赵\n dst: Старина Чжао\n status: approved\n - src: 赵大\n dst: Чжао Да\n status: approved\n aliases:\n - alias: 老赵\n", "shared"},
|
|
}
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
p := writeSeed(t, tc.yaml)
|
|
err := SeedLint(p)
|
|
if err == nil {
|
|
t.Fatalf("%s: seed-lint must fail loud", tc.name)
|
|
}
|
|
if !strings.Contains(err.Error(), tc.want) {
|
|
t.Fatalf("%s: error %q must mention %q", tc.name, err.Error(), tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|