Have dumbindent break after some '{' and ';'s

This commit is contained in:
Nigel Tao committed 2020-06-07 21:52:24 +10:00
1 parent 709e169955
commit 53d5f5155c
5 files changed
+140 -34

No files matched your search

+35
View File
@@ -15,6 +15,7 @@
package dumbindent
import (
"os"
"testing"
)
@@ -66,6 +67,14 @@ func TestFormatBytes(tt *testing.T) {
// Nested blocks with label.
src: "if (b) {\nlabel:\nswitch (i) {\ncase 0:\nj = k\nbreak;\n}\n}\n",
want: "if (b) {\n label:\n switch (i) {\n case 0:\n j = k\n break;\n }\n}\n",
}, {
// Inserted line breaks.
src: "if (x) { goto fail; }\n",
want: "if (x) {\n goto fail;\n}\n",
}, {
// Leading blank lines.
src: "\n\n\n x = y;",
want: "x = y;\n",
}}
for i, tc := range testCases {
@@ -74,3 +83,29 @@ func TestFormatBytes(tt *testing.T) {
}
}
}
func ExampleFormatBytes() {
const src = `
// Blah blah blah.
for (i = 0; i < 3; i++) {
j = 0; j < 4; j++;
if (i < j) { foo(); }
}
`
os.Stdout.Write(FormatBytes(nil, []byte(src)))
// Output:
// // Blah blah blah.
//
// for (i = 0; i < 3; i++) {
// j = 0;
// j < 4;
// j++;
// if (i < j) {
// foo();
// }
// }
}