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

Function TestConfigAddVariableDecls

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

Source from the content-addressed store, hash-verified

404}
405
406func TestConfigAddVariableDecls(t *testing.T) {
407 tests := []struct {
408 name string
409 in *decls.VariableDecl
410 out *Variable
411 }{
412 {
413 name: "nil var decl",
414 },
415 {
416 name: "simple var decl",
417 in: decls.NewVariable("var", types.StringType),
418 out: NewVariable("var", NewTypeDesc("string")),
419 },
420 {
421 name: "parameterized var decl",
422 in: decls.NewVariable("var", types.NewListType(types.NewTypeParamType("T"))),
423 out: NewVariable("var", NewTypeDesc("list", NewTypeParam("T"))),
424 },
425 {
426 name: "opaque var decl",
427 in: decls.NewVariable("var", types.NewOpaqueType("bitvector")),
428 out: NewVariable("var", NewTypeDesc("bitvector")),
429 },
430 {
431 name: "proto var decl",
432 in: decls.NewVariable("var", types.NewObjectType("google.type.Expr")),
433 out: NewVariable("var", NewTypeDesc("google.type.Expr")),
434 },
435 {
436 name: "proto var decl with doc",
437 in: decls.NewVariableWithDoc("var", types.NewObjectType("google.type.Expr"), "API-friendly CEL expression type"),
438 out: NewVariableWithDoc("var", NewTypeDesc("google.type.Expr"), "API-friendly CEL expression type"),
439 },
440 }
441 for _, tst := range tests {
442 tc := tst
443 t.Run(tc.name, func(t *testing.T) {
444 conf := NewConfig(tc.name).AddVariableDecls(tc.in)
445 if len(conf.Variables) != 1 {
446 t.Fatalf("AddVariableDecls() did not add declaration to conf: %v", conf)
447 }
448 if !reflect.DeepEqual(conf.Variables[0], tc.out) {
449 t.Errorf("AddVariableDecls() added %v, wanted %v", conf.Variables, tc.out)
450 }
451 })
452 }
453}
454
455func TestConfigAddVariableDeclsEmpty(t *testing.T) {
456 if len(NewConfig("").AddVariables().Variables) != 0 {

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