| 705 | } |
| 706 | |
| 707 | func TestVM_CallN(t *testing.T) { |
| 708 | input := `fn(1, 2, 3)` |
| 709 | |
| 710 | tree, err := parser.Parse(input) |
| 711 | require.NoError(t, err) |
| 712 | |
| 713 | env := map[string]any{ |
| 714 | "fn": func(args ...any) (any, error) { |
| 715 | sum := 0 |
| 716 | for _, arg := range args { |
| 717 | sum += arg.(int) |
| 718 | } |
| 719 | return sum, nil |
| 720 | }, |
| 721 | } |
| 722 | |
| 723 | config := conf.New(env) |
| 724 | program, err := compiler.Compile(tree, config) |
| 725 | require.NoError(t, err) |
| 726 | |
| 727 | out, err := vm.Run(program, env) |
| 728 | require.NoError(t, err) |
| 729 | require.Equal(t, 6, out) |
| 730 | } |
| 731 | |
| 732 | // TestVM_IndexAndCountOperations tests the index and count manipulation opcodes directly |
| 733 | func TestVM_IndexAndCountOperations(t *testing.T) { |