TestVM_IndexOperations tests the index manipulation opcodes
(t *testing.T)
| 562 | |
| 563 | // TestVM_IndexOperations tests the index manipulation opcodes |
| 564 | func TestVM_IndexOperations(t *testing.T) { |
| 565 | tests := []struct { |
| 566 | name string |
| 567 | expr string |
| 568 | want any |
| 569 | }{ |
| 570 | { |
| 571 | name: "decrement index in loop", |
| 572 | expr: "reduce([1,2,3], #acc + #, 0)", |
| 573 | want: 6, |
| 574 | }, |
| 575 | { |
| 576 | name: "set index in loop", |
| 577 | expr: "map([1,2,3], # * 2)", |
| 578 | want: []any{2, 4, 6}, |
| 579 | }, |
| 580 | } |
| 581 | |
| 582 | for _, tt := range tests { |
| 583 | t.Run(tt.name, func(t *testing.T) { |
| 584 | program, err := expr.Compile(tt.expr) |
| 585 | require.NoError(t, err) |
| 586 | |
| 587 | testVM := &vm.VM{} |
| 588 | got, err := testVM.Run(program, nil) |
| 589 | require.NoError(t, err) |
| 590 | require.Equal(t, tt.want, got) |
| 591 | }) |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // TestVM_DirectCallOpcodes tests the specialized call opcodes directly |
| 596 | func TestVM_DirectCallOpcodes(t *testing.T) { |