Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Mar 20, 2023
1 parent e692bb6 commit 66100c4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
67 changes: 67 additions & 0 deletions decoder/expr_type_declaration_completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
16 changes: 8 additions & 8 deletions decoder/hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
Expand All @@ -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},
Expand All @@ -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},
},
},
},
Expand All @@ -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},
Expand Down Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down

0 comments on commit 66100c4

Please sign in to comment.