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

Function TestConfigAddVariableDecls

common/env/env_test.go:448–510  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

446}
447
448func TestConfigAddVariableDecls(t *testing.T) {
449 tests := []struct {
450 name string
451 in *decls.VariableDecl
452 out *Variable
453 }{
454 {
455 name: "nil var decl",
456 },
457 {
458 name: "simple var decl",
459 in: decls.NewVariable("var", types.StringType),
460 out: NewVariable("var", NewTypeDesc("string")),
461 },
462 {
463 name: "parameterized var decl",
464 in: decls.NewVariable("var", types.NewListType(types.NewTypeParamType("T"))),
465 out: NewVariable("var", NewTypeDesc("list", NewTypeParam("T"))),
466 },
467 {
468 name: "opaque var decl",
469 in: decls.NewVariable("var", types.NewOpaqueType("bitvector")),
470 out: NewVariable("var", NewTypeDesc("bitvector")),
471 },
472 {
473 name: "proto var decl",
474 in: decls.NewVariable("var", types.NewObjectType("google.type.Expr")),
475 out: NewVariable("var", NewTypeDesc("google.type.Expr")),
476 },
477 {
478 name: "proto var decl with doc",
479 in: decls.NewVariableWithDoc("var", types.NewObjectType("google.type.Expr"), "API-friendly CEL expression type"),
480 out: NewVariableWithDoc("var", NewTypeDesc("google.type.Expr"), "API-friendly CEL expression type"),
481 },
482 {
483 name: "error var decl",
484 in: decls.NewVariable("var", types.ErrorType),
485 out: NewVariable("var", NewTypeDesc("*error*")),
486 },
487 {
488 name: "unknown var decl",
489 in: decls.NewVariable("var", types.UnknownType),
490 out: NewVariable("var", NewTypeDesc("*unknown*")),
491 },
492 {
493 name: "unspecified var decl",
494 in: decls.NewVariable("var", &types.Type{}),
495 out: NewVariable("var", NewTypeDesc("*unspecified type*")),
496 },
497 }
498 for _, tst := range tests {
499 tc := tst
500 t.Run(tc.name, func(t *testing.T) {
501 conf := NewConfig(tc.name).AddVariableDecls(tc.in)
502 if len(conf.Variables) != 1 {
503 t.Fatalf("AddVariableDecls() did not add declaration to conf: %v", conf)
504 }
505 if !reflect.DeepEqual(conf.Variables[0], tc.out) {

Callers

nothing calls this directly

Calls 12

NewVariableFunction · 0.92
NewListTypeFunction · 0.92
NewTypeParamTypeFunction · 0.92
NewOpaqueTypeFunction · 0.92
NewObjectTypeFunction · 0.92
NewVariableWithDocFunction · 0.92
NewTypeDescFunction · 0.85
NewTypeParamFunction · 0.85
NewConfigFunction · 0.85
AddVariableDeclsMethod · 0.80
NewVariableFunction · 0.70
NewVariableWithDocFunction · 0.70

Tested by

no test coverage detected