(t *testing.T)
| 316 | } |
| 317 | |
| 318 | func TestInliningOptimizer(t *testing.T) { |
| 319 | type varExpr struct { |
| 320 | name string |
| 321 | alias string |
| 322 | t *cel.Type |
| 323 | expr string |
| 324 | } |
| 325 | tests := []struct { |
| 326 | expr string |
| 327 | vars []varExpr |
| 328 | inlined string |
| 329 | folded string |
| 330 | }{ |
| 331 | { |
| 332 | expr: `a || b`, |
| 333 | vars: []varExpr{ |
| 334 | { |
| 335 | name: "a", |
| 336 | t: cel.BoolType, |
| 337 | }, |
| 338 | { |
| 339 | name: "b", |
| 340 | alias: "bravo", |
| 341 | t: cel.BoolType, |
| 342 | expr: `'hello'.contains('lo')`, |
| 343 | }, |
| 344 | }, |
| 345 | inlined: `a || "hello".contains("lo")`, |
| 346 | folded: `true`, |
| 347 | }, |
| 348 | { |
| 349 | expr: `a + [a]`, |
| 350 | vars: []varExpr{ |
| 351 | { |
| 352 | name: "a", |
| 353 | alias: "alpha", |
| 354 | t: cel.DynType, |
| 355 | expr: `dyn([1, 2])`, |
| 356 | }, |
| 357 | }, |
| 358 | inlined: `cel.bind(alpha, dyn([1, 2]), alpha + [alpha])`, |
| 359 | folded: `[1, 2, [1, 2]]`, |
| 360 | }, |
| 361 | { |
| 362 | expr: `a && (a || b)`, |
| 363 | vars: []varExpr{ |
| 364 | { |
| 365 | name: "a", |
| 366 | alias: "alpha", |
| 367 | t: cel.BoolType, |
| 368 | expr: `'hello'.contains('lo')`, |
| 369 | }, |
| 370 | { |
| 371 | name: "b", |
| 372 | t: cel.BoolType, |
| 373 | }, |
| 374 | }, |
| 375 | inlined: `cel.bind(alpha, "hello".contains("lo"), alpha && (alpha || b))`, |
nothing calls this directly
no test coverage detected