Stop dividing templates up, and execute by name
- This allows us to use templates defined from anywhere in other templates.
This commit is contained in:
parent
7545343e0d
commit
e08eacad05
5 changed files with 95 additions and 40 deletions
|
@ -6,19 +6,21 @@ import (
|
|||
"text/template"
|
||||
)
|
||||
|
||||
func TestTemplateListSort(t *testing.T) {
|
||||
templs := templateList{
|
||||
template.New("bob.tpl"),
|
||||
template.New("all.tpl"),
|
||||
template.New("struct.tpl"),
|
||||
template.New("ttt.tpl"),
|
||||
func TestTemplateNameListSort(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
templs := templateNameList{
|
||||
"bob.tpl",
|
||||
"all.tpl",
|
||||
"struct.tpl",
|
||||
"ttt.tpl",
|
||||
}
|
||||
|
||||
expected := []string{"bob.tpl", "all.tpl", "struct.tpl", "ttt.tpl"}
|
||||
|
||||
for i, v := range templs {
|
||||
if v.Name() != expected[i] {
|
||||
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v.Name())
|
||||
if v != expected[i] {
|
||||
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,8 +29,40 @@ func TestTemplateListSort(t *testing.T) {
|
|||
sort.Sort(templs)
|
||||
|
||||
for i, v := range templs {
|
||||
if v.Name() != expected[i] {
|
||||
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v.Name())
|
||||
if v != expected[i] {
|
||||
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTemplateList_Templates(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tpl := template.New("")
|
||||
tpl.New("wat.tpl").Parse("hello")
|
||||
tpl.New("que.tpl").Parse("there")
|
||||
tpl.New("not").Parse("hello")
|
||||
|
||||
tplList := templateList{tpl}
|
||||
foundWat, foundQue, foundNot := false, false, false
|
||||
for _, n := range tplList.Templates() {
|
||||
switch n {
|
||||
case "wat.tpl":
|
||||
foundWat = true
|
||||
case "que.tpl":
|
||||
foundQue = true
|
||||
case "not":
|
||||
foundNot = true
|
||||
}
|
||||
}
|
||||
|
||||
if !foundWat {
|
||||
t.Error("want wat")
|
||||
}
|
||||
if !foundQue {
|
||||
t.Error("want que")
|
||||
}
|
||||
if foundNot {
|
||||
t.Error("don't want not")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue