(t *testing.T)
| 404 | } |
| 405 | |
| 406 | func 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 | |
| 455 | func TestConfigAddVariableDeclsEmpty(t *testing.T) { |
| 456 | if len(NewConfig("").AddVariables().Variables) != 0 { |
nothing calls this directly
no test coverage detected