Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion parser/unparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (un *unparser) visitConstVal(val ref.Val) error {
// represent the float using the minimum required digits
d := strconv.FormatFloat(float64(val), 'g', -1, 64)
un.str.WriteString(d)
if !strings.Contains(d, ".") {
if !strings.ContainsAny(d, ".eE") {
un.str.WriteString(".0")
}
case types.Int:
Expand Down
7 changes: 7 additions & 0 deletions parser/unparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ func TestUnparse(t *testing.T) {
{name: "call_cond_equiv", in: `(a || b ? c : d).e`, out: `((a || b) ? c : d).e`},
{name: "lit_quote_bytes_equiv", in: `b'aaa"bbb'`, out: `b"\141\141\141\042\142\142\142"`},
{name: "select_equiv", in: `a . b . c`, out: `a.b.c`},
// Doubles whose 'g'-format produces scientific notation must
// roundtrip without an incorrect trailing ".0". See #1325.
{name: "lit_double_sci_small", in: `0.00001`, out: `1e-05`},
{name: "lit_double_sci_smaller", in: `0.000000001`, out: `1e-09`},
{name: "lit_double_sci_large", in: `1e30`, out: `1e+30`},
{name: "lit_double_sci_neg_exp", in: `5e-5`, out: `5e-05`},
{name: "lit_double_sci_upper_e", in: `1E7`, out: `1e+07`},

// These expressions require macro call tracking to be enabled.
{
Expand Down