github.com/wynshop-open-source/gomplate@v3.5.0+incompatible/funcs/conv_test.go (about) 1 package funcs 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestDefault(t *testing.T) { 11 s := struct{}{} 12 c := ConvNS() 13 def := "DEFAULT" 14 data := []struct { 15 val interface{} 16 empty bool 17 }{ 18 {0, true}, 19 {1, false}, 20 {nil, true}, 21 {"", true}, 22 {"foo", false}, 23 {[]string{}, true}, 24 {[]string{"foo"}, false}, 25 {[]string{""}, false}, 26 {c, false}, 27 {s, false}, 28 } 29 30 for _, d := range data { 31 t.Run(fmt.Sprintf("%T/%#v empty==%v", d.val, d.val, d.empty), func(t *testing.T) { 32 if d.empty { 33 assert.Equal(t, def, c.Default(def, d.val)) 34 } else { 35 assert.Equal(t, d.val, c.Default(def, d.val)) 36 } 37 }) 38 } 39 }