vm: compare Array by reference in EQUAL
This commit is contained in:
parent
99f1d761ca
commit
a88a8e13fc
2 changed files with 27 additions and 0 deletions
|
@ -454,6 +454,12 @@ func (v *VM) execute(ctx *Context, op Instruction) {
|
||||||
if a == nil {
|
if a == nil {
|
||||||
panic("no second-to-the-top element found")
|
panic("no second-to-the-top element found")
|
||||||
}
|
}
|
||||||
|
if ta, ok := a.value.(*ArrayItem); ok {
|
||||||
|
if tb, ok := b.value.(*ArrayItem); ok {
|
||||||
|
v.estack.PushVal(ta == tb)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
v.estack.PushVal(reflect.DeepEqual(a, b))
|
v.estack.PushVal(reflect.DeepEqual(a, b))
|
||||||
|
|
||||||
// Bit operations.
|
// Bit operations.
|
||||||
|
|
|
@ -405,6 +405,27 @@ func TestEQUALGoodInteger(t *testing.T) {
|
||||||
assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value)
|
assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEQUALArrayTrue(t *testing.T) {
|
||||||
|
prog := makeProgram(DUP, EQUAL)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]StackItem{})
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEQUALArrayFalse(t *testing.T) {
|
||||||
|
prog := makeProgram(EQUAL)
|
||||||
|
vm := load(prog)
|
||||||
|
vm.estack.PushVal([]StackItem{})
|
||||||
|
vm.estack.PushVal([]StackItem{})
|
||||||
|
vm.Run()
|
||||||
|
assert.Equal(t, false, vm.state.HasFlag(faultState))
|
||||||
|
assert.Equal(t, 1, vm.estack.Len())
|
||||||
|
assert.Equal(t, &BoolItem{false}, vm.estack.Pop().value)
|
||||||
|
}
|
||||||
|
|
||||||
func TestNumEqual(t *testing.T) {
|
func TestNumEqual(t *testing.T) {
|
||||||
prog := makeProgram(NUMEQUAL)
|
prog := makeProgram(NUMEQUAL)
|
||||||
vm := load(prog)
|
vm := load(prog)
|
||||||
|
|
Loading…
Reference in a new issue