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

Function TestCheck

checker/checker_test.go:2512–2627  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2510}
2511
2512func TestCheck(t *testing.T) {
2513 p, err := parser.NewParser(
2514 parser.Macros(parser.AllMacros...),
2515 )
2516 if err != nil {
2517 t.Fatalf("parser.NewParser() failed: %v", err)
2518 }
2519
2520 for i, tst := range testCases(t) {
2521 name := fmt.Sprintf("%d %s", i, tst.in)
2522 tc := tst
2523 t.Run(name, func(t *testing.T) {
2524 tcParser := p
2525 if tc.env.optionalSyntax || tc.env.variadicASTs {
2526 tcParser, err = parser.NewParser(
2527 parser.Macros(parser.AllMacros...),
2528 parser.EnableOptionalSyntax(tc.env.optionalSyntax),
2529 parser.EnableVariadicOperatorASTs(tc.env.variadicASTs),
2530 )
2531 if err != nil {
2532 t.Fatalf("parser.NewParser() failed: %v", err)
2533 }
2534 }
2535 // Runs the tests in parallel to ensure that there are no data races
2536 // due to shared mutable state across tests.
2537 t.Parallel()
2538
2539 src := common.NewTextSource(tc.in)
2540 pAst, errors := tcParser.Parse(src)
2541 if len(errors.GetErrors()) > 0 {
2542 t.Fatalf("Unexpected parse errors: %v", errors.ToDisplayString())
2543 }
2544
2545 reg, err := types.NewRegistry(
2546 types.JSONFieldNames(tc.env.jsonFieldNames),
2547 types.ProtoTypeDefs(&proto2pb.TestAllTypes{}, &proto3pb.TestAllTypes{}),
2548 )
2549 if err != nil {
2550 t.Fatalf("types.NewRegistry() failed: %v", err)
2551 }
2552 if tc.env.optionalSyntax {
2553 if err := reg.RegisterType(types.OptionalType); err != nil {
2554 t.Fatalf("reg.RegisterType(optional_type) failed: %v", err)
2555 }
2556 }
2557 cont, err := containers.NewContainer(containers.Name(tc.container))
2558 if err != nil {
2559 t.Fatalf("containers.NewContainer() failed: %v", err)
2560 }
2561 opts := []Option{CrossTypeNumericComparisons(true)}
2562 if len(tc.opts) != 0 {
2563 opts = tc.opts
2564 }
2565 if tc.env.jsonFieldNames {
2566 opts = append(opts, JSONFieldNames(true))
2567 }
2568 env, err := NewEnv(cont, reg, opts...)
2569 if err != nil {

Callers

nothing calls this directly

Calls 15

RegisterTypeMethod · 0.95
AddFunctionsMethod · 0.95
AddIdentsMethod · 0.95
NewParserFunction · 0.92
MacrosFunction · 0.92
EnableOptionalSyntaxFunction · 0.92
NewTextSourceFunction · 0.92
NewRegistryFunction · 0.92
JSONFieldNamesFunction · 0.92
ProtoTypeDefsFunction · 0.92
NewContainerFunction · 0.92

Tested by

no test coverage detected