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

Function TestEnvFromConfig

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

Source from the content-addressed store, hash-verified

471}
472
473func TestEnvFromConfig(t *testing.T) {
474 type exprCase struct {
475 name string
476 in any
477 expr string
478 iss error
479 out ref.Val
480 }
481 tests := []struct {
482 name string
483 beforeOpts []EnvOption
484 afterOpts []EnvOption
485 conf *env.Config
486 confHandlers []ConfigOptionFactory
487 exprs []exprCase
488 }{
489 {
490 name: "std env",
491 conf: env.NewConfig("std env"),
492 exprs: []exprCase{
493 {
494 name: "literal",
495 expr: "'hello world'",
496 out: types.String("hello world"),
497 },
498 {
499 name: "size",
500 expr: "'hello world'.size()",
501 out: types.Int(11),
502 },
503 },
504 },
505 {
506 name: "std env - imports",
507 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
508 conf: env.NewConfig("std env - imports").
509 AddImports(env.NewImport("google.expr.proto3.test.TestAllTypes")),
510 exprs: []exprCase{
511 {
512 name: "literal",
513 expr: "TestAllTypes{single_int64: 15}.single_int64",
514 out: types.Int(15),
515 },
516 },
517 },
518 {
519 name: "std env - context proto",
520 beforeOpts: []EnvOption{Types(&proto3pb.TestAllTypes{})},
521 conf: env.NewConfig("std env - context proto").
522 SetContainer("google.expr.proto3.test").
523 SetContextVariable(env.NewContextVariable("google.expr.proto3.test.TestAllTypes")),
524 exprs: []exprCase{
525 {
526 name: "field select literal",
527 in: mustContextProto(t, &proto3pb.TestAllTypes{SingleInt64: 10}),
528 expr: "TestAllTypes{single_int64: single_int64}.single_int64",
529 out: types.Int(10),
530 },

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