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

Function TestAbsTraversalForExpr

traversal_for_expr_test.go:61–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestAbsTraversalForExpr(t *testing.T) {
62 tests := []struct {
63 Expr Expression
64 WantRootName string
65 }{
66 {
67 asTraversalSupported{RootName: "foo"},
68 "foo",
69 },
70 {
71 asTraversalNotSupported{},
72 "",
73 },
74 {
75 asTraversalDeclined{},
76 "",
77 },
78 {
79 asTraversalWrappedDelegated{
80 original: asTraversalSupported{RootName: "foo"},
81 },
82 "foo",
83 },
84 {
85 asTraversalWrappedDelegated{
86 original: asTraversalWrappedDelegated{
87 original: asTraversalSupported{RootName: "foo"},
88 },
89 },
90 "foo",
91 },
92 }
93
94 for _, test := range tests {
95 t.Run("", func(t *testing.T) {
96 got, diags := AbsTraversalForExpr(test.Expr)
97 switch {
98 case got != nil:
99 if test.WantRootName == "" {
100 t.Fatalf("traversal was returned; want error")
101 }
102 if len(got) != 1 {
103 t.Fatalf("wrong traversal length %d; want 1", len(got))
104 }
105 gotRoot, ok := got[0].(TraverseRoot)
106 if !ok {
107 t.Fatalf("first traversal step is %T; want hcl.TraverseRoot", got[0])
108 }
109 if gotRoot.Name != test.WantRootName {
110 t.Errorf("wrong root name %q; want %q", gotRoot.Name, test.WantRootName)
111 }
112 default:
113 if !diags.HasErrors() {
114 t.Errorf("returned nil traversal without error diagnostics")
115 }
116 if test.WantRootName != "" {
117 t.Errorf("traversal was not returned; want TraverseRoot(%q)", test.WantRootName)
118 }

Callers

nothing calls this directly

Calls 3

AbsTraversalForExprFunction · 0.85
RunMethod · 0.80
HasErrorsMethod · 0.80

Tested by

no test coverage detected