Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions defaults_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sprig

import (
"math"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -150,6 +151,15 @@ func TestToJson(t *testing.T) {
}
}

func TestMustToJson(t *testing.T) {
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": math.NaN()}}

tpl := `{{.Top | mustToJson}}`
if err := runtv(tpl, "", dict); err == nil {
t.Error("expected err, got nil")
}
}

func TestToPrettyJson(t *testing.T) {
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42}}
tpl := `{{.Top | toPrettyJson}}`
Expand All @@ -163,6 +173,15 @@ func TestToPrettyJson(t *testing.T) {
}
}

func TestMustToPrettyJson(t *testing.T) {
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": math.NaN()}}

tpl := `{{.Top | mustToPrettyJson}}`
if err := runtv(tpl, "", dict); err == nil {
t.Error("expected err, got nil")
}
}

func TestToRawJson(t *testing.T) {
dict := map[string]interface{}{"Top": map[string]interface{}{"bool": true, "string": "test", "number": 42, "html": "<HEAD>"}}
tpl := `{{.Top | toRawJson}}`
Expand Down
Loading