diff --git a/parser/unparser.go b/parser/unparser.go index 5ff979aa..c3c40a0d 100644 --- a/parser/unparser.go +++ b/parser/unparser.go @@ -276,6 +276,9 @@ func (un *unparser) visitConst(expr *exprpb.Expr) error { // represent the float using the minimum required digits d := strconv.FormatFloat(c.GetDoubleValue(), 'g', -1, 64) un.str.WriteString(d) + if !strings.Contains(d, ".") { + un.str.WriteString(".0") + } case *exprpb.Constant_Int64Value: i := strconv.FormatInt(c.GetInt64Value(), 10) un.str.WriteString(i) diff --git a/parser/unparser_test.go b/parser/unparser_test.go index 7696d724..aea5bdec 100644 --- a/parser/unparser_test.go +++ b/parser/unparser_test.go @@ -68,6 +68,11 @@ func TestUnparse(t *testing.T) { {name: "func_in", in: `a in b`}, {name: "list_empty", in: `[]`}, {name: "list_one", in: `[1]`}, + {name: "list_ints", in: `[1, 2, 3]`}, + {name: "list_doubles", in: `[1.0, 2.0, 3.0]`}, + {name: "list_doubles", in: `[1.1, 2.1, 3.1]`}, + {name: "list_uints", in: `[1u, 2u, 3u]`}, + {name: "list_numeric", in: `[1, 2.0, 3u]`}, {name: "list_many", in: `["hello, world", "goodbye, world", "sure, why not?"]`}, {name: "lit_bytes", in: `b"\303\203\302\277"`}, {name: "lit_double", in: `-42.101`},