Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33
@@ -78,6 +78,7 @@ func TestAJSONNumberOrBooleanInARecordColumnIsRefused(t *testing.T) {
|
||||
`{"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)
|
||||
@@ -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}}`,
|
||||
|
||||
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user