diff --git a/spellings_test.go b/spellings_test.go index ddd3b6e..022e8a2 100644 --- a/spellings_test.go +++ b/spellings_test.go @@ -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}}`, diff --git a/struct_test.go b/struct_test.go index 085013b..afbe924 100644 --- a/struct_test.go +++ b/struct_test.go @@ -253,6 +253,17 @@ func TestFakeStructTakesTheDatatypeItsGoTypeSets(t *testing.T) { } } +func TestFakeStructTypesABareNumberOrBooleanByItsGoType(t *testing.T) { + v := struct { + N int `fake:"[5, 6]"` + B bool `fake:"[true, false]"` + S string `fake:"[7.50]"` + }{} + if err := structData(t).FakeStruct(&v); err != nil || (v.N != 5 && v.N != 6) || v.S != "7.50" { + t.Errorf("FakeStruct = %+v, %v, want each value typed by its field", v, err) + } +} + func TestFakeStructWithNoTagsFillsNothing(t *testing.T) { v := struct{ A string }{A: "kept"} if err := structData(t).FakeStruct(&v); err != nil || v.A != "kept" {