-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_test.go
51 lines (48 loc) · 1.15 KB
/
filter_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
// Copyright 2015 Seth Bunce. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
package stem
import (
"bytes"
"testing"
)
func TestFilter(t *testing.T) {
tests := []struct{
name string // name of the test printed with errors.
flag Filter // flag for filter to enable.
tmpl string // tmpl is the template text.
want string // want this output.
}{
{
name: "blank lines",
flag: NoBlankLines,
tmpl: "foo\n\nbar",
want: "foo\nbar",
},
{
name: "left space",
flag: TrimLeftSpace,
tmpl: "foo\n bar",
want: "foo\nbar",
},
{
name: "left space",
flag: TrimRightSpace,
tmpl: "foo \nbar",
want: "foo\nbar",
},
}
for _, test := range tests {
tmpl, err := Parse(test.tmpl)
if err != nil {
t.Fatalf("couldn't parse template: %v", err)
}
tmpl.Filter(test.flag)
got := bytes.NewBuffer(make([]byte, 0))
if err := tmpl.Execute(got, map[string]interface{}{}); err != nil {
t.Fatalf("couldn't execute template: %v", err)
}
if got.String() != test.want {
t.Fatalf("test %q, got %v, want %v", test.name, got.String(), test.want)
}
}
}