52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package tests
|
|
|
|
import (
|
|
"git.virtual.blue/tomgracey/template-nest-go"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderWithDefaults(t *testing.T) {
|
|
nest, err := templatenest.New(templatenest.Option{
|
|
TemplateDir: "templates",
|
|
Defaults: templatenest.Hash{
|
|
"variable": "Simple Variable",
|
|
"space": templatenest.Hash{
|
|
"inside": "A variable inside a space.",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Failed to initialize TemplateNest: %+v", err)
|
|
}
|
|
|
|
page := templatenest.Hash{
|
|
"TEMPLATE": "00-simple-page",
|
|
"simple_component": []templatenest.Hash{
|
|
templatenest.Hash{
|
|
"TEMPLATE": "01-simple-component",
|
|
"variable": "Simple Variable in Simple Component",
|
|
},
|
|
},
|
|
}
|
|
|
|
outputPage := templatenest.Hash{"TEMPLATE": "output/01-simple-page"}
|
|
|
|
assert.Equal(
|
|
t,
|
|
nest.MustRender(outputPage),
|
|
nest.MustRender(page),
|
|
"Rendered output does not match expected output",
|
|
)
|
|
|
|
spacePage := templatenest.Hash{"TEMPLATE": "03-namespace-page"}
|
|
spaceOutputPage := templatenest.Hash{"TEMPLATE": "output/11-namespace-page"}
|
|
|
|
assert.Equal(
|
|
t,
|
|
nest.MustRender(spaceOutputPage),
|
|
nest.MustRender(spacePage),
|
|
"Rendered output does not match expected output",
|
|
)
|
|
}
|