Compare commits

...

2 Commits

Author SHA1 Message Date
lilleman 88143153ed Read a signed zero off the mantissa, and drop the comment on the unused Pow
Tests / vet + fmt + tests (pull_request) Successful in 1m1s
Tests / vet + fmt + tests (push) Successful in 6s
2026-09-15 15:17:38 +02:00
lilleman 08949eb72c Tests: CSV quotes a COPY marker, a leading space and a bare CR, and a sub-float literal is no signed zero 2026-09-15 15:17:33 +02:00
3 changed files with 14 additions and 2 deletions
+1
View File
@@ -111,6 +111,7 @@ func TestDatatypeAcceptsAColumnThatAlwaysParses(t *testing.T) {
`{"format":"{calc(x + 1)}","x":"{float(0,9,0)}","datatype":"integer"}`,
`{"format":"{float(-1,1,2)}","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":"{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"}`,
+10
View File
@@ -131,6 +131,16 @@ func TestRecordCSV(t *testing.T) {
if len(seen) != 4 {
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) {
+3 -2
View File
@@ -205,7 +205,7 @@ func magnitude(v proven) float64 { return math.Max(math.Abs(v.lo), math.Abs(v.hi
// and within int64, else a number.
func printedNumber(token string, v proven, dp int) proven {
if dp >= 0 {
half, _ := strconv.ParseFloat("5e-"+strconv.Itoa(dp+1), 64) // math.Pow(10, -dp) can land below the tie and let a printed zero through
half, _ := strconv.ParseFloat("5e-"+strconv.Itoa(dp+1), 64)
v = proven{lo: v.lo - half, hi: v.hi + half, nonZero: math.Max(0, v.nonZero-half), integral: v.integral || dp == 0}
}
if dp != 0 && !(dp < 0 && v.integral) {
@@ -271,7 +271,8 @@ func literalValue(text string) proven {
// signedZero refuses a zero written with a sign as a typed value, naming it unsigned.
func signedZero(text string, v proven) proven {
if !strings.HasPrefix(text, "-") || v.notOperand != "" || v.lo != 0 {
mantissa, _, _ := strings.Cut(strings.ToLower(text), "e")
if !strings.HasPrefix(text, "-") || v.notOperand != "" || strings.Trim(mantissa, "-0.") != "" {
return v
}
for _, d := range []DataType{DataTypeInteger, DataTypeNumber} {