Skip to content

Commit 64a478c

Browse files
committed
decoder: add test for dep schema & make it pass
1 parent bab293a commit 64a478c

File tree

2 files changed

+261
-39
lines changed

2 files changed

+261
-39
lines changed

decoder/semantic_tokens.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package decoder
22

33
import (
44
"context"
5-
"log"
65
"sort"
76

87
"github.com/zclconf/go-cty/cty"
@@ -48,20 +47,17 @@ func (d *PathDecoder) tokensForBody(ctx context.Context, body *hclsyntax.Body, b
4847
return tokens
4948
}
5049

50+
// TODO: test for count extension used in root BodySchema
5151
if bodySchema.Extensions != nil {
52-
ctx = icontext.WithExtensions(ctx, bodySchema.Extensions)
5352
if bodySchema.Extensions.Count {
5453
if _, ok := body.Attributes["count"]; ok {
5554
// append to context we need count provided
5655
ctx = icontext.WithActiveCount(ctx)
57-
log.Printf("Found Expression: ")
5856
}
5957
}
6058
}
6159

6260
for name, attr := range body.Attributes {
63-
64-
log.Printf("Found: %q / %v+", name, bodySchema.Extensions)
6561
attrSchema, ok := bodySchema.Attributes[name]
6662
if !ok {
6763
if bodySchema.Extensions != nil && name == "count" && bodySchema.Extensions.Count {
@@ -93,8 +89,6 @@ func (d *PathDecoder) tokensForBody(ctx context.Context, body *hclsyntax.Body, b
9389
})
9490

9591
ec := ExprConstraints(attrSchema.Expr)
96-
countAvailable := icontext.ActiveCountFromContext(ctx)
97-
log.Printf("Found Expression: countAvailable %t", countAvailable)
9892
tokens = append(tokens, d.tokensForExpression(ctx, attr.Expr, ec)...)
9993
}
10094

@@ -136,6 +130,15 @@ func (d *PathDecoder) tokensForBody(ctx context.Context, body *hclsyntax.Body, b
136130
}
137131

138132
if block.Body != nil {
133+
// TODO: Test for count.index in a sub-block
134+
if blockSchema.Body != nil && blockSchema.Body.Extensions != nil {
135+
if blockSchema.Body.Extensions.Count {
136+
if _, ok := block.Body.Attributes["count"]; ok {
137+
// append to context we need count provided
138+
ctx = icontext.WithActiveCount(ctx)
139+
}
140+
}
141+
}
139142
tokens = append(tokens, d.tokensForBody(ctx, block.Body, blockSchema.Body, blockModifiers)...)
140143
}
141144

@@ -176,7 +179,6 @@ func (d *PathDecoder) tokensForExpression(ctx context.Context, expr hclsyntax.Ex
176179
}
177180
countAvailable := icontext.ActiveCountFromContext(ctx)
178181
// TODO why is countAvailable not true here?
179-
log.Printf("Found Expression: %t / %t - %v+", countAvailable, address.Equals(countIndexAttr), address)
180182
// if address.Equals(countIndexAttr) && countAvailable {
181183
if address.Equals(countIndexAttr) && countAvailable {
182184
traversal := eType.AsTraversal()

0 commit comments

Comments
 (0)