Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpogran committed Mar 16, 2023
1 parent bd28b85 commit f38d132
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 37 deletions.
28 changes: 28 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,18 @@ 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 object value",
map[string]*schema.AttributeSchema{
Expand Down
48 changes: 25 additions & 23 deletions decoder/expression_candidates_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,9 +1193,7 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
"type declaration",
map[string]*schema.AttributeSchema{
"attr": {
Expr: schema.ExprConstraints{
schema.TypeDeclarationExpr{},
},
Constraint: schema.TypeDeclaration{},
},
},
`attr =
Expand All @@ -1219,7 +1217,7 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "bool", Snippet: "bool"},
Kind: lang.AttributeCandidateKind,
Kind: lang.BoolCandidateKind,
},
{
Label: "number",
Expand All @@ -1237,7 +1235,7 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "number", Snippet: "number"},
Kind: lang.AttributeCandidateKind,
Kind: lang.NumberCandidateKind,
},
{
Label: "string",
Expand All @@ -1255,11 +1253,11 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "string", Snippet: "string"},
Kind: lang.AttributeCandidateKind,
Kind: lang.StringCandidateKind,
},
{
Label: "list()",
Detail: "list()",
Label: "list()",
Detail: "list",
TextEdit: lang.TextEdit{Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Expand All @@ -1273,11 +1271,12 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "list()", Snippet: "list(${0})"},
Kind: lang.AttributeCandidateKind,
Kind: lang.ListCandidateKind,
TriggerSuggest: true,
},
{
Label: "set()",
Detail: "set()",
Label: "set()",
Detail: "set",
TextEdit: lang.TextEdit{Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Expand All @@ -1291,11 +1290,12 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "set()", Snippet: "set(${0})"},
Kind: lang.AttributeCandidateKind,
Kind: lang.SetCandidateKind,
TriggerSuggest: true,
},
{
Label: "tuple()",
Detail: "tuple()",
Label: "tuple([…])",
Detail: "tuple",
TextEdit: lang.TextEdit{Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Expand All @@ -1308,12 +1308,13 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Column: 8,
Byte: 7,
},
}, NewText: "tuple()", Snippet: "tuple(${0})"},
Kind: lang.AttributeCandidateKind,
}, NewText: "tuple([])", Snippet: "tuple([ ${0} ])"},
Kind: lang.TupleCandidateKind,
TriggerSuggest: true,
},
{
Label: "map()",
Detail: "map()",
Label: "map()",
Detail: "map",
TextEdit: lang.TextEdit{Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Expand All @@ -1327,11 +1328,12 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Byte: 7,
},
}, NewText: "map()", Snippet: "map(${0})"},
Kind: lang.AttributeCandidateKind,
Kind: lang.MapCandidateKind,
TriggerSuggest: true,
},
{
Label: "object({})",
Detail: "object({})",
Label: "object({})",
Detail: "object",
TextEdit: lang.TextEdit{Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Expand All @@ -1344,8 +1346,8 @@ func TestLegacyDecoder_CandidateAtPos_expressions(t *testing.T) {
Column: 8,
Byte: 7,
},
}, NewText: "object({})", Snippet: "object({\n ${1:name} = ${2}\n})"},
Kind: lang.AttributeCandidateKind,
}, NewText: "object({\n\n})", Snippet: "object({\n ${1:name} = ${2}\n})"},
Kind: lang.ObjectCandidateKind,
},
}),
},
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
12 changes: 6 additions & 6 deletions decoder/semantic_tokens_expr_legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"known primitive type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = string`,
Expand Down Expand Up @@ -2135,7 +2135,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"unknown primitive type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = foobar`,
Expand Down Expand Up @@ -2163,7 +2163,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"known collection type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = list(any)`,
Expand Down Expand Up @@ -2225,7 +2225,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"unknown collection type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = foobar(any)`,
Expand Down Expand Up @@ -2253,7 +2253,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"known object type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = object({
Expand Down Expand Up @@ -2334,7 +2334,7 @@ func TestLegacyDecoder_SemanticTokensInFile_typeDeclaration(t *testing.T) {
"unknown object type",
map[string]*schema.AttributeSchema{
"type": {
Expr: schema.ExprConstraints{schema.TypeDeclarationExpr{}},
Constraint: schema.TypeDeclaration{},
},
},
`type = foobar({
Expand Down

0 comments on commit f38d132

Please sign in to comment.