2022-04-15 06:31:58 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
from .fixtures import * # noqa
|
|
|
|
|
2022-04-15 06:31:58 +00:00
|
|
|
import pytest
|
2022-06-01 01:04:14 +00:00
|
|
|
from shoggoth.vm import *
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-15 06:31:58 +00:00
|
|
|
[[True], [False]],
|
|
|
|
[[True], [False]],
|
|
|
|
])
|
|
|
|
def test_not(vm, stack, ret):
|
2022-04-21 06:17:59 +00:00
|
|
|
assert vm.run([Opcode.CALLS(NOT)], stack = stack) == ret
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-15 06:31:58 +00:00
|
|
|
[[False, False], [False]],
|
|
|
|
[[True, False], [True]],
|
|
|
|
[[False, True], [True]],
|
|
|
|
[[True, True], [True]],
|
|
|
|
])
|
|
|
|
def test_or(vm, stack, ret):
|
2022-04-21 06:17:59 +00:00
|
|
|
assert vm.run([Opcode.CALLS(OR)], stack = stack) == ret
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-15 06:31:58 +00:00
|
|
|
[[False, False], [False]],
|
|
|
|
[[True, False], [False]],
|
|
|
|
[[False, True], [False]],
|
|
|
|
[[True, True], [True]],
|
|
|
|
])
|
|
|
|
def test_and(vm, stack, ret):
|
2022-04-21 06:17:59 +00:00
|
|
|
assert vm.run([Opcode.CALLS(AND)], stack = stack) == ret
|
2022-04-15 06:31:58 +00:00
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-15 06:31:58 +00:00
|
|
|
[[False, False], [False]],
|
|
|
|
[[True, False], [True]],
|
|
|
|
[[False, True], [True]],
|
|
|
|
[[True, True], [False]],
|
|
|
|
])
|
|
|
|
def test_xor(vm, stack, ret):
|
2022-04-21 06:17:59 +00:00
|
|
|
assert vm.run([Opcode.CALLS(XOR)], stack = stack) == ret
|
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-21 06:17:59 +00:00
|
|
|
[[], [FunctionRef.parse(NOT)]]
|
|
|
|
])
|
|
|
|
def test_funref(vm, stack, ret):
|
|
|
|
assert vm.run([Opcode.FUNREF(NOT), Opcode.RETURN(1)], stack = stack) == ret
|
|
|
|
|
|
|
|
|
2022-05-31 15:41:10 +00:00
|
|
|
@pytest.mark.parametrize("stack,ret", [
|
2022-04-21 06:17:59 +00:00
|
|
|
[[], [True]]
|
|
|
|
])
|
|
|
|
def test_callf(vm, stack, ret):
|
|
|
|
assert vm.run([Opcode.FALSE(), Opcode.FUNREF(NOT), Opcode.CALLF(1)], stack = stack) == ret
|