package tests import ( "git.virtual.blue/tomgracey/template-nest-go" "github.com/stretchr/testify/assert" "io/ioutil" "strings" "testing" ) func TestRenderWithAltDelim(t *testing.T) { nest, err := templatenest.New(templatenest.Option{ TemplateDir: "templates", Delimiters: [2]string{"<%", "%>"}, }) if err != nil { t.Fatalf("Failed to initialize TemplateNest: %+v", err) } page := map[string]interface{}{ "TEMPLATE": "00-simple-page-alt-delim", "variable": "Simple Variable", "simple_component": map[string]interface{}{ "TEMPLATE": "01-simple-component-alt-delim", "variable": "Simple Variable in Simple Component", }, } render := nest.MustRender(page) outputPath := "templates/output/01-simple-page.html" outputContents, err := ioutil.ReadFile(outputPath) if err != nil { t.Fatalf("error reading file (`%s`): %+v", outputPath, err) } assert.Equal( t, strings.TrimSpace(string(outputContents)), render, "Rendered output does not match expected output", ) } func TestRenderWithAltDelimAndFixedIndent(t *testing.T) { nest, err := templatenest.New(templatenest.Option{ TemplateDir: "templates", Delimiters: [2]string{"<%", "%>"}, FixedIndent: true, }) if err != nil { t.Fatalf("Failed to initialize TemplateNest: %+v", err) } page := map[string]interface{}{ "TEMPLATE": "00-simple-page-alt-delim", "variable": "Simple Variable", "simple_component": map[string]interface{}{ "TEMPLATE": "02-simple-component-multi-line-alt-delim", }, } render := nest.MustRender(page) outputPath := "templates/output/07-simple-page-fixed-indent.html" outputContents, err := ioutil.ReadFile(outputPath) if err != nil { t.Fatalf("error reading file (`%s`): %+v", outputPath, err) } assert.Equal( t, strings.TrimSpace(string(outputContents)), render, "Rendered output does not match expected output", ) }