From 53ee54e0da34370e928b8cf6d72f8d25f24e6ee4 Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Tue, 12 Mar 2024 09:37:20 +0100 Subject: [PATCH] chore: add test from #665 --- hclsyntax/expression_template_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hclsyntax/expression_template_test.go b/hclsyntax/expression_template_test.go index c78094f5..aa33c9d9 100644 --- a/hclsyntax/expression_template_test.go +++ b/hclsyntax/expression_template_test.go @@ -438,6 +438,28 @@ trim`, } +func TestTemplateExprGracefulValue(t *testing.T) { + // we don't care about diags since we know it's invalid config + expr, _ := ParseTemplate([]byte(`prefix${provider::}`), "", hcl.Pos{Line: 1, Column: 1, Byte: 0}) + + got, _ := expr.Value(nil) // this should not panic + + if !got.RawEquals(cty.UnknownVal(cty.String).RefineNotNull()) { + t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, cty.UnknownVal(cty.String).RefineNotNull()) + } +} + +func TestTemplateExprWrappedGracefulValue(t *testing.T) { + // we don't care about diags since we know it's invalid config + expr, _ := ParseTemplate([]byte(`${provider::}`), "", hcl.Pos{Line: 1, Column: 1, Byte: 0}) + + got, _ := expr.Value(nil) // this should not panic + + if !got.RawEquals(cty.DynamicVal) { + t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, cty.NilVal) + } +} + func TestTemplateExprIsStringLiteral(t *testing.T) { tests := map[string]bool{ // A simple string value is a string literal