Skip to content

Commit

Permalink
better string literals normalization
Browse files Browse the repository at this point in the history
Signed-off-by: Iskander Sharipov <[email protected]>
  • Loading branch information
quasilyte committed Jan 31, 2019
1 parent b1a996f commit 544300f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions testdata/normalize_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ func identityTest() {
_, _ = 12412.312, 12412.312
}

func stringLiteralsTest() {
_, _ = ``, ""
_, _ = `\\`, "\\\\"
_, _ = `\d+`, "\\d+"
_, _ = `123`, "123"
_, _ = "\n"+``+"\n", "\n\n"
}

func defaultSlicingBoundsTest() {
var xs []int
var s string
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func constValueNode(cv constant.Value) ast.Expr {
v := constant.StringVal(cv)
return &ast.BasicLit{
Kind: token.STRING,
Value: `"` + v + `"`,
Value: strconv.Quote(v),
}

case constant.Int:
Expand Down

0 comments on commit 544300f

Please sign in to comment.