-
Notifications
You must be signed in to change notification settings - Fork 15
/
tabscanner_test.go
95 lines (93 loc) · 1.93 KB
/
tabscanner_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package struct2ts
import (
"bytes"
"testing"
)
func TestTabScanner_Write(t *testing.T) {
tests := []struct {
Name string
Input struct {
Tabs string
Buffers []string
}
Expected struct {
Output string
n *int
}
}{
{
"One new line mid string - one input, 3 spaces",
struct {
Tabs string
Buffers []string
}{Tabs: " ", Buffers: []string{"Hello how are you?\nI'm fine thanks!"}},
struct {
Output string
n *int
}{Output: "Hello how are you?\n I'm fine thanks!"},
},
{
"One new line end string - one input, 3 spaces",
struct {
Tabs string
Buffers []string
}{Tabs: " ", Buffers: []string{"Hello how are you?\n"}},
struct {
Output string
n *int
}{Output: "Hello how are you?\n "},
},
{
"One new line start string - one input, 3 spaces",
struct {
Tabs string
Buffers []string
}{Tabs: " ", Buffers: []string{"\nHello how are you?"}},
struct {
Output string
n *int
}{Output: "\n Hello how are you?"},
},
{
"empty string",
struct {
Tabs string
Buffers []string
}{Tabs: " ", Buffers: []string{""}},
struct {
Output string
n *int
}{Output: ""},
},
{
"Just a new line",
struct {
Tabs string
Buffers []string
}{Tabs: " ", Buffers: []string{"\n"}},
struct {
Output string
n *int
}{Output: "\n "},
},
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
outputBuffer := bytes.NewBuffer(nil)
ts := newTabScanner(outputBuffer, test.Input.Tabs)
for _, s := range test.Input.Buffers {
_, err := ts.Write([]byte(s))
if err != nil {
t.Error("Buffer write error", err)
}
}
if outputBuffer.String() != test.Expected.Output {
t.Log("Output buffer doesn't match. Got ")
t.Log(outputBuffer.String())
t.Log("expected")
t.Log(test.Expected.Output)
t.Fail()
}
})
}
}