Skip to content

Commit

Permalink
printer: fix printing of floats
Browse files Browse the repository at this point in the history
  • Loading branch information
dustmop authored and rvagg committed May 12, 2022
1 parent 294ccfe commit 37f875b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -46,6 +49,9 @@ func TestSimpleData(t *testing.T) {
0: int{1}
1: int{2}
}
string{"list with float"}: list{
0: float{3.4}
}
}`,
))
})
Expand Down

0 comments on commit 37f875b

Please sign in to comment.