-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathindent_test.go
More file actions
48 lines (45 loc) · 750 Bytes
/
Copy pathindent_test.go
File metadata and controls
48 lines (45 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package dot
import (
"bytes"
"fmt"
"testing"
)
func TestIndentWriter(t *testing.T) {
b := new(bytes.Buffer)
i := NewIndentWriter(b)
i.WriteString("doc {")
i.NewLineIndentWhile(func() {
fmt.Fprint(i, "chapter {")
i.NewLineIndentWhile(func() {
fmt.Fprint(i, "chapter text")
})
i.WriteString("}")
})
i.WriteString("}")
got := b.String()
want := `doc {
chapter {
chapter text
}
}`
if got != want {
t.Fail()
}
}
func TestIndentWriter_IndentWhile(t *testing.T) {
b := new(bytes.Buffer)
i := NewIndentWriter(b)
i.IndentWhile(func() {
i.WriteString("[")
i.IndentWhile(func() {
i.WriteString("test")
})
i.WriteString("]")
})
got := b.String()
want := ` [ test]`
if got != want {
t.Log(got)
t.Fail()
}
}