-
Notifications
You must be signed in to change notification settings - Fork 0
/
writer_test.go
57 lines (49 loc) · 1.11 KB
/
writer_test.go
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
49
50
51
52
53
54
55
56
57
package lunar
import (
"bytes"
"fmt"
"testing"
)
func TestWriteLine(t *testing.T) {
buf := &bytes.Buffer{}
w := NewWriter(buf)
// Write one line
w.WriteLine("foo")
want := "foo\n"
if s := buf.String(); s != want {
t.Fatalf("Got output %q, want %q", s, want)
}
// Indent and write two more
w.Indent()
w.Indent()
w.WriteLine("bar boo")
w.WriteLine("hooray")
want += "\t\tbar boo\n\t\thooray\n"
if s := buf.String(); s != want {
t.Fatalf("Got output %q, want %q", s, want)
}
// Dedent and write another
w.Dedent()
w.WriteLine("dedented")
want += "\tdedented\n"
if s := buf.String(); s != want {
t.Fatalf("Got output %q, want %q", s, want)
}
// Dedent and write another
w.Dedent()
w.WriteLine("back to square one")
want += "back to square one\n"
if s := buf.String(); s != want {
t.Fatalf("Got output %q, want %q", s, want)
}
}
func TestWriteLinef(t *testing.T) {
buf := &bytes.Buffer{}
w := NewWriter(buf)
want := fmt.Sprintf("\tfoo %s %d hi\n", "foo", 5)
w.Indent()
w.WriteLinef("foo %s %d hi", "foo", 5)
if s := buf.String(); s != want {
t.Fatalf("Got output %q, want %q", s, want)
}
}