File tree 1 file changed +52
-0
lines changed
1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -89,3 +89,55 @@ func TestParseTruncateFunction(t *testing.T) {
89
89
})
90
90
}
91
91
}
92
+
93
+ func TestHeaderFunctions (t * testing.T ) {
94
+ const source = "hello world"
95
+
96
+ tests := []struct {
97
+ doc string
98
+ template string
99
+ }{
100
+ {
101
+ doc : "json" ,
102
+ template : `{{ json .}}` ,
103
+ },
104
+ {
105
+ doc : "split" ,
106
+ template : `{{ split . ","}}` ,
107
+ },
108
+ {
109
+ doc : "join" ,
110
+ template : `{{ join . ","}}` ,
111
+ },
112
+ {
113
+ doc : "title" ,
114
+ template : `{{ title .}}` ,
115
+ },
116
+ {
117
+ doc : "lower" ,
118
+ template : `{{ lower .}}` ,
119
+ },
120
+ {
121
+ doc : "upper" ,
122
+ template : `{{ upper .}}` ,
123
+ },
124
+ {
125
+ doc : "truncate" ,
126
+ template : `{{ truncate . 2}}` ,
127
+ },
128
+ }
129
+
130
+ for _ , tc := range tests {
131
+ t .Run (tc .doc , func (t * testing.T ) {
132
+ tmpl , err := New ("" ).Funcs (HeaderFunctions ).Parse (tc .template )
133
+ assert .NilError (t , err )
134
+
135
+ var b bytes.Buffer
136
+ assert .NilError (t , tmpl .Execute (& b , source ))
137
+
138
+ // All header-functions are currently stubs, and don't modify the input.
139
+ expected := source
140
+ assert .Equal (t , expected , b .String ())
141
+ })
142
+ }
143
+ }
You can’t perform that action at this time.
0 commit comments