TestVM_IndexAndCountOperations tests the index and count manipulation opcodes directly
(t *testing.T)
| 731 | |
| 732 | // TestVM_IndexAndCountOperations tests the index and count manipulation opcodes directly |
| 733 | func TestVM_IndexAndCountOperations(t *testing.T) { |
| 734 | tests := []struct { |
| 735 | name string |
| 736 | bytecode []vm.Opcode |
| 737 | args []int |
| 738 | consts []any |
| 739 | want any |
| 740 | wantErr bool |
| 741 | }{ |
| 742 | { |
| 743 | name: "GetIndex", |
| 744 | bytecode: []vm.Opcode{ |
| 745 | vm.OpPush, // Push array to stack |
| 746 | vm.OpBegin, // Start scope |
| 747 | vm.OpGetIndex, // Get current index |
| 748 | }, |
| 749 | args: []int{0, 0, 0}, |
| 750 | consts: []any{[]any{1, 2, 3}}, // Array for scope |
| 751 | want: 0, // Initial index is 0 |
| 752 | }, |
| 753 | { |
| 754 | name: "DecrementIndex", |
| 755 | bytecode: []vm.Opcode{ |
| 756 | vm.OpPush, // Push array to stack |
| 757 | vm.OpBegin, // Start scope |
| 758 | vm.OpDecrementIndex, // Decrement index |
| 759 | vm.OpGetIndex, // Get current index |
| 760 | }, |
| 761 | args: []int{0, 0, 0, 0}, |
| 762 | consts: []any{[]any{1, 2, 3}}, // Array for scope |
| 763 | want: -1, // After decrement |
| 764 | }, |
| 765 | { |
| 766 | name: "GetCount", |
| 767 | bytecode: []vm.Opcode{ |
| 768 | vm.OpPush, // Push array to stack |
| 769 | vm.OpBegin, // Start scope |
| 770 | vm.OpGetCount, // Get current count |
| 771 | }, |
| 772 | args: []int{0, 0, 0}, |
| 773 | consts: []any{[]any{1, 2, 3}}, // Array for scope |
| 774 | want: 0, // Initial count is 0 |
| 775 | }, |
| 776 | { |
| 777 | name: "IncrementCount", |
| 778 | bytecode: []vm.Opcode{ |
| 779 | vm.OpPush, // Push array to stack |
| 780 | vm.OpBegin, // Start scope |
| 781 | vm.OpIncrementCount, // Increment count |
| 782 | vm.OpGetCount, // Get current count |
| 783 | }, |
| 784 | args: []int{0, 0, 0, 0}, |
| 785 | consts: []any{[]any{1, 2, 3}}, // Array for scope |
| 786 | want: 1, // After increment |
| 787 | }, |
| 788 | { |
| 789 | name: "Multiple operations", |
| 790 | bytecode: []vm.Opcode{ |