Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test case for panics for invalid namespaced function expressions #383

Merged
merged 6 commits into from
Apr 5, 2024
Prev Previous commit
Next Next commit
test: add test case for semantic tokens for panics for invalid namesp…
…aced function expressions
  • Loading branch information
ansgarm authored and dbanck committed Mar 26, 2024
commit 8b51bb7dcfc0ef880072f9bef70dfe8c898081cb
48 changes: 48 additions & 0 deletions decoder/semantic_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,54 @@ resource "vault_auth_backend" "blah" {
}
}

func TestDecoder_SemanticTokensInFile_nil_expr(t *testing.T) {
// provider:: is not a traversal expression, so hcl will return a ExprSyntaxError which needs to be handled
f, _ := hclsyntax.ParseConfig([]byte(`attr = provider::`), "test.tf", hcl.InitialPos)

d := testPathDecoder(t, &PathContext{
Schema: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {Constraint: schema.AnyExpression{OfType: cty.DynamicPseudoType}},
},
},
Files: map[string]*hcl.File{
"test.tf": f,
},
})

ctx := context.Background()

tokens, err := d.SemanticTokensInFile(ctx, "test.tf")
if err != nil {
t.Fatal(err)
}

expectedTokens := []lang.SemanticToken{
{
Type: "hcl-attrName",
Modifiers: lang.SemanticTokenModifiers{},
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Line: 1,
Column: 1,
Byte: 0,
},
End: hcl.Pos{
Line: 1,
Column: 5,
Byte: 4,
},
},
},
}

diff := cmp.Diff(expectedTokens, tokens)
if diff != "" {
t.Fatalf("unexpected tokens: %s", diff)
}
}

func TestDecoder_SemanticTokensInFile_dependentSchema(t *testing.T) {
bodySchema := &schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
Expand Down