(t *testing.T)
| 406 | } |
| 407 | |
| 408 | func TestEvalApplyFn(t *testing.T) { |
| 409 | tests := []struct { |
| 410 | name string |
| 411 | expr ast.ApplyFn |
| 412 | want ast.Constant |
| 413 | }{ |
| 414 | { |
| 415 | name: "construct a pair", |
| 416 | expr: ast.ApplyFn{symbols.Pair, []ast.BaseTerm{ast.String("hello"), ast.Number(2)}}, |
| 417 | want: *pair(ast.String("hello"), ast.Number(2)), |
| 418 | }, |
| 419 | { |
| 420 | name: "construct a tuple, case pair", |
| 421 | expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello"), ast.Number(2)}}, |
| 422 | want: *pair(ast.String("hello"), ast.Number(2)), |
| 423 | }, |
| 424 | { |
| 425 | name: "construct a tuple, case single-element tuple", |
| 426 | expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello")}}, |
| 427 | want: ast.String("hello"), |
| 428 | }, |
| 429 | { |
| 430 | name: "construct a tuple, case more than two elements", |
| 431 | expr: ast.ApplyFn{symbols.Tuple, []ast.BaseTerm{ast.String("hello"), ast.Number(2), ast.Number(32)}}, |
| 432 | want: *pair(ast.String("hello"), *pair(ast.Number(2), ast.Number(32))), |
| 433 | }, |
| 434 | { |
| 435 | name: "construct a list", |
| 436 | expr: ast.ApplyFn{symbols.List, []ast.BaseTerm{ast.String("hello"), ast.Number(2), ast.Number(32)}}, |
| 437 | want: ast.List([]ast.Constant{ast.String("hello"), ast.Number(2), ast.Number(32)}), |
| 438 | }, |
| 439 | { |
| 440 | name: "get element of list", |
| 441 | expr: ast.ApplyFn{symbols.ListGet, []ast.BaseTerm{ |
| 442 | ast.List([]ast.Constant{ast.String("hello"), ast.Number(2), ast.Number(32)}), |
| 443 | ast.Number(2)}}, |
| 444 | want: ast.Number(32), |
| 445 | }, |
| 446 | { |
| 447 | name: "min of number list", |
| 448 | expr: ast.ApplyFn{symbols.Min, []ast.BaseTerm{ |
| 449 | ast.List([]ast.Constant{ast.Number(2), ast.Number(5), ast.Number(32)})}}, |
| 450 | want: ast.Number(2), |
| 451 | }, |
| 452 | { |
| 453 | name: "sum of number list", |
| 454 | expr: ast.ApplyFn{symbols.Sum, []ast.BaseTerm{ |
| 455 | ast.List([]ast.Constant{ast.Number(2), ast.Number(5), ast.Number(32)})}}, |
| 456 | want: ast.Number(39), |
| 457 | }, |
| 458 | { |
| 459 | name: "floatmax of float64 list", |
| 460 | expr: ast.ApplyFn{symbols.FloatMax, []ast.BaseTerm{ |
| 461 | ast.List([]ast.Constant{ast.Float64(2.0), ast.Float64(5.0), ast.Float64(32.0)})}}, |
| 462 | want: ast.Float64(32.0), |
| 463 | }, |
| 464 | { |
| 465 | name: "append element to empty list", |
nothing calls this directly
no test coverage detected