source/projects/shoggoth/test/python/ichor/test_bootstrap.py

143 lines
3.3 KiB
Python
Raw Normal View History

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-06-01 01:25:18 +00:00
from ichor import *
2022-06-01 05:17:32 +00:00
import pytest
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):
assert vm.run([
Opcode.IDENTIFIERC(NOT1),
Opcode.FUNREF(),
Opcode.CALLF(1),
Opcode.RETURN(1)
], 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):
assert vm.run([
Opcode.IDENTIFIERC(OR2),
Opcode.FUNREF(),
Opcode.CALLF(2),
Opcode.RETURN(1)
], 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):
assert vm.run([
Opcode.IDENTIFIERC(AND2),
Opcode.FUNREF(),
Opcode.CALLF(2),
Opcode.RETURN(1)
], 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]],
])
2022-06-01 05:08:29 +00:00
def test_xor2(vm, stack, ret):
assert vm.run([
Opcode.IDENTIFIERC(XOR2),
Opcode.FUNREF(),
Opcode.CALLF(2),
Opcode.RETURN(1)
], stack = stack) == ret
2022-06-01 05:08:29 +00:00
2022-06-01 05:54:11 +00:00
2022-06-01 05:08:29 +00:00
@pytest.mark.parametrize("stack,ret", [
[[False, False, False], [False]],
[[True, False, False], [True]],
[[False, True, False], [True]],
[[True, True, False], [True]],
[[True, True, True], [False]],
[[False, True, True], [True]],
[[False, False, True], [True]],
])
def test_xor3(vm, stack, ret):
assert vm.run([
Opcode.IDENTIFIERC(XOR3),
Opcode.FUNREF(),
Opcode.CALLF(3),
Opcode.RETURN(1)
], stack = stack) == ret
2022-05-31 15:41:10 +00:00
@pytest.mark.parametrize("stack,ret", [
2022-06-01 05:08:29 +00:00
[[], [FunctionRef.parse(NOT1)]]
])
def test_funref(vm, stack, ret):
assert vm.run([
Opcode.IDENTIFIERC(NOT1),
Opcode.FUNREF(),
Opcode.RETURN(1)
], stack = stack) == ret
2022-05-31 15:41:10 +00:00
@pytest.mark.parametrize("stack,ret", [
[[], [True]]
])
def test_callf(vm, stack, ret):
assert vm.run([
Opcode.FALSE(),
Opcode.IDENTIFIERC(NOT1),
Opcode.FUNREF(),
Opcode.CALLF(1),
Opcode.RETURN(1)
], stack = stack) == ret
2022-06-01 05:54:11 +00:00
@pytest.mark.parametrize("stack,ret", [
[[False, False], [False]],
[[True, False], [True]],
[[False, True], [True]],
[[True, True], [False]],
])
def test_callc(vm, stack, ret):
assert vm.run([
Opcode.IDENTIFIERC(XOR2),
Opcode.FUNREF(),
2022-06-01 05:54:11 +00:00
Opcode.CLOSUREF(1),
Opcode.CALLC(1),
Opcode.RETURN(1),
], stack = stack) == ret
2022-06-01 06:09:59 +00:00
@pytest.mark.parametrize("stack,ret", [
[[False, False, False], [False]],
[[True, False, False], [True]],
[[False, True, False], [True]],
[[True, True, False], [True]],
[[True, True, True], [False]],
[[False, True, True], [True]],
[[False, False, True], [True]],
])
def test_closurec(vm, stack, ret):
assert vm.run([
Opcode.IDENTIFIERC(XOR3),
Opcode.FUNREF(),
2022-06-01 06:09:59 +00:00
Opcode.CLOSUREF(1),
Opcode.CLOSUREC(1),
Opcode.CALLC(1),
Opcode.RETURN(1),
], stack = stack) == ret