2022-03-29 07:29:18 +00:00
|
|
|
"""
|
|
|
|
Tests coverign the VM interpreter
|
|
|
|
"""
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
from .fixtures import * # noqa
|
|
|
|
|
2022-06-01 01:25:18 +00:00
|
|
|
from ichor import *
|
2022-06-01 05:17:32 +00:00
|
|
|
import pytest
|
2022-03-29 07:29:18 +00:00
|
|
|
|
2022-04-12 07:49:12 +00:00
|
|
|
|
|
|
|
def test_return(vm):
|
2022-06-28 04:35:21 +00:00
|
|
|
assert vm.run([Opcode.RETURN(0)], stack=[TRUE, FALSE]) == []
|
|
|
|
assert vm.run([Opcode.RETURN(1)], stack=[TRUE, FALSE]) == [TRUE]
|
|
|
|
assert vm.run([Opcode.RETURN(2)], stack=[TRUE, FALSE]) == [TRUE, FALSE]
|
2022-03-29 07:29:18 +00:00
|
|
|
|
|
|
|
|
2022-04-12 07:49:12 +00:00
|
|
|
def test_dup(vm):
|
2022-06-28 04:35:21 +00:00
|
|
|
assert vm.run([Opcode.DUP(1), Opcode.RETURN(3)], stack=[FALSE, TRUE]) == [FALSE, TRUE, TRUE]
|
|
|
|
assert vm.run([Opcode.DUP(2), Opcode.RETURN(4)], stack=[FALSE, TRUE]) == [FALSE, TRUE, FALSE, TRUE]
|
2022-03-29 07:29:18 +00:00
|
|
|
|
|
|
|
|
2022-04-12 07:49:12 +00:00
|
|
|
def test_rot(vm):
|
2022-03-29 07:29:18 +00:00
|
|
|
assert vm.run([
|
|
|
|
Opcode.ROT(2),
|
|
|
|
Opcode.RETURN(2)
|
2022-06-28 04:35:21 +00:00
|
|
|
], stack=[FALSE, TRUE]) == [TRUE, FALSE]
|
2022-03-29 07:29:18 +00:00
|
|
|
|
|
|
|
assert vm.run([
|
|
|
|
Opcode.ROT(3),
|
|
|
|
Opcode.RETURN(3)
|
2022-06-28 04:35:21 +00:00
|
|
|
], stack=[FALSE, TRUE, FALSE]) == [FALSE, FALSE, TRUE]
|
2022-03-29 07:29:18 +00:00
|
|
|
|
|
|
|
|
2022-04-12 07:49:12 +00:00
|
|
|
def test_drop(vm):
|
2022-03-29 07:29:18 +00:00
|
|
|
assert vm.run([
|
|
|
|
Opcode.DROP(1),
|
|
|
|
Opcode.RETURN(1)
|
2022-06-28 04:35:21 +00:00
|
|
|
], stack=[TRUE, FALSE]) == [TRUE]
|
2022-03-29 07:29:18 +00:00
|
|
|
|
|
|
|
|
2022-04-12 07:49:12 +00:00
|
|
|
def test_dup_too_many(vm):
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.DUP(1)])
|
|
|
|
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.FALSE(), Opcode.DUP(2)])
|
|
|
|
|
|
|
|
|
|
|
|
def test_rot_too_many(vm):
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.ROT(1)])
|
|
|
|
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.TRUE(), Opcode.ROT(2)])
|
|
|
|
|
|
|
|
|
|
|
|
def test_drop_too_many(vm):
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.DROP(1)])
|
|
|
|
|
|
|
|
with pytest.raises(InterpreterError):
|
|
|
|
vm.run([Opcode.TRUE(), Opcode.DROP(2)])
|