port compact function
This commit is contained in:
parent
1901d5d184
commit
e697e7d733
|
@ -176,8 +176,6 @@ var CompactFunc = function.New(&function.Spec{
|
|||
it := args[0].ElementIterator()
|
||||
for it.Next() {
|
||||
_, v := it.Element()
|
||||
fmt.Println("ohai!")
|
||||
fmt.Println(v.AsString())
|
||||
if v.AsString() == "" {
|
||||
continue
|
||||
}
|
||||
|
@ -208,5 +206,5 @@ func CoalesceList(args ...cty.Value) (cty.Value, error) {
|
|||
// Compact takes a list of strings and returns a new list
|
||||
// with any empty string elements removed.
|
||||
func Compact(list cty.Value) (cty.Value, error) {
|
||||
return CoalesceListFunc.Call([]cty.Value{list})
|
||||
return CompactFunc.Call([]cty.Value{list})
|
||||
}
|
||||
|
|
|
@ -339,6 +339,30 @@ func TestCompact(t *testing.T) {
|
|||
}),
|
||||
false,
|
||||
},
|
||||
{
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.StringVal("test"),
|
||||
cty.StringVal("test"),
|
||||
cty.StringVal(""),
|
||||
}),
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.StringVal("test"),
|
||||
cty.StringVal("test"),
|
||||
}),
|
||||
false,
|
||||
},
|
||||
{ // errrors on list of lists
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.StringVal("test"),
|
||||
}),
|
||||
cty.ListVal([]cty.Value{
|
||||
cty.StringVal(""),
|
||||
}),
|
||||
}),
|
||||
cty.NilVal,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
|
@ -44,7 +44,7 @@ func (s *Scope) Functions() map[string]function.Function {
|
|||
"cidrsubnet": funcs.CidrSubnetFunc,
|
||||
"coalesce": stdlib.CoalesceFunc,
|
||||
"coalescelist": funcs.CoalesceListFunc,
|
||||
"compact": unimplFunc, // TODO
|
||||
"compact": funcs.CompactFunc,
|
||||
"concat": stdlib.ConcatFunc,
|
||||
"contains": unimplFunc, // TODO
|
||||
"csvdecode": stdlib.CSVDecodeFunc,
|
||||
|
|
Loading…
Reference in New Issue