MCPcopy Create free account
hub / github.com/expr-lang/expr / TestVM_IndexOperations

Function TestVM_IndexOperations

vm/vm_test.go:564–593  ·  view source on GitHub ↗

TestVM_IndexOperations tests the index manipulation opcodes

(t *testing.T)

Source from the content-addressed store, hash-verified

562
563// TestVM_IndexOperations tests the index manipulation opcodes
564func 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
596func TestVM_DirectCallOpcodes(t *testing.T) {

Callers

nothing calls this directly

Calls 4

RunMethod · 0.95
CompileFunction · 0.92
NoErrorFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…