MCPcopy
hub / github.com/hashicorp/hcl / TestWalk

Function TestWalk

hclsyntax/walk_test.go:17–160  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestWalk(t *testing.T) {
18
19 tests := []struct {
20 src string
21 want []testWalkCall
22 }{
23 {
24 `1`,
25 []testWalkCall{
26 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
27 {testWalkExit, "*hclsyntax.LiteralValueExpr"},
28 },
29 },
30 {
31 `foo`,
32 []testWalkCall{
33 {testWalkEnter, "*hclsyntax.ScopeTraversalExpr"},
34 {testWalkExit, "*hclsyntax.ScopeTraversalExpr"},
35 },
36 },
37 {
38 `1 + 1`,
39 []testWalkCall{
40 {testWalkEnter, "*hclsyntax.BinaryOpExpr"},
41 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
42 {testWalkExit, "*hclsyntax.LiteralValueExpr"},
43 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
44 {testWalkExit, "*hclsyntax.LiteralValueExpr"},
45 {testWalkExit, "*hclsyntax.BinaryOpExpr"},
46 },
47 },
48 {
49 `(1 + 1)`,
50 []testWalkCall{
51 {testWalkEnter, "*hclsyntax.ParenthesesExpr"},
52 {testWalkEnter, "*hclsyntax.BinaryOpExpr"},
53 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
54 {testWalkExit, "*hclsyntax.LiteralValueExpr"},
55 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
56 {testWalkExit, "*hclsyntax.LiteralValueExpr"},
57 {testWalkExit, "*hclsyntax.BinaryOpExpr"},
58 {testWalkExit, "*hclsyntax.ParenthesesExpr"},
59 },
60 },
61 {
62 `a[0]`,
63 []testWalkCall{
64 // because the index is constant here, the index is absorbed into the traversal
65 {testWalkEnter, "*hclsyntax.ScopeTraversalExpr"},
66 {testWalkExit, "*hclsyntax.ScopeTraversalExpr"},
67 },
68 },
69 {
70 `0[foo]`, // semantically incorrect, but should still parse and be walkable
71 []testWalkCall{
72 {testWalkEnter, "*hclsyntax.IndexExpr"},
73 {testWalkEnter, "*hclsyntax.LiteralValueExpr"},
74 {testWalkExit, "*hclsyntax.LiteralValueExpr"},

Callers

nothing calls this directly

Calls 6

WalkFunction · 0.85
RunMethod · 0.80
HasErrorsMethod · 0.80
EqualMethod · 0.80
ParseExpressionFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected