/
easygen_test.go
73 lines (61 loc) · 2.16 KB
/
easygen_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package easygen_test
import (
"os"
"text/template"
"github.com/go-easygen/easygen"
)
var tmpl *template.Template
func init() {
tmpl = easygen.NewTemplate().Funcs(easygen.FuncDefs())
}
////////////////////////////////////////////////////////////////////////////
// Lists
//==========================================================================
// list0 data + string template
// I.e.: EasyGen -ts "{{range .Colors}}{{.}}, {{end}}" test/list0
// Test string template with list0 data
func ExampleProcess0_list0StrTemplate() {
// Equivalent testing on commandline:
// easygen -ts '{{range .Colors}}{{.}}, {{end}}' test/list0
easygen.Process0(tmpl, os.Stdout,
"{{range .Colors}}{{.}}, {{end}}", "test/list0")
// Output:
// red, blue, white,
}
// Test HTML template with list1 data
func ExampleProcess2_html() {
// Equivalent testing on commandline:
// easygen -tf test/list1HTML test/list1
easygen.Process2(tmpl, os.Stdout, "test/list1HTML", "test/list1")
// Output:
// The quoted colors are: "red", "blue", "white", .
}
////////////////////////////////////////////////////////////////////////////
// Strings Test
// Test string comparison in template
func ExampleProcess0_stringsCmp() {
// Equivalent testing on commandline:
// easygen -ts '{{The {{if ... {{end}}.' test/strings0
easygen.Process0(tmpl, os.Stdout,
`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")
// Output:
// The eq says Nay but eqf says Yea.
}
// Test the string split function in template
func ExampleProcess0_split0() {
// Equivalent testing on commandline:
// easygen -ts '{{split .Colorlist}}' test/list0
easygen.Process0(tmpl, os.Stdout,
`{{split .Colorlist}}`, "test/list0")
// Output:
// [red blue white]
}
// Test the string split function in template again
func ExampleProcess0_split1() {
// Equivalent testing on commandline:
// easygen -ts '{{range ... {{end}}' test/list0
easygen.Process0(tmpl, os.Stdout,
`{{range (split .Colorlist)}}{{.}} {{end}}`, "test/list0")
// Output:
// red blue white
}