From e09a3298c3de1e47d02473792065ec5d708580c1 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sat, 16 Nov 2024 18:22:01 +0530 Subject: [PATCH] Add more simple render tests --- tests/01_render_test.go | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/01_render_test.go b/tests/01_render_test.go index cfec9c2..fdf7535 100644 --- a/tests/01_render_test.go +++ b/tests/01_render_test.go @@ -143,3 +143,69 @@ func TestRenderArrayOfTemplateHash(t *testing.T) { assert.Equal(t, outputRender, render, "Rendered output does not match expected output") } + +func TestRenderNonExistentFile(t *testing.T) { + nest, err := templatenest.New(templatenest.Option{TemplateDir: "templates"}) + if err != nil { + t.Fatalf("Failed to initialize TemplateNest: %+v", err) + } + + page := templatenest.Hash{"TEMPLATE": "this-template-file-does-not-exist"} + + _, err = nest.Render(page) + if assert.NotNil(t, err) { + expected := "error getting file info:" + assert.Equal(t, expected, err.Error()[:len(expected)]) + } +} + +func TestRenderNoNameLabel(t *testing.T) { + nest, err := templatenest.New(templatenest.Option{TemplateDir: "templates"}) + if err != nil { + t.Fatalf("Failed to initialize TemplateNest: %+v", err) + } + + page := templatenest.Hash{"variable": "Simple Variable"} + + _, err = nest.Render(page) + if assert.NotNil(t, err) { + expected := "encountered hash with no name label" + assert.Equal(t, expected, err.Error()[:len(expected)]) + } +} + +func TestRenderSimplePageArrays(t *testing.T) { + nest, err := templatenest.New(templatenest.Option{ + TemplateDir: "templates", + NoEscapeInput: true, + }) + if err != nil { + t.Fatalf("Failed to initialize TemplateNest: %+v", err) + } + + page := templatenest.Hash{ + "TEMPLATE": "00-simple-page", + "variable": "Simple Variable", + "simple_component": []interface{}{ + templatenest.Hash{ + "TEMPLATE": "01-simple-component", + "variable": "Simple Variable in Simple Component", + }, + "Another test", + []interface{}{ + templatenest.Hash{ + "TEMPLATE": "01-simple-component", + "variable": "Simple Variable in Simple Component", + }, + "Another nested test 2", + }, + }, + } + + outputPage := templatenest.Hash{"TEMPLATE": "output/12-simple-page-arrays"} + + render := nest.MustRender(page) + outputRender := nest.MustRender(outputPage) + + assert.Equal(t, outputRender, render, "Rendered output does not match expected output") +}