MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestAstToStringWithOptions

Function TestAstToStringWithOptions

cel/io_test.go:151–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

149}
150
151func TestAstToStringWithOptions(t *testing.T) {
152 stdEnv, err := NewEnv(
153 OptionalTypes(),
154 EnableMacroCallTracking(),
155 )
156 if err != nil {
157 t.Fatalf("NewEnv() failed: %v", err)
158 }
159 in := "a.`b-c` && (x || y)"
160 ast, iss := stdEnv.Parse(in)
161 if iss.Err() != nil {
162 t.Fatalf("stdEnv.Parse(%q) failed: %v", in, iss.Err())
163 }
164 // Default: no backtick escaping
165 exprDefault, err := AstToString(ast)
166 if err != nil {
167 t.Fatalf("AstToString(ast) failed: %v", err)
168 }
169 if exprDefault != "a.b-c && (x || y)" {
170 t.Errorf("got %q, wanted %q", exprDefault, "a.b-c && (x || y)")
171 }
172
173 // Opt-in: backtick escaping
174 exprEscaped, err := AstToString(ast, FormatEscapeIdentifiers(true))
175 if err != nil {
176 t.Fatalf("AstToString(ast) failed: %v", err)
177 }
178 if exprEscaped != in {
179 t.Errorf("got %q, wanted %q", exprEscaped, in)
180 }
181
182 // Word wrap
183 exprWrapped, err := AstToString(ast, FormatWrapOnColumn(5))
184 if err != nil {
185 t.Fatalf("AstToString(ast) failed: %v", err)
186 }
187 if exprWrapped != "a.b-c &&\n(x ||\ny)" {
188 t.Errorf("got %q, wanted %q", exprWrapped, "a.b-c &&\n(x ||\ny)")
189 }
190}
191
192func TestExprToString(t *testing.T) {
193 stdEnv, err := NewEnv(EnableMacroCallTracking())

Callers

nothing calls this directly

Calls 8

ParseMethod · 0.95
OptionalTypesFunction · 0.85
EnableMacroCallTrackingFunction · 0.85
AstToStringFunction · 0.85
FormatEscapeIdentifiersFunction · 0.85
FormatWrapOnColumnFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70

Tested by

no test coverage detected