github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/flosch/pongo2.v3/pongo2_test.go (about) 1 package pongo2 2 3 import ( 4 "testing" 5 6 . "github.com/insionng/yougam/libraries/check.v1" 7 ) 8 9 // Hook up gocheck into the "go test" runner. 10 11 func Test(t *testing.T) { TestingT(t) } 12 13 type TestSuite struct { 14 tpl *Template 15 } 16 17 var ( 18 _ = Suite(&TestSuite{}) 19 test_suite2 = NewSet("test suite 2") 20 ) 21 22 func parseTemplate(s string, c Context) string { 23 t, err := test_suite2.FromString(s) 24 if err != nil { 25 panic(err) 26 } 27 out, err := t.Execute(c) 28 if err != nil { 29 panic(err) 30 } 31 return out 32 } 33 34 func parseTemplateFn(s string, c Context) func() { 35 return func() { 36 parseTemplate(s, c) 37 } 38 } 39 40 func (s *TestSuite) TestMisc(c *C) { 41 // Must 42 // TODO: Add better error message (see issue #18) 43 c.Check(func() { Must(test_suite2.FromFile("template_tests/inheritance/base2.tpl")) }, 44 PanicMatches, 45 `\[Error \(where: fromfile\) in template_tests/inheritance/doesnotexist.tpl | Line 1 Col 12 near 'doesnotexist.tpl'\] open template_tests/inheritance/doesnotexist.tpl: no such file or directory`) 46 47 // Context 48 c.Check(parseTemplateFn("", Context{"'illegal": nil}), PanicMatches, ".*not a valid identifier.*") 49 50 // Registers 51 c.Check(func() { RegisterFilter("escape", nil) }, PanicMatches, ".*is already registered.*") 52 c.Check(func() { RegisterTag("for", nil) }, PanicMatches, ".*is already registered.*") 53 54 // ApplyFilter 55 v, err := ApplyFilter("title", AsValue("this is a title"), nil) 56 if err != nil { 57 c.Fatal(err) 58 } 59 c.Check(v.String(), Equals, "This Is A Title") 60 c.Check(func() { 61 _, err := ApplyFilter("doesnotexist", nil, nil) 62 if err != nil { 63 panic(err) 64 } 65 }, PanicMatches, `\[Error \(where: applyfilter\)\] Filter with name 'doesnotexist' not found.`) 66 }