Skip to content
Merged
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
25 changes: 23 additions & 2 deletions strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@ package sprig
import (
"encoding/base32"
"encoding/base64"
"errors"
"fmt"
"testing"
"unicode/utf8"

"github.com/stretchr/testify/assert"
)

type stringerImpl struct {
Value string
}

// String satisfies the Stringer interface.
func (s stringerImpl) String() string {
return s.Value
}

func TestSubstr(t *testing.T) {
tpl := `{{"fooo" | substr 0 3 }}`
if err := runt(tpl, "foo"); err != nil {
Expand Down Expand Up @@ -121,8 +131,19 @@ func TestSplitn(t *testing.T) {
}

func TestToString(t *testing.T) {
tpl := `{{ toString 1 | kindOf }}`
assert.NoError(t, runt(tpl, "string"))
tests := []interface{}{
1,
"string",
[]byte("bytes"),
errors.New("error"),
stringerImpl{
Value: "stringer",
},
}
for _, test := range tests {
tpl := `{{ toString .Value | kindOf }}`
assert.NoError(t, runtv(tpl, "string", map[string]interface{}{"Value": test}))
}
}

func TestToStrings(t *testing.T) {
Expand Down
Loading