From c66f493017793828e7f1d11c3e1bbac250e28120 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Tue, 24 Sep 2019 16:45:41 +0300 Subject: [PATCH] vm: compare Map by reference in EQUAL --- pkg/vm/vm.go | 5 +++++ pkg/vm/vm_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 658b26bc9..17ac189b1 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -478,6 +478,11 @@ func (v *VM) execute(ctx *Context, op Instruction) { v.estack.PushVal(ta == tb) break } + } else if ma, ok := a.value.(*MapItem); ok { + if mb, ok := b.value.(*MapItem); ok { + v.estack.PushVal(ma == mb) + break + } } v.estack.PushVal(reflect.DeepEqual(a, b)) diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index f46ea67ff..4b121d6e3 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -446,6 +446,27 @@ func TestEQUALArrayFalse(t *testing.T) { assert.Equal(t, &BoolItem{false}, vm.estack.Pop().value) } +func TestEQUALMapTrue(t *testing.T) { + prog := makeProgram(DUP, EQUAL) + vm := load(prog) + vm.estack.Push(&Element{value: NewMapItem()}) + vm.Run() + assert.Equal(t, false, vm.HasFailed()) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value) +} + +func TestEQUALMapFalse(t *testing.T) { + prog := makeProgram(EQUAL) + vm := load(prog) + vm.estack.Push(&Element{value: NewMapItem()}) + vm.estack.Push(&Element{value: NewMapItem()}) + vm.Run() + assert.Equal(t, false, vm.HasFailed()) + assert.Equal(t, 1, vm.estack.Len()) + assert.Equal(t, &BoolItem{false}, vm.estack.Pop().value) +} + func TestNumEqual(t *testing.T) { prog := makeProgram(NUMEQUAL) vm := load(prog)