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

Function TestFunctionDocumentation

common/decls/decls_test.go:271–387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestFunctionDocumentation(t *testing.T) {
272 tests := []struct {
273 name string
274 fn *FunctionDecl
275 signatures []string
276 examples []string
277 }{
278 {
279 name: "function",
280 fn: testFunction(t, "size",
281 FunctionDocs(`compute the number of entries in a list or map`),
282 MemberOverload("list_size",
283 []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType,
284 OverloadExamples(`[].size() // 0`, `[1, 2, 3].size() // 3`)),
285 Overload("size_list",
286 []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType,
287 OverloadExamples(`size([]) // 0`, `size([1, 2, 3]) // 3`))),
288 signatures: []string{
289 "list(<T>).size() -> int",
290 "size(list(<T>)) -> int",
291 },
292 examples: []string{
293 `[].size() // 0`,
294 `[1, 2, 3].size() // 3`,
295 `size([]) // 0`,
296 `size([1, 2, 3]) // 3`,
297 },
298 },
299 {
300 name: "type",
301 fn: testFunction(t, overloads.TypeConvertType,
302 Overload(overloads.TypeConvertType,
303 []*types.Type{types.NewTypeTypeWithParam(types.NewTypeParamType("T"))},
304 types.TypeType,
305 OverloadExamples(`type(int) // type`))),
306 signatures: []string{"type(type) -> type"},
307 examples: []string{`type(int) // type`},
308 },
309 {
310 name: "unary operator",
311 fn: testFunction(t, operators.Negate,
312 FunctionDocs(`negate a numeric value`),
313 Overload(overloads.NegateInt64, []*types.Type{types.IntType}, types.IntType,
314 OverloadExamples(`-(1) // -1`))),
315 signatures: []string{"-int -> int"},
316 examples: []string{`-(1) // -1`},
317 },
318 {
319 name: "binary operator",
320 fn: testFunction(t, operators.Add,
321 FunctionDocs(`add two numeric values`),
322 Overload(overloads.AddInt64, []*types.Type{types.IntType, types.IntType}, types.IntType,
323 OverloadExamples(`1 + 2 // 3`))),
324 signatures: []string{"int + int -> int"},
325 examples: []string{`1 + 2 // 3`},
326 },
327 {
328 name: "index operator",

Callers

nothing calls this directly

Calls 12

NewListTypeFunction · 0.92
NewTypeParamTypeFunction · 0.92
NewTypeTypeWithParamFunction · 0.92
OverloadDeclsMethod · 0.80
testFunctionFunction · 0.70
FunctionDocsFunction · 0.70
MemberOverloadFunction · 0.70
OverloadExamplesFunction · 0.70
OverloadFunction · 0.70
DocumentationMethod · 0.65
DescriptionMethod · 0.65
ContainsMethod · 0.65

Tested by

no test coverage detected