Test a struct tag's bare number or boolean typed by its Go type, and a column's refusal offering only a datatype that holds the number

This commit is contained in:
2026-10-08 11:54:29 +02:00
committed by Lillem4n
parent 8a8c915679
commit 9e392d02fd
2 changed files with 23 additions and 4 deletions
+12 -4
View File
@@ -75,10 +75,11 @@ func TestAPartWithNoEffectRendersAsWithoutIt(t *testing.T) {
func TestAJSONNumberOrBooleanInARecordColumnIsRefused(t *testing.T) {
for src, want := range map[string][]string{
`{"format":"","n":5}`: {`"5"`, `{"format":"5","datatype":"integer"}`},
`{"format":"","n":1.50}`: {`"1.50"`, `{"format":"1.50","datatype":"number"}`},
`{"format":"","b":true}`: {`"true"`, `{"format":"true","datatype":"boolean"}`},
`{"format":"","n":[5,"x"]}`: {`"5"`, `{"format":"5","datatype":"integer"}`},
`{"format":"","n":5}`: {`"5"`, `{"format":"5","datatype":"integer"}`},
`{"format":"","n":1.50}`: {`"1.50"`, `{"format":"1.50","datatype":"number"}`},
`{"format":"","b":true}`: {`"true"`, `{"format":"true","datatype":"boolean"}`},
`{"format":"","n":12345678901234567890}`: {`"12345678901234567890"`, `{"format":"12345678901234567890","datatype":"number"}`},
`{"format":"","n":[5,"x"]}`: {`"5"`, `{"format":"5","datatype":"integer"}`},
} {
_, err := resolved(t, src)
for _, w := range want {
@@ -89,6 +90,13 @@ func TestAJSONNumberOrBooleanInARecordColumnIsRefused(t *testing.T) {
}
}
func TestAJSONNumberNoDatatypeHoldsIsOfferedAsTextAlone(t *testing.T) {
_, err := resolved(t, `{"format":"","n":1e400}`)
if err == nil || !strings.Contains(err.Error(), `write "1e400" for text`) || strings.Contains(err.Error(), `"datatype"`) {
t.Errorf("compile(1e400 in a column) = %v, want text offered alone", err)
}
}
func TestAJSONNumberOrBooleanIsItsText(t *testing.T) {
f := newGenerator(t, writeData(t, map[string]string{
"n": `{"format":"{x}","x":{"format":"{a} {b} {c} {d}","a":5,"b":1.50,"c":12345678901234567890,"d":true}}`,