diff --git a/lang/funcs/cidr.go b/lang/funcs/cidr.go index 2680790bb..6ce8aa9fa 100644 --- a/lang/funcs/cidr.go +++ b/lang/funcs/cidr.go @@ -10,7 +10,7 @@ import ( "github.com/zclconf/go-cty/cty/gocty" ) -// CidrHostFunc contructs a function that calculates a full host IP address +// CidrHostFunc contructs a function that calculates a full host IP address // within a given IP network address prefix. var CidrHostFunc = function.New(&function.Spec{ Params: []function.Parameter{ @@ -43,7 +43,7 @@ var CidrHostFunc = function.New(&function.Spec{ }, }) -// CidrNetmaskFunc contructs a function that converts an IPv4 address prefix given +// CidrNetmaskFunc contructs a function that converts an IPv4 address prefix given // in CIDR notation into a subnet mask address. var CidrNetmaskFunc = function.New(&function.Spec{ Params: []function.Parameter{ @@ -63,7 +63,7 @@ var CidrNetmaskFunc = function.New(&function.Spec{ }, }) -// CidrSubnetFunc contructs a function that calculates a subnet address within +// CidrSubnetFunc contructs a function that calculates a subnet address within // a given IP network address prefix. var CidrSubnetFunc = function.New(&function.Spec{ Params: []function.Parameter{ diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index 27641150c..a28dd3eee 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -107,7 +107,7 @@ var LengthFunc = function.New(&function.Spec{ }, }) -// CoalesceListFunc contructs a function that takes any number of list arguments +// CoalesceListFunc contructs a function that takes any number of list arguments // and returns the first one that isn't empty. var CoalesceListFunc = function.New(&function.Spec{ Params: []function.Parameter{}, @@ -159,7 +159,7 @@ var CoalesceListFunc = function.New(&function.Spec{ }, }) -// CompactFunc contructs a function that takes a list of strings and returns a new list +// CompactFunc contructs a function that takes a list of strings and returns a new list // with any empty string elements removed. var CompactFunc = function.New(&function.Spec{ Params: []function.Parameter{ @@ -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}) } diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index 0385e4c64..c963a2bef 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -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 { diff --git a/lang/functions.go b/lang/functions.go index fd69d9002..cc653e86c 100644 --- a/lang/functions.go +++ b/lang/functions.go @@ -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,