Typed columns and null #13
@@ -111,6 +111,7 @@ func TestDatatypeAcceptsAColumnThatAlwaysParses(t *testing.T) {
|
|||||||
`{"format":"{calc(x + 1)}","x":"{float(0,9,0)}","datatype":"integer"}`,
|
`{"format":"{calc(x + 1)}","x":"{float(0,9,0)}","datatype":"integer"}`,
|
||||||
`{"format":"{float(-1,1,2)}","datatype":"number"}`,
|
`{"format":"{float(-1,1,2)}","datatype":"number"}`,
|
||||||
`{"format":"{v}","v":["1","2.5","6.022e23"],"datatype":"number"}`,
|
`{"format":"{v}","v":["1","2.5","6.022e23"],"datatype":"number"}`,
|
||||||
|
`{"format":"{v}","v":["-1e-400","0.5"],"datatype":"number"}`,
|
||||||
`{"format":"{b}","b":["true","false"],"datatype":"boolean"}`,
|
`{"format":"{b}","b":["true","false"],"datatype":"boolean"}`,
|
||||||
`{"format":"{calc(net * qty, 2)}","net":["19.99","5.00"],"qty":["3","7"],"datatype":"number"}`,
|
`{"format":"{calc(net * qty, 2)}","net":["19.99","5.00"],"qty":["3","7"],"datatype":"number"}`,
|
||||||
`{"format":"{calc(a + b)}","a":"{int(1,9)}","b":"{int(-9,9)}","datatype":"integer"}`,
|
`{"format":"{calc(a + b)}","a":"{int(1,9)}","b":"{int(-9,9)}","datatype":"integer"}`,
|
||||||
|
|||||||
@@ -131,6 +131,16 @@ func TestRecordCSV(t *testing.T) {
|
|||||||
if len(seen) != 4 {
|
if len(seen) != 4 {
|
||||||
t.Fatalf("round-tripped %d of the 4 values; the comma, quote and newline shapes must each survive", len(seen))
|
t.Fatalf("round-tripped %d of the 4 values; the comma, quote and newline shapes must each survive", len(seen))
|
||||||
}
|
}
|
||||||
|
for value, want := range map[string]string{`\.`: `"\."`, " x": `" x"`, " x": "\" x\"", "a\rb": "\"a\rb\""} {
|
||||||
|
body, _ := json.Marshal(map[string]string{"format": "", "v": value})
|
||||||
|
r, err := newGenerator(t, writeData(t, map[string]string{"q": string(body)})).FakeRecord("q")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if got := r.CSVLine(); got != want {
|
||||||
|
t.Errorf("CSVLine() of %q = %q, want %q, quoted where encoding/csv quotes", value, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecordCSVEmptyValueStaysARow(t *testing.T) {
|
func TestRecordCSVEmptyValueStaysARow(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user