-
-
Notifications
You must be signed in to change notification settings - Fork 270
/
filters_builtin_test.go
42 lines (36 loc) · 945 Bytes
/
filters_builtin_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
package pongo2
import (
"errors"
"fmt"
"io"
"path/filepath"
"testing"
)
type DummyLoader struct{}
func (l *DummyLoader) Abs(base, name string) string {
return filepath.Join(filepath.Dir(base), name)
}
func (l *DummyLoader) Get(path string) (io.Reader, error) {
return nil, errors.New("dummy not found")
}
func FuzzBuiltinFilters(f *testing.F) {
f.Add("foobar", "123")
f.Add("foobar", `123,456`)
f.Add("foobar", `123,456,"789"`)
f.Add("foobar", `"test","test"`)
f.Add("foobar", `123,"test"`)
f.Add("foobar", "")
f.Add("123", "foobar")
f.Fuzz(func(t *testing.T, value, filterArg string) {
ts := NewSet("fuzz-test", &DummyLoader{})
for name := range filters {
tpl, err := ts.FromString(fmt.Sprintf("{{ %v|%v:%v }}", value, name, filterArg))
if tpl != nil && err != nil {
t.Errorf("filter=%q value=%q, filterArg=%q, err=%v", name, value, filterArg, err)
}
if err == nil {
tpl.Execute(nil)
}
}
})
}