config: make formatlist work on lists of length 1

removes treat-lists-as-scalar special casing for formatlist

/cc @radeksimko

fixes #2240
This commit is contained in:
Paul Hinze 2015-06-25 18:45:17 -05:00
parent e88aeede9b
commit c95f21cec1
2 changed files with 6 additions and 21 deletions

View File

@ -138,16 +138,6 @@ func interpolationFuncFormatList() ast.Function {
parts := StringList(s).Slice() parts := StringList(s).Slice()
// 0 or 1 length lists are treated as scalars and repeated
switch len(parts) {
case 0:
varargs[i-1] = ""
continue
case 1:
varargs[i-1] = parts[0]
continue
}
// otherwise the list is sent down to be indexed // otherwise the list is sent down to be indexed
varargs[i-1] = parts varargs[i-1] = parts

View File

@ -190,23 +190,18 @@ func TestInterpolateFuncFormatList(t *testing.T) {
"A=1, B=2, C=3", "A=1, B=2, C=3",
false, false,
}, },
// formatlist of lists of length zero/one are repeated, just as scalars are
{
`${join(", ", formatlist("%s=%s", split(",", ""), split(",", "1,2,3")))}`,
"=1, =2, =3",
false,
},
{
`${join(", ", formatlist("%s=%s", split(",", "A"), split(",", "1,2,3")))}`,
"A=1, A=2, A=3",
false,
},
// Mismatched list lengths generate an error // Mismatched list lengths generate an error
{ {
`${formatlist("%s=%2s", split(",", "A,B,C,D"), split(",", "1,2,3"))}`, `${formatlist("%s=%2s", split(",", "A,B,C,D"), split(",", "1,2,3"))}`,
nil, nil,
true, true,
}, },
// Works with lists of length 1 [GH-2240]
{
`${formatlist("%s.id", split(",", "demo-rest-elb"))}`,
NewStringList([]string{"demo-rest-elb.id"}).String(),
false,
},
}, },
}) })
} }