Skip to content

Commit 53ee54e

Browse files
committed
chore: add test from #665
1 parent 1cbb0d4 commit 53ee54e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

hclsyntax/expression_template_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,28 @@ trim`,
438438

439439
}
440440

441+
func TestTemplateExprGracefulValue(t *testing.T) {
442+
// we don't care about diags since we know it's invalid config
443+
expr, _ := ParseTemplate([]byte(`prefix${provider::}`), "", hcl.Pos{Line: 1, Column: 1, Byte: 0})
444+
445+
got, _ := expr.Value(nil) // this should not panic
446+
447+
if !got.RawEquals(cty.UnknownVal(cty.String).RefineNotNull()) {
448+
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, cty.UnknownVal(cty.String).RefineNotNull())
449+
}
450+
}
451+
452+
func TestTemplateExprWrappedGracefulValue(t *testing.T) {
453+
// we don't care about diags since we know it's invalid config
454+
expr, _ := ParseTemplate([]byte(`${provider::}`), "", hcl.Pos{Line: 1, Column: 1, Byte: 0})
455+
456+
got, _ := expr.Value(nil) // this should not panic
457+
458+
if !got.RawEquals(cty.DynamicVal) {
459+
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, cty.NilVal)
460+
}
461+
}
462+
441463
func TestTemplateExprIsStringLiteral(t *testing.T) {
442464
tests := map[string]bool{
443465
// A simple string value is a string literal

0 commit comments

Comments
 (0)