-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
91 lines (83 loc) · 1.76 KB
/
format_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
package a2conf_test
import (
"io"
"io/ioutil"
"strings"
"testing"
. "github.com/bearx3f/a2conf"
)
var (
opt = FormatOption{
Tab2Space: true,
TabSize: 4,
}
test1In, _ = ioutil.ReadFile("./test/test1_input.txt")
test1Out, _ = ioutil.ReadFile("./test/test1_output.txt")
test2In, _ = ioutil.ReadFile("./test/test2_input.txt")
test2Out, _ = ioutil.ReadFile("./test/test2_output.txt")
test3In, _ = ioutil.ReadFile("./test/test3_input.txt")
test3Out, _ = ioutil.ReadFile("./test/test3_output.txt")
test4In, _ = ioutil.ReadFile("./test/test4_input.txt")
test4Out, _ = ioutil.ReadFile("./test/test4_output.txt")
)
func TestFormat(t *testing.T) {
type args struct {
in io.Reader
fmtOpt FormatOption
}
tests := []struct {
name string
args args
wantOutput string
wantErr bool
}{
{
name: "Test1",
args: args{
strings.NewReader(string(test1In)),
opt,
},
wantOutput: string(test1Out),
wantErr: false,
},
{
name: "Test2",
args: args{
strings.NewReader(string(test2In)),
opt,
},
wantOutput: string(test2Out),
wantErr: false,
},
{
name: "Test3",
args: args{
strings.NewReader(string(test3In)),
opt,
},
wantOutput: string(test3Out),
wantErr: false,
},
{
name: "Test4",
args: args{
strings.NewReader(string(test4In)),
opt,
},
wantOutput: string(test4Out),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotOutput, err := Format(tt.args.in, tt.args.fmtOpt)
if (err != nil) != tt.wantErr {
t.Errorf("Format() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotOutput != tt.wantOutput {
t.Errorf("Format() = %v, want %v", gotOutput, tt.wantOutput)
}
})
}
}