Add unit test that raw strings are printed as is (#599)

## Changes
Add unit test that raw strings are printed as is. This method is useful
to print text that would otherwise be interpreted a go text template.
This commit is contained in:
shreyas-goenka 2023-07-25 17:18:43 +02:00 committed by GitHub
parent 47640b8b94
commit 34f196bb4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -2,12 +2,28 @@ package template
import ( import (
"context" "context"
"strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestTemplatePrintStringWithoutProcessing(t *testing.T) {
ctx := context.Background()
tmpDir := t.TempDir()
r, err := newRenderer(ctx, nil, "./testdata/print-without-processing/template", "./testdata/print-without-processing/library", tmpDir)
require.NoError(t, err)
err = r.walk()
assert.NoError(t, err)
assert.Len(t, r.files, 1)
cleanContent := strings.Trim(string(r.files[0].content), "\n\r")
assert.Equal(t, `{{ fail "abc" }}`, cleanContent)
}
func TestTemplateRegexpCompileFunction(t *testing.T) { func TestTemplateRegexpCompileFunction(t *testing.T) {
ctx := context.Background() ctx := context.Background()
tmpDir := t.TempDir() tmpDir := t.TempDir()

View File

@ -0,0 +1 @@
{{`{{ fail "abc" }}`}}