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