Have dumbindent handle multi-line strings/comments

Fixes #31
This commit is contained in:
Nigel Tao committed 2020-06-06 22:32:39 +10:00
1 parent 3d7af06727
commit 6424bae087
4 files changed
+89 -42

No files matched your search

+13 -3
View File
@@ -23,6 +23,10 @@ func TestFormatBytes(tt *testing.T) {
src string
want string
}{{
// Leading and trailing space.
src: "\t\tx y \n",
want: "x y\n",
}, {
// Braces.
src: "foo{\nbar\n }\nbaz\n",
want: "foo{\n bar\n}\nbaz\n",
@@ -50,6 +54,14 @@ func TestFormatBytes(tt *testing.T) {
// Double-quote string.
src: "a = \"{\"\nb = {\nc = 0\n",
want: "a = \"{\"\nb = {\n c = 0\n",
}, {
// Back-tick string.
src: "a['key'] = `{\n\n\nX` ; \nb = {\nc = 0\n",
want: "a['key'] = `{\n\n\nX` ;\nb = {\n c = 0\n",
}, {
// Slash-star comment.
src: " a['key'] = /*{\n\n\nX*/ ; \nb = {\nc = 0\n",
want: "a['key'] = /*{\n\n\nX*/ ;\nb = {\n c = 0\n",
}, {
// Label.
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
@@ -57,9 +69,7 @@ func TestFormatBytes(tt *testing.T) {
}}
for i, tc := range testCases {
if g, err := FormatBytes(nil, []byte(tc.src)); err != nil {
tt.Fatalf("i=%d, src=%q: %v", i, tc.src, err)
} else if got := string(g); got != tc.want {
if got := string(FormatBytes(nil, []byte(tc.src))); got != tc.want {
tt.Fatalf("i=%d, src=%q:\ngot %q\nwant %q", i, tc.src, got, tc.want)
}
}