config: Remove "setproduct" function, which is now in lang/funcs

This commit is contained in:
Martin Atkins 2019-01-15 11:54:51 -08:00
parent da51e72cbb
commit 4e14ab7557
2 changed files with 0 additions and 105 deletions

View File

@ -118,7 +118,6 @@ func Funcs() map[string]ast.Function {
"min": interpolationFuncMin(),
"pathexpand": interpolationFuncPathExpand(),
"pow": interpolationFuncPow(),
"setproduct": interpolationFuncSetProduct(),
"uuid": interpolationFuncUUID(),
"replace": interpolationFuncReplace(),
"rsadecrypt": interpolationFuncRsaDecrypt(),
@ -1740,55 +1739,3 @@ func interpolationFuncRsaDecrypt() ast.Function {
},
}
}
// interpolationFuncSetProduct implements the "setproduct" function
// that returns the cartesian product of two or more lists or sets
func interpolationFuncSetProduct() ast.Function {
return ast.Function{
ArgTypes: []ast.Type{ast.TypeList},
ReturnType: ast.TypeList,
Variadic: true,
VariadicType: ast.TypeList,
Callback: func(args []interface{}) (interface{}, error) {
if len(args) < 2 {
return nil, fmt.Errorf("must provide at least two arguments")
}
total := 1
for _, arg := range args {
total *= len(arg.([]ast.Variable))
}
if total == 0 {
return nil, fmt.Errorf("empty list provided")
}
product := make([][]ast.Variable, total)
b := make([]ast.Variable, total*len(args))
n := make([]int, len(args))
s := 0
for i := range product {
e := s + len(args)
pi := b[s:e]
product[i] = pi
s = e
for j, n := range n {
pi[j] = args[j].([]ast.Variable)[n]
}
for j := len(n) - 1; j >= 0; j-- {
n[j]++
if n[j] < len(args[j].([]ast.Variable)) {
break
}
n[j] = 0
}
}
return listVariableSliceToVariableValue(product), nil
},
}
}

View File

@ -2960,55 +2960,3 @@ H7CurtMwALQ/n/6LUKFmjRZjqbKX9SO2QSaC3grd6sY9Tu+bZjLe
},
})
}
func TestInterpolateFuncSetProduct(t *testing.T) {
testFunction(t, testFunctionConfig{
Cases: []testFunctionCase{
{
`${setproduct(list("dev", "qas", "prd"), list("applicationA", "applicationB", "applicationC"))}`,
[]interface{}{
[]interface{}{"dev", "applicationA"},
[]interface{}{"dev", "applicationB"},
[]interface{}{"dev", "applicationC"},
[]interface{}{"qas", "applicationA"},
[]interface{}{"qas", "applicationB"},
[]interface{}{"qas", "applicationC"},
[]interface{}{"prd", "applicationA"},
[]interface{}{"prd", "applicationB"},
[]interface{}{"prd", "applicationC"}},
false,
},
{
`${setproduct(list("A", "B"), list("C", "D"), list("E", "F"))}`,
[]interface{}{
[]interface{}{"A", "C", "E"},
[]interface{}{"A", "C", "F"},
[]interface{}{"A", "D", "E"},
[]interface{}{"A", "D", "F"},
[]interface{}{"B", "C", "E"},
[]interface{}{"B", "C", "F"},
[]interface{}{"B", "D", "E"},
[]interface{}{"B", "D", "F"},
},
false,
},
{
`${setproduct(list(), list(), list())}`,
nil,
true,
},
{
`${setproduct(list("foo"),list("bar"))}`,
[]interface{}{
[]interface{}{"foo", "bar"},
},
false,
},
{
`${setproduct(list("foo"))}`,
nil,
true,
},
},
})
}