Tests: a struct column need not agree on a datatype, text beside a typed column read names its text spelling, a column read is reported before its reader, and column reads through a dot, a choice and an always-null column

This commit is contained in:
2026-09-15 21:10:36 +02:00
parent 2a750008bf
commit bc4280561e
3 changed files with 50 additions and 8 deletions
+8
View File
@@ -49,6 +49,7 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) {
{"items of two datatypes", `[{"format":"1","datatype":"integer"},{"format":"true","datatype":"boolean"}]`, "a column holds one datatype"},
{"an item beside a typed column it reads", `["{/src.score}","x"]`, `write it as {"format":"x","datatype":"integer"}`},
{"a typed item beside a string column it reads", `["{/src.code}",{"format":"1","datatype":"integer"}]`, `write it as {"format":"{/src.code}","datatype":"integer"}`},
{"text beside a typed column it reads", `["{/src.score}","n/a"]`, `to read that column as text, write {"format":"{text}","text":"{/src.score}"}`},
{"a datatype over a typed column", `{"format":"{/src.score}","datatype":"integer"}`, `{/src.score} takes datatype integer from the column it reads; drop "datatype"`},
{"another datatype over a typed column", `{"format":"{/src.score}","datatype":"number"}`, `{/src.score} takes datatype integer from the column it reads; drop "datatype"`},
{"a value of the column it reads", `{"format":"{/src.code}","datatype":"integer"}`, `"2x" is not an integer`},
@@ -98,6 +99,13 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) {
t.Errorf("%s: NewTemplate = %v, want the inline template refused the same way", c.name, err)
}
}
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
"a": `{"format":"","c":["{/b.x}",{"format":"1","datatype":"integer"}]}`,
"b": `{"format":"","x":["2",{"format":"1","datatype":"integer"}]}`,
})))
if want := `b: field "x": item "2"`; err == nil || !strings.Contains(err.Error(), want) {
t.Errorf("a column reading one whose items disagree: New = %v, want the column read reported first, containing %q", err, want)
}
}
var jsonInteger = regexp.MustCompile(`^(0|-?[1-9][0-9]*)$`)