Add dumbindent.Options (tabs vs spaces)

This commit is contained in:
Nigel Tao committed 2020-06-07 21:59:53 +10:00
1 parent 53d5f5155c
commit 2858c4cfc2
4 files changed
+54 -15

No files matched your search

+11 -2
View File
@@ -78,12 +78,21 @@ func TestFormatBytes(tt *testing.T) {
}}
for i, tc := range testCases {
if got := string(FormatBytes(nil, []byte(tc.src))); got != tc.want {
if got := string(FormatBytes(nil, []byte(tc.src), nil)); got != tc.want {
tt.Fatalf("i=%d, src=%q:\ngot %q\nwant %q", i, tc.src, got, tc.want)
}
}
}
func TestTabs(tt *testing.T) {
const src = "a {\nb\n}\n"
got := string(FormatBytes(nil, []byte(src), &Options{Tabs: true}))
want := "a {\n\tb\n}\n"
if got != want {
tt.Fatalf("\ngot %q\nwant %q", got, want)
}
}
func ExampleFormatBytes() {
const src = `
// Blah blah blah.
@@ -95,7 +104,7 @@ if (i < j) { foo(); }
}
`
os.Stdout.Write(FormatBytes(nil, []byte(src)))
os.Stdout.Write(FormatBytes(nil, []byte(src), nil))
// Output:
// // Blah blah blah.