(t *testing.T)
| 459 | } |
| 460 | |
| 461 | func TestConfigAddFunctionDecls(t *testing.T) { |
| 462 | tests := []struct { |
| 463 | name string |
| 464 | in *decls.FunctionDecl |
| 465 | out *Function |
| 466 | }{ |
| 467 | { |
| 468 | name: "nil function decl", |
| 469 | }, |
| 470 | { |
| 471 | name: "global function decl", |
| 472 | in: mustNewFunction(t, "size", |
| 473 | decls.Overload("size_string", []*types.Type{types.StringType}, types.IntType), |
| 474 | ), |
| 475 | out: NewFunction("size", |
| 476 | NewOverload("size_string", []*TypeDesc{NewTypeDesc("string")}, NewTypeDesc("int")), |
| 477 | ), |
| 478 | }, |
| 479 | { |
| 480 | name: "global function decl - nullable arg", |
| 481 | in: mustNewFunction(t, "size", |
| 482 | decls.Overload("size_wrapper_string", []*types.Type{types.NewNullableType(types.StringType)}, types.IntType), |
| 483 | ), |
| 484 | out: NewFunction("size", |
| 485 | NewOverload("size_wrapper_string", []*TypeDesc{NewTypeDesc("google.protobuf.StringValue")}, NewTypeDesc("int")), |
| 486 | ), |
| 487 | }, |
| 488 | { |
| 489 | name: "member function decl - nullable arg", |
| 490 | in: mustNewFunction(t, "size", |
| 491 | decls.MemberOverload("list_size", []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), |
| 492 | decls.MemberOverload("string_size", []*types.Type{types.StringType}, types.IntType), |
| 493 | ), |
| 494 | out: NewFunction("size", |
| 495 | NewMemberOverload("list_size", NewTypeDesc("list", NewTypeParam("T")), []*TypeDesc{}, NewTypeDesc("int")), |
| 496 | NewMemberOverload("string_size", NewTypeDesc("string"), []*TypeDesc{}, NewTypeDesc("int")), |
| 497 | ), |
| 498 | }, |
| 499 | { |
| 500 | name: "global function decl - with doc", |
| 501 | in: mustNewFunction(t, "size", |
| 502 | decls.FunctionDocs("return the number of unicode code points", "in a string"), |
| 503 | decls.Overload("size_string", []*types.Type{types.StringType}, types.IntType, |
| 504 | decls.OverloadExamples(`'hello'.size() // 5`)), |
| 505 | ), |
| 506 | out: NewFunctionWithDoc("size", |
| 507 | "return the number of unicode code points\nin a string", |
| 508 | NewOverload("size_string", []*TypeDesc{NewTypeDesc("string")}, NewTypeDesc("int"), |
| 509 | `'hello'.size() // 5`), |
| 510 | ), |
| 511 | }, |
| 512 | } |
| 513 | for _, tst := range tests { |
| 514 | tc := tst |
| 515 | t.Run(tc.name, func(t *testing.T) { |
| 516 | conf := NewConfig(tc.name).AddFunctionDecls(tc.in) |
| 517 | if len(conf.Functions) != 1 { |
| 518 | t.Fatalf("AddFunctionDecls() did not add declaration to conf: %v", conf) |
nothing calls this directly
no test coverage detected