make tests happy

This commit is contained in:
Hunter Kehoe
2025-07-07 22:47:41 -06:00
parent 1f2c76e63d
commit 650f492d7d
9 changed files with 27 additions and 210 deletions

View File

@@ -3,16 +3,10 @@ package sprig
import (
"bytes"
"encoding/json"
"math/rand"
"reflect"
"strings"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
// dfault checks whether `given` is set, and returns default if not set.
//
// This returns `d` if `given` appears not to be set, and `given` otherwise.

View File

@@ -11,6 +11,8 @@ import (
"strings"
ttemplate "text/template"
"time"
"golang.org/x/text/cases"
)
// FuncMap produces the function map.
@@ -107,7 +109,7 @@ var genericMap = map[string]interface{}{
"trim": strings.TrimSpace,
"upper": strings.ToUpper,
"lower": strings.ToLower,
"title": strings.Title,
"title": cases.Title,
"substr": substring,
// Switch order so that "foo" | repeat 5
"repeat": func(count int, str string) string { return strings.Repeat(str, count) },

View File

@@ -39,7 +39,7 @@ func mustPush(list interface{}, v interface{}) ([]interface{}, error) {
return append(nl, v), nil
default:
return nil, fmt.Errorf("Cannot push on type %s", tp)
return nil, fmt.Errorf("cannot push on type %s", tp)
}
}
@@ -69,7 +69,7 @@ func mustPrepend(list interface{}, v interface{}) ([]interface{}, error) {
return append([]interface{}{v}, nl...), nil
default:
return nil, fmt.Errorf("Cannot prepend on type %s", tp)
return nil, fmt.Errorf("cannot prepend on type %s", tp)
}
}
@@ -113,7 +113,7 @@ func mustChunk(size int, list interface{}) ([][]interface{}, error) {
return nl, nil
default:
return nil, fmt.Errorf("Cannot chunk type %s", tp)
return nil, fmt.Errorf("cannot chunk type %s", tp)
}
}
@@ -139,7 +139,7 @@ func mustLast(list interface{}) (interface{}, error) {
return l2.Index(l - 1).Interface(), nil
default:
return nil, fmt.Errorf("Cannot find last on type %s", tp)
return nil, fmt.Errorf("cannot find last on type %s", tp)
}
}
@@ -165,7 +165,7 @@ func mustFirst(list interface{}) (interface{}, error) {
return l2.Index(0).Interface(), nil
default:
return nil, fmt.Errorf("Cannot find first on type %s", tp)
return nil, fmt.Errorf("cannot find first on type %s", tp)
}
}
@@ -196,7 +196,7 @@ func mustRest(list interface{}) ([]interface{}, error) {
return nl, nil
default:
return nil, fmt.Errorf("Cannot find rest on type %s", tp)
return nil, fmt.Errorf("cannot find rest on type %s", tp)
}
}
@@ -227,7 +227,7 @@ func mustInitial(list interface{}) ([]interface{}, error) {
return nl, nil
default:
return nil, fmt.Errorf("Cannot find initial on type %s", tp)
return nil, fmt.Errorf("cannot find initial on type %s", tp)
}
}
@@ -267,7 +267,7 @@ func mustReverse(v interface{}) ([]interface{}, error) {
return nl, nil
default:
return nil, fmt.Errorf("Cannot find reverse on type %s", tp)
return nil, fmt.Errorf("cannot find reverse on type %s", tp)
}
}
@@ -298,7 +298,7 @@ func mustCompact(list interface{}) ([]interface{}, error) {
return nl, nil
default:
return nil, fmt.Errorf("Cannot compact on type %s", tp)
return nil, fmt.Errorf("cannot compact on type %s", tp)
}
}
@@ -329,7 +329,7 @@ func mustUniq(list interface{}) ([]interface{}, error) {
return dest, nil
default:
return nil, fmt.Errorf("Cannot find uniq on type %s", tp)
return nil, fmt.Errorf("cannot find uniq on type %s", tp)
}
}
@@ -369,7 +369,7 @@ func mustWithout(list interface{}, omit ...interface{}) ([]interface{}, error) {
return res, nil
default:
return nil, fmt.Errorf("Cannot find without on type %s", tp)
return nil, fmt.Errorf("cannot find without on type %s", tp)
}
}
@@ -401,7 +401,7 @@ func mustHas(needle interface{}, haystack interface{}) (bool, error) {
return false, nil
default:
return false, fmt.Errorf("Cannot find has on type %s", tp)
return false, fmt.Errorf("cannot find has on type %s", tp)
}
}
@@ -457,7 +457,7 @@ func concat(lists ...interface{}) interface{} {
res = append(res, l2.Index(i).Interface())
}
default:
panic(fmt.Sprintf("Cannot concat type %s as list", tp))
panic(fmt.Sprintf("cannot concat type %s as list", tp))
}
}
return res

View File

@@ -101,7 +101,7 @@ func TestToFloat64(t *testing.T) {
if target != toFloat64("102") {
t.Errorf("Expected 102")
}
if 0 != toFloat64("frankie") {
if toFloat64("frankie") != 0 {
t.Errorf("Expected 0")
}
if target != toFloat64(uint16(102)) {
@@ -110,10 +110,10 @@ func TestToFloat64(t *testing.T) {
if target != toFloat64(uint64(102)) {
t.Errorf("Expected 102")
}
if 102.1234 != toFloat64(float64(102.1234)) {
if toFloat64(float64(102.1234)) != 102.1234 {
t.Errorf("Expected 102.1234")
}
if 1 != toFloat64(true) {
if toFloat64(true) != 1 {
t.Errorf("Expected 102")
}
}
@@ -137,7 +137,7 @@ func TestToInt64(t *testing.T) {
if target != toInt64("102") {
t.Errorf("Expected 102")
}
if 0 != toInt64("frankie") {
if toInt64("frankie") != 0 {
t.Errorf("Expected 0")
}
if target != toInt64(uint16(102)) {
@@ -149,7 +149,7 @@ func TestToInt64(t *testing.T) {
if target != toInt64(float64(102.1234)) {
t.Errorf("Expected 102")
}
if 1 != toInt64(true) {
if toInt64(true) != 1 {
t.Errorf("Expected 102")
}
}
@@ -174,7 +174,7 @@ func TestToInt(t *testing.T) {
if target != toInt("102") {
t.Errorf("Expected 102")
}
if 0 != toInt("frankie") {
if toInt("frankie") != 0 {
t.Errorf("Expected 0")
}
if target != toInt(uint16(102)) {
@@ -186,7 +186,7 @@ func TestToInt(t *testing.T) {
if target != toInt(float64(102.1234)) {
t.Errorf("Expected 102")
}
if 1 != toInt(true) {
if toInt(true) != 1 {
t.Errorf("Expected 102")
}
}