-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathgtf_text_test.go
More file actions
29 lines (22 loc) · 840 Bytes
/
Copy pathgtf_text_test.go
File metadata and controls
29 lines (22 loc) · 840 Bytes
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
package gtf
import (
"bytes"
"testing"
"text/template"
)
func TextTemplateParseTest(buffer *bytes.Buffer, body string, data interface{}) {
tpl := template.New("test").Funcs(GtfTextFuncMap)
tpl.Parse(body)
tpl.Execute(buffer, data)
}
func TestTextTemplateGtfFuncMap(t *testing.T) {
var buffer bytes.Buffer
TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | replace \" \" }}", "")
AssertEqual(t, &buffer, "TheGoProgrammingLanguage")
TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | findreplace \" \" \"X\" }}", "")
AssertEqual(t, &buffer, "TheXGoXProgrammingXLanguage")
TextTemplateParseTest(&buffer, "{{ \"The Go Programming Language\" | length }}", "")
AssertEqual(t, &buffer, "27")
TextTemplateParseTest(&buffer, "{{ 21 | divisibleby 3 }}", "")
AssertEqual(t, &buffer, "true")
}