This commit is contained in:
24
pkg/filter/dump_test.go
Normal file
24
pkg/filter/dump_test.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package filter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"github.com/flosch/pongo2"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestDumpFilter(t *testing.T) {
|
||||
Convey("set context", t, func() {
|
||||
ctx := pongo2.Context{
|
||||
"testvar": "test",
|
||||
}
|
||||
Convey("parse template", func() {
|
||||
output, err := pongo2.RenderTemplateString("{{ testvar|safe|dump }}", ctx)
|
||||
So(err, ShouldBeNil)
|
||||
So(output, ShouldEqual, spew.Sdump("test"))
|
||||
})
|
||||
})
|
||||
}
|
||||
50
pkg/filter/json_test.go
Normal file
50
pkg/filter/json_test.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package filter
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
|
||||
"github.com/flosch/pongo2"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestJSONFilter(t *testing.T) {
|
||||
Convey("set context", t, func() {
|
||||
ctx := pongo2.Context{
|
||||
"teststr": "test",
|
||||
"testmap": map[string]interface{}{
|
||||
"float": 1.23,
|
||||
"int": 5,
|
||||
"str": "test",
|
||||
},
|
||||
"testerr": math.Inf(1),
|
||||
}
|
||||
Convey("parse template", func() {
|
||||
output, err := pongo2.RenderTemplateString("{{ teststr|safe|json }}", ctx)
|
||||
So(err, ShouldBeNil)
|
||||
So(output, ShouldEqual, `"test"`)
|
||||
|
||||
output, err = pongo2.RenderTemplateString("{{ testmap|safe|json }}", ctx)
|
||||
So(err, ShouldBeNil)
|
||||
So(output, ShouldEqual, `{"float":1.23,"int":5,"str":"test"}`)
|
||||
|
||||
output, err = pongo2.RenderTemplateString(`{{ testmap|safe|json:"pretty" }}`, ctx)
|
||||
So(err, ShouldBeNil)
|
||||
So(output, ShouldEqual, `{
|
||||
"float": 1.23,
|
||||
"int": 5,
|
||||
"str": "test"
|
||||
}`)
|
||||
|
||||
output, err = pongo2.RenderTemplateString("{{ testnil|safe|json }}", ctx)
|
||||
So(err, ShouldBeNil)
|
||||
So(output, ShouldEqual, `null`)
|
||||
|
||||
output, err = pongo2.RenderTemplateString("{{ testerr|safe|json }}", ctx)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(output, ShouldEqual, ``)
|
||||
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user