From b625d4b90e3f0d229185dd0b16c293ccd917564c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sun, 18 Jun 2017 09:13:48 -0700 Subject: [PATCH] zclsyntax: test some more cases of unknowns in "for" --- zcl/zclsyntax/expression_test.go | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/zcl/zclsyntax/expression_test.go b/zcl/zclsyntax/expression_test.go index 7b00007..9766dc9 100644 --- a/zcl/zclsyntax/expression_test.go +++ b/zcl/zclsyntax/expression_test.go @@ -529,6 +529,22 @@ upper( }), 0, }, + { + `{for i, v in ["a", "b", "c", "b", "d"]: v => i... if i <= 2}`, + nil, + cty.ObjectVal(map[string]cty.Value{ + "a": cty.TupleVal([]cty.Value{ + cty.NumberIntVal(0), + }), + "b": cty.TupleVal([]cty.Value{ + cty.NumberIntVal(1), + }), + "c": cty.TupleVal([]cty.Value{ + cty.NumberIntVal(2), + }), + }), + 0, + }, { `{for i, v in ["a", "b", "c", "b", "d"]: v => i}`, nil, @@ -590,6 +606,39 @@ upper( cty.DynamicVal, 1, // can't iterate over a string (even if it's unknown) }, + { + `[for v in ["a", "b"]: v if unk]`, + &zcl.EvalContext{ + Variables: map[string]cty.Value{ + "unk": cty.UnknownVal(cty.Bool), + }, + }, + cty.DynamicVal, + 0, + }, + { + `[for v in ["a", "b"]: v if unk]`, + &zcl.EvalContext{ + Variables: map[string]cty.Value{ + "unk": cty.UnknownVal(cty.Number), + }, + }, + cty.DynamicVal, + 0, // if expression must be bool + }, + { + `[for v in ["a", "b"]: unk]`, + &zcl.EvalContext{ + Variables: map[string]cty.Value{ + "unk": cty.UnknownVal(cty.String), + }, + }, + cty.TupleVal([]cty.Value{ + cty.UnknownVal(cty.String), + cty.UnknownVal(cty.String), + }), + 0, + }, { `[{name: "Steve"}, {name: "Ermintrude"}].*.name`,