From 37f875b8e4c89ef768a0e0f952d2af0644f91b3a Mon Sep 17 00:00:00 2001 From: Dustin Long Date: Wed, 11 May 2022 17:14:23 -0400 Subject: [PATCH] printer: fix printing of floats --- printer/printer.go | 2 +- printer/printer_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/printer/printer.go b/printer/printer.go index 763c3543..55cb6bc1 100644 --- a/printer/printer.go +++ b/printer/printer.go @@ -359,7 +359,7 @@ func (z *printBuf) doString(indentLevel int, printState uint8, n datamodel.Node) case datamodel.Kind_Float: x, _ := n.AsFloat() z.writeString("{") - strconv.FormatFloat(x, 'f', -1, 64) + z.writeString(strconv.FormatFloat(x, 'f', -1, 64)) z.writeString("}") case datamodel.Kind_String: x, _ := n.AsString() diff --git a/printer/printer_test.go b/printer/printer_test.go index 82b8ca3a..9a53b617 100644 --- a/printer/printer_test.go +++ b/printer/printer_test.go @@ -33,6 +33,9 @@ func TestSimpleData(t *testing.T) { qp.ListEntry(la, qp.Int(1)) qp.ListEntry(la, qp.Int(2)) })) + qp.MapEntry(ma, "list with float", qp.List(1, func(la datamodel.ListAssembler) { + qp.ListEntry(la, qp.Float(3.4)) + })) }) qt.Check(t, Sprint(n), qt.CmpEquals(), testutil.Dedent(` map{ @@ -46,6 +49,9 @@ func TestSimpleData(t *testing.T) { 0: int{1} 1: int{2} } + string{"list with float"}: list{ + 0: float{3.4} + } }`, )) })