diff --git a/datatype_test.go b/datatype_test.go index 4393dde..9ba95aa 100644 --- a/datatype_test.go +++ b/datatype_test.go @@ -46,7 +46,6 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) { for _, c := range []struct{ name, column, want string }{ {"an item beside a typed one", `[{"format":"1","datatype":"integer"},"x"]`, `write it as {"format":"x","datatype":"integer"}`}, {"a weighted item beside a typed one", `[{"format":"1","datatype":"integer"},{"format":"2","weight":3}]`, `give it "datatype": "integer"`}, - {"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}","5"]`, `write it as {"format":"5","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}"}`}, @@ -54,7 +53,6 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) { {"a datatype a typed column's values reject", `{"format":"{/src.score}","datatype":"boolean"}`, "{int(1,9)} prints an integer, not a boolean"}, {"two typed columns it reads", `["{/src.score}","{/src.flag}"]`, `so to read "{/src.score}" as text, write {"format":"{text}","text":"{/src.score}"}`}, {"a typed column read that holds the datatype declared beside it", `[{"format":"1.5","datatype":"number"},"{/src.score}"]`, `so write "{/src.score}" as {"format":"{/src.score}","datatype":"number"}`}, - {"two datatypes the first holds both of", `[{"format":"1","datatype":"integer"},{"format":"1.5","datatype":"number"}]`, "its items hold integer and number; a column holds one datatype"}, {"a typed column read holding the datatype of another", `["{/src.ratio}","{/src.score}"]`, `so write "{/src.ratio}" as {"format":"{/src.ratio}","datatype":"integer"}`}, {"text before a typed column it reads", `["n/a","{/src.score}"]`, `to read that column as text, write {"format":"{text}","text":"{/src.score}"}`}, {"a weighted item beside a typed column it reads", `["{/src.score}",{"format":"5","weight":2}]`, `give it "datatype": "integer"`}, @@ -108,6 +106,18 @@ func TestDatatypeRejectsAValueItsTypeRejects(t *testing.T) { t.Errorf("%s: NewTemplate = %v, want the inline template refused the same way", c.name, err) } } + for column, want := range map[string]string{ + `[{"format":"1","datatype":"integer"},{"format":"true","datatype":"boolean"}]`: "its items hold integer and boolean; a column holds one datatype", + `[{"format":"1","datatype":"integer"},{"format":"1.5","datatype":"number"}]`: "its items hold integer and number; a column holds one datatype", + } { + row := `{"format":"","col":` + column + `}` + if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{"row": row}))); err == nil || !strings.HasSuffix(err.Error(), want) { + t.Errorf("items of two declared datatypes %s: New = %v, want an error ending %q", column, err, want) + } + if _, err := newGenerator(t, writeData(t, tree)).NewTemplate(row); err == nil || !strings.HasSuffix(err.Error(), want) { + t.Errorf("items of two declared datatypes %s: NewTemplate = %v, want an error ending %q", column, err, want) + } + } _, 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"}]}`,