Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go-bindata: balance backquoted string concatenation
The current code prints long string concatenations like a + b + c + d + e + f The new code prints ((a + (b + c)) + (d + (e + f))) This has the effect of minimizing the overall height of the expression tree, which makes recursive traversals of the tree a little happier and makes incremental computation of string constants as in go/types and go/vet MUCH happier. The compilers and go/types should be fixed so that this isn't necessary, but we can't fix the old releases, and this is very easy, so it seems worth doing. For golang/go#23222.
- Loading branch information
1 parent
c45d99b
commit e5078a2
Showing
2 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package bindata | ||
|
||
import "testing" | ||
|
||
var sanitizeTests = []struct { | ||
in string | ||
out string | ||
}{ | ||
{`hello`, "`hello`"}, | ||
{"hello\nworld", "`hello\nworld`"}, | ||
{"`ello", "(\"`\" + `ello`)"}, | ||
{"`a`e`i`o`u`", "(((\"`\" + `a`) + (\"`\" + (`e` + \"`\"))) + ((`i` + (\"`\" + `o`)) + (\"`\" + (`u` + \"`\"))))"}, | ||
{"\xEF\xBB\xBF`s away!", "(\"\\xEF\\xBB\\xBF\" + (\"`\" + `s away!`))"}, | ||
} | ||
|
||
func TestSanitize(t *testing.T) { | ||
for _, tt := range sanitizeTests { | ||
out := []byte(sanitize([]byte(tt.in))) | ||
if string(out) != tt.out { | ||
t.Errorf("sanitize(%q):\nhave %q\nwant %q", tt.in, out, tt.out) | ||
} | ||
} | ||
} |
e5078a2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!