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

Function TestEnvFromConfig

cel/env_test.go:614–1102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

612}
613
614func TestEnvFromConfig(t *testing.T) {
615 type exprCase struct {
616 name string
617 in any
618 expr string
619 iss error
620 out ref.Val
621 }
622 tests := []struct {
623 name string
624 beforeOpts []EnvOption
625 afterOpts []EnvOption
626 conf *env.Config
627 confHandlers []ConfigOptionFactory
628 exprs []exprCase
629 }{
630 {
631 name: "std env",
632 conf: env.NewConfig("std env"),
633 exprs: []exprCase{
634 {
635 name: "literal",
636 expr: "'hello world'",
637 out: types.String("hello world"),
638 },
639 {
640 name: "size",
641 expr: "'hello world'.size()",
642 out: types.Int(11),
643 },
644 },
645 },
646 {
647 name: "std env - imports",
648 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
649 conf: env.NewConfig("std env - imports").
650 AddImports(env.NewImport("google.expr.proto3.test.TestAllTypes")),
651 exprs: []exprCase{
652 {
653 name: "literal",
654 expr: "TestAllTypes{single_int64: 15}.single_int64",
655 out: types.Int(15),
656 },
657 },
658 },
659 {
660 name: "std env - context proto",
661 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
662 conf: env.NewConfig("std env - context proto").
663 SetContainer("google.expr.proto3.test").
664 SetContextVariable(env.NewContextVariable("google.expr.proto3.test.TestAllTypes")),
665 exprs: []exprCase{
666 {
667 name: "field select literal",
668 in: mustContextProto(t, &proto3pb.TestAllTypes{SingleInt64: 10}),
669 expr: "TestAllTypes{single_int64: single_int64}.single_int64",
670 out: types.Int(10),
671 },

Callers

nothing calls this directly

Calls 15

CELTypeProviderMethod · 0.95
CompileMethod · 0.95
ProgramMethod · 0.95
NewConfigFunction · 0.92
StringTypeAlias · 0.92
IntTypeAlias · 0.92
NewImportFunction · 0.92
NewContextVariableFunction · 0.92
NewFeatureFunction · 0.92
JSONFieldNamesFunction · 0.92
NewVariableFunction · 0.92
NewTypeDescFunction · 0.92

Tested by

no test coverage detected