gopkg.in/easygen.v4@v4.1.0/easygen_test.go (about) 1 package easygen_test 2 3 import ( 4 "os" 5 "text/template" 6 7 "github.com/go-easygen/easygen" 8 ) 9 10 var tmpl *template.Template 11 12 func init() { 13 tmpl = easygen.NewTemplate().Funcs(easygen.FuncDefs()) 14 } 15 16 //////////////////////////////////////////////////////////////////////////// 17 // Lists 18 19 //========================================================================== 20 // list0 data + string template 21 // I.e.: EasyGen -ts "{{range .Colors}}{{.}}, {{end}}" test/list0 22 23 // Test string template with list0 data 24 func ExampleProcess0_list0StrTemplate() { 25 // Equivalent testing on commandline: 26 // easygen -ts '{{range .Colors}}{{.}}, {{end}}' test/list0 27 easygen.Process0(tmpl, os.Stdout, 28 "{{range .Colors}}{{.}}, {{end}}", "test/list0") 29 // Output: 30 // red, blue, white, 31 } 32 33 // Test HTML template with list1 data 34 func ExampleProcess2_html() { 35 // Equivalent testing on commandline: 36 // easygen -tf test/list1HTML test/list1 37 easygen.Process2(tmpl, os.Stdout, "test/list1HTML", "test/list1") 38 // Output: 39 // The quoted colors are: "red", "blue", "white", . 40 } 41 42 //////////////////////////////////////////////////////////////////////////// 43 // Strings Test 44 45 // Test string comparison in template 46 func ExampleProcess0_stringsCmp() { 47 // Equivalent testing on commandline: 48 // easygen -ts '{{The {{if ... {{end}}.' test/strings0 49 easygen.Process0(tmpl, os.Stdout, 50 `The {{if eq .StrTest "-AB-axxb- HTML Html html"}}eq says Yea{{else}}eq says Nay{{end}} but {{if eqf .StrTest "-AB-axxb- HTML Html html"}}eqf says Yea{{else}}eqf says Nay{{end}}.`, "test/strings0") 51 // Output: 52 // The eq says Nay but eqf says Yea. 53 } 54 55 // Test the string split function in template 56 func ExampleProcess0_split0() { 57 // Equivalent testing on commandline: 58 // easygen -ts '{{split .Colorlist}}' test/list0 59 easygen.Process0(tmpl, os.Stdout, 60 `{{split .Colorlist}}`, "test/list0") 61 // Output: 62 // [red blue white] 63 } 64 65 // Test the string split function in template again 66 func ExampleProcess0_split1() { 67 // Equivalent testing on commandline: 68 // easygen -ts '{{range ... {{end}}' test/list0 69 easygen.Process0(tmpl, os.Stdout, 70 `{{range (split .Colorlist)}}{{.}} {{end}}`, "test/list0") 71 // Output: 72 // red blue white 73 }