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

decoder: Fix collection of implied declared targets of complex types #259

Merged
merged 2 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions decoder/expr_list_ref_targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,73 @@ func TestCollectRefTargets_exprList_implied_hcl(t *testing.T) {
},
},
},
{
"declared as type",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
Constraint: schema.List{
Elem: schema.LiteralType{Type: cty.Bool},
},
IsOptional: true,
},
},
},
},
},
},
`blk { attr = [] }`,
reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
End: hcl.Pos{Line: 1, Column: 18, Byte: 17},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
End: hcl.Pos{Line: 1, Column: 4, Byte: 3},
},
Type: cty.Object(map[string]cty.Type{
"attr": cty.List(cty.Bool),
}),
NestedTargets: reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
lang.AttrStep{Name: "attr"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
End: hcl.Pos{Line: 1, Column: 16, Byte: 15},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
End: hcl.Pos{Line: 1, Column: 11, Byte: 10},
},
Type: cty.List(cty.Bool),
NestedTargets: reference.Targets{},
},
},
},
},
},
{
"undeclared as reference",
&schema.BodySchema{
Expand Down Expand Up @@ -1013,6 +1080,73 @@ func TestCollectRefTargets_exprList_implied_json(t *testing.T) {
},
},
},
{
"declared as type",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
Constraint: schema.List{
Elem: schema.LiteralType{Type: cty.Bool},
},
IsOptional: true,
},
},
},
},
},
},
`{"blk": {"attr": []}}`,
reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 9, Byte: 8},
End: hcl.Pos{Line: 1, Column: 21, Byte: 20},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 9, Byte: 8},
End: hcl.Pos{Line: 1, Column: 10, Byte: 9},
},
Type: cty.Object(map[string]cty.Type{
"attr": cty.List(cty.Bool),
}),
NestedTargets: reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
lang.AttrStep{Name: "attr"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 10, Byte: 9},
End: hcl.Pos{Line: 1, Column: 20, Byte: 19},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 10, Byte: 9},
End: hcl.Pos{Line: 1, Column: 16, Byte: 15},
},
Type: cty.List(cty.Bool),
NestedTargets: reference.Targets{},
},
},
},
},
},
{
"undeclared as reference",
&schema.BodySchema{
Expand Down
134 changes: 134 additions & 0 deletions decoder/expr_map_ref_targets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,73 @@ func TestCollectRefTargets_exprMap_implied_hcl(t *testing.T) {
},
},
},
{
"declared as type",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
Constraint: schema.Map{
Elem: schema.LiteralType{Type: cty.Bool},
},
IsOptional: true,
},
},
},
},
},
},
`blk { attr = {} }`,
reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
End: hcl.Pos{Line: 1, Column: 18, Byte: 17},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
End: hcl.Pos{Line: 1, Column: 4, Byte: 3},
},
Type: cty.Object(map[string]cty.Type{
"attr": cty.Map(cty.Bool),
}),
NestedTargets: reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
lang.AttrStep{Name: "attr"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
End: hcl.Pos{Line: 1, Column: 16, Byte: 15},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl",
Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
End: hcl.Pos{Line: 1, Column: 11, Byte: 10},
},
Type: cty.Map(cty.Bool),
NestedTargets: reference.Targets{},
},
},
},
},
},
{
"undeclared as reference",
&schema.BodySchema{
Expand Down Expand Up @@ -1284,6 +1351,73 @@ func TestCollectRefTargets_exprMap_implied_json(t *testing.T) {
},
},
},
{
"declared as type",
&schema.BodySchema{
Blocks: map[string]*schema.BlockSchema{
"blk": {
Address: &schema.BlockAddrSchema{
Steps: schema.Address{
schema.StaticStep{Name: "blk"},
},
BodyAsData: true,
InferBody: true,
},
Body: &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"attr": {
Constraint: schema.Map{
Elem: schema.LiteralType{Type: cty.Bool},
},
IsOptional: true,
},
},
},
},
},
},
`{"blk": {"attr": {}}}`,
reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 9, Byte: 8},
End: hcl.Pos{Line: 1, Column: 21, Byte: 20},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 9, Byte: 8},
End: hcl.Pos{Line: 1, Column: 10, Byte: 9},
},
Type: cty.Object(map[string]cty.Type{
"attr": cty.Map(cty.Bool),
}),
NestedTargets: reference.Targets{
{
Addr: lang.Address{
lang.RootStep{Name: "blk"},
lang.AttrStep{Name: "attr"},
},
RangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 10, Byte: 9},
End: hcl.Pos{Line: 1, Column: 20, Byte: 19},
},
DefRangePtr: &hcl.Range{
Filename: "test.hcl.json",
Start: hcl.Pos{Line: 1, Column: 10, Byte: 9},
End: hcl.Pos{Line: 1, Column: 16, Byte: 15},
},
Type: cty.Map(cty.Bool),
NestedTargets: reference.Targets{},
},
},
},
},
},
{
"undeclared as reference",
&schema.BodySchema{
Expand Down
Loading