Moved to google.golang.org/genproto/googleapis/api/annotations
Fixes #52
This commit is contained in:
84
vendor/github.com/Masterminds/sprig/defaults_test.go
generated
vendored
Normal file
84
vendor/github.com/Masterminds/sprig/defaults_test.go
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
package sprig
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDefault(t *testing.T) {
|
||||
tpl := `{{"" | default "foo"}}`
|
||||
if err := runt(tpl, "foo"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{default "foo" 234}}`
|
||||
if err := runt(tpl, "234"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{default "foo" 2.34}}`
|
||||
if err := runt(tpl, "2.34"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tpl = `{{ .Nothing | default "123" }}`
|
||||
if err := runt(tpl, "123"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{ default "123" }}`
|
||||
if err := runt(tpl, "123"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmpty(t *testing.T) {
|
||||
tpl := `{{if empty 1}}1{{else}}0{{end}}`
|
||||
if err := runt(tpl, "0"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tpl = `{{if empty 0}}1{{else}}0{{end}}`
|
||||
if err := runt(tpl, "1"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{if empty ""}}1{{else}}0{{end}}`
|
||||
if err := runt(tpl, "1"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{if empty 0.0}}1{{else}}0{{end}}`
|
||||
if err := runt(tpl, "1"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{if empty false}}1{{else}}0{{end}}`
|
||||
if err := runt(tpl, "1"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
dict := map[string]interface{}{"top": map[string]interface{}{}}
|
||||
tpl = `{{if empty .top.NoSuchThing}}1{{else}}0{{end}}`
|
||||
if err := runtv(tpl, "1", dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{if empty .bottom.NoSuchThing}}1{{else}}0{{end}}`
|
||||
if err := runtv(tpl, "1", dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func TestCoalesce(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
`{{ coalesce 1 }}`: "1",
|
||||
`{{ coalesce "" 0 nil 2 }}`: "2",
|
||||
`{{ $two := 2 }}{{ coalesce "" 0 nil $two }}`: "2",
|
||||
`{{ $two := 2 }}{{ coalesce "" $two 0 0 0 }}`: "2",
|
||||
`{{ $two := 2 }}{{ coalesce "" $two 3 4 5 }}`: "2",
|
||||
`{{ coalesce }}`: "<no value>",
|
||||
}
|
||||
for tpl, expect := range tests {
|
||||
assert.NoError(t, runt(tpl, expect))
|
||||
}
|
||||
|
||||
dict := map[string]interface{}{"top": map[string]interface{}{}}
|
||||
tpl := `{{ coalesce .top.NoSuchThing .bottom .bottom.dollar "airplane"}}`
|
||||
if err := runtv(tpl, "airplane", dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user