(t *testing.T)
| 535 | } |
| 536 | |
| 537 | func TestEvalApplyFnNegative(t *testing.T) { |
| 538 | tests := []struct { |
| 539 | name string |
| 540 | expr ast.ApplyFn |
| 541 | }{ |
| 542 | { |
| 543 | name: "len of non-list", |
| 544 | expr: ast.ApplyFn{symbols.Len, []ast.BaseTerm{ast.Number(23)}}, |
| 545 | }, |
| 546 | { |
| 547 | name: "get of non-list, non-struct", |
| 548 | expr: ast.ApplyFn{symbols.ListGet, []ast.BaseTerm{ast.Number(23), ast.Number(23)}}, |
| 549 | }, |
| 550 | { |
| 551 | name: "append of non-list", |
| 552 | expr: ast.ApplyFn{symbols.Append, []ast.BaseTerm{ast.Number(23), ast.Number(23)}}, |
| 553 | }, |
| 554 | { |
| 555 | name: "out of bounds", |
| 556 | expr: ast.ApplyFn{symbols.ListGet, []ast.BaseTerm{ast.ListNil, ast.Number(1)}}, |
| 557 | }, |
| 558 | { |
| 559 | name: "lookup map not found", |
| 560 | expr: ast.ApplyFn{symbols.MapGet, []ast.BaseTerm{ |
| 561 | ast.ApplyFn{symbols.Map, []ast.BaseTerm{ast.Number(1), ast.String("v"), ast.Number(2), ast.String("foo")}}, |
| 562 | ast.Number(3)}}, |
| 563 | }, |
| 564 | { |
| 565 | name: "lookup struct not found", |
| 566 | expr: ast.ApplyFn{symbols.StructGet, []ast.BaseTerm{ |
| 567 | ast.ApplyFn{symbols.Struct, []ast.BaseTerm{name("/field1"), ast.String("value"), name("/field2"), ast.Number(32)}}, |
| 568 | name("/field3")}}, |
| 569 | }, |
| 570 | } |
| 571 | for _, test := range tests { |
| 572 | t.Run(test.name, func(t *testing.T) { |
| 573 | if res, err := EvalApplyFn(test.expr, ast.ConstSubstMap{}); err == nil { // if no error |
| 574 | t.Errorf("EvalApplyFn(%v)=%v, want error", test.expr, res) |
| 575 | } |
| 576 | }) |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | func TestRoundTrip(t *testing.T) { |
| 581 | tests := []ast.Atom{ |
nothing calls this directly
no test coverage detected