From 66100c43b0652ac1e51323795cd8441c4a125382 Mon Sep 17 00:00:00 2001 From: James Pogran Date: Mon, 20 Mar 2023 12:25:41 -0400 Subject: [PATCH] adding tests --- .../expr_type_declaration_completion_test.go | 67 +++++++++++++++++++ decoder/hover_test.go | 16 ++--- 2 files changed, 75 insertions(+), 8 deletions(-) diff --git a/decoder/expr_type_declaration_completion_test.go b/decoder/expr_type_declaration_completion_test.go index 7868a2bc..f3c57f43 100644 --- a/decoder/expr_type_declaration_completion_test.go +++ b/decoder/expr_type_declaration_completion_test.go @@ -176,6 +176,22 @@ func TestCompletionAtPos_exprTypeDeclaration(t *testing.T) { }, }), }, + { + "tuple inside brackets single-line", + map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.TypeDeclaration{}, + }, + }, + `attr = tuple([ ]) +`, + hcl.Pos{Line: 1, Column: 15, Byte: 14}, + lang.CompleteCandidates(allTypeDeclarationsAsCandidates("", hcl.Range{ + Filename: "test.tf", + Start: hcl.Pos{Line: 1, Column: 15, Byte: 14}, + End: hcl.Pos{Line: 1, Column: 15, Byte: 14}, + })), + }, { "inside tuple - second type after comma", map[string]*schema.AttributeSchema{ @@ -341,6 +357,57 @@ func TestCompletionAtPos_exprTypeDeclaration(t *testing.T) { }, }), }, + { + "single-line new element inside quoted key name with no equal sign", + map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.TypeDeclaration{}, + }, + }, + `attr = { "foo" } +`, + hcl.Pos{Line: 1, Column: 12, Byte: 11}, + lang.CompleteCandidates([]lang.Candidate{}), + }, + { + "single-line new element inside key name with no equal sign", + map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.TypeDeclaration{}, + }, + }, + `attr = { foo } +`, + hcl.Pos{Line: 1, Column: 11, Byte: 10}, + lang.CompleteCandidates([]lang.Candidate{}), + }, + { + "single-line new element value after equal sign", + map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.TypeDeclaration{}, + }, + }, + `attr = { foo = } +`, + hcl.Pos{Line: 1, Column: 16, Byte: 15}, + lang.CompleteCandidates([]lang.Candidate{ + { + Label: `kw`, + Detail: "keyword", + TextEdit: lang.TextEdit{ + Range: hcl.Range{ + Filename: "test.tf", + Start: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + NewText: `kw`, + Snippet: `kw`, + }, + Kind: lang.KeywordCandidateKind, + }, + }), + }, { "single-line object value", map[string]*schema.AttributeSchema{ diff --git a/decoder/hover_test.go b/decoder/hover_test.go index 3014f13d..415139e0 100644 --- a/decoder/hover_test.go +++ b/decoder/hover_test.go @@ -843,7 +843,7 @@ func TestDecoder_HoverAtPos_typeDeclaration(t *testing.T) { Body: &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ "type": { - Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}}, + Constraint: schema.TypeDeclaration{}, IsOptional: true, Description: lang.PlainText("Special attribute"), }, @@ -868,7 +868,7 @@ func TestDecoder_HoverAtPos_typeDeclaration(t *testing.T) { } `, &lang.HoverData{ - Content: lang.Markdown("Type declaration"), + Content: lang.Markdown("_string_"), Range: hcl.Range{ Filename: "test.tf", Start: hcl.Pos{Line: 2, Column: 10, Byte: 27}, @@ -883,11 +883,11 @@ func TestDecoder_HoverAtPos_typeDeclaration(t *testing.T) { } `, &lang.HoverData{ - Content: lang.Markdown("Type declaration"), + Content: lang.Markdown("_string_"), Range: hcl.Range{ Filename: "test.tf", - Start: hcl.Pos{Line: 2, Column: 10, Byte: 27}, - End: hcl.Pos{Line: 2, Column: 22, Byte: 39}, + Start: hcl.Pos{Line: 2, Column: 15, Byte: 32}, + End: hcl.Pos{Line: 2, Column: 21, Byte: 38}, }, }, }, @@ -900,7 +900,7 @@ func TestDecoder_HoverAtPos_typeDeclaration(t *testing.T) { } `, &lang.HoverData{ - Content: lang.Markdown("Type declaration"), + Content: lang.Markdown("```\n{\n vegan = bool\n}\n```\n_object_"), Range: hcl.Range{ Filename: "test.tf", Start: hcl.Pos{Line: 2, Column: 10, Byte: 27}, @@ -1664,7 +1664,7 @@ func TestDecoder_HoverAtPos_extensions_references(t *testing.T) { Body: &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ "type": { - Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}}, + Constraint: schema.TypeDeclaration{}, IsOptional: true, }, }, @@ -1734,7 +1734,7 @@ variable "name" { Body: &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ "type": { - Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}}, + Constraint: schema.TypeDeclaration{}, IsOptional: true, }, },