vm: implement EQUAL opcode properly

When comparing elements of different types, conversions
should be performed. This commit implement custom equality
predicate for each stack item type.
This commit is contained in:
Evgenii Stratonikov 2020-03-11 16:44:10 +03:00
parent 5da82e8cf0
commit dfc59129c7
4 changed files with 100 additions and 13 deletions

View file

@ -1006,6 +1006,16 @@ func TestEQUALGoodInteger(t *testing.T) {
assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value)
}
func TestEQUALIntegerByteArray(t *testing.T) {
prog := makeProgram(opcode.EQUAL)
vm := load(prog)
vm.estack.PushVal([]byte{16})
vm.estack.PushVal(16)
runVM(t, vm)
assert.Equal(t, 1, vm.estack.Len())
assert.Equal(t, &BoolItem{true}, vm.estack.Pop().value)
}
func TestEQUALArrayTrue(t *testing.T) {
prog := makeProgram(opcode.DUP, opcode.EQUAL)
vm := load(prog)