113 lines
2.5 KiB
Python
113 lines
2.5 KiB
Python
import pytest
|
|
|
|
from phasm.type3.entry import Type3Exception
|
|
|
|
from ..helpers import Suite
|
|
|
|
EXTENTABLE = [
|
|
('u8', 'u32', ),
|
|
('u8', 'u64', ),
|
|
('u32', 'u64', ),
|
|
|
|
('i8', 'i32', ),
|
|
('i8', 'i64', ),
|
|
('i32', 'i64', ),
|
|
]
|
|
|
|
@pytest.mark.integration_test
|
|
def test_extend_not_implemented():
|
|
code_py = """
|
|
class Foo:
|
|
val: i32
|
|
|
|
class Baz:
|
|
val: i32
|
|
|
|
@exported
|
|
def testEntry(x: Foo) -> Baz:
|
|
return extend(x)
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Missing type class instantation: Extendable Foo Baz'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('ext_from,ext_to', EXTENTABLE)
|
|
def test_extend_ok(ext_from,ext_to):
|
|
code_py = f"""
|
|
CONSTANT: {ext_from} = 10
|
|
|
|
@exported
|
|
def testEntry() -> {ext_to}:
|
|
return extend(CONSTANT)
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 10 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('ext_from,in_put,ext_to,exp_out', [
|
|
('u8', 241, 'u32', 241),
|
|
('u32', 4059165169, 'u64', 4059165169),
|
|
('u8', 241, 'u64', 241),
|
|
|
|
('i8', 113, 'i32', 113),
|
|
('i32', 1911681521, 'i64', 1911681521),
|
|
('i8', 113, 'i64', 113),
|
|
|
|
('i8', -15, 'i32', -15),
|
|
('i32', -15, 'i64', -15),
|
|
('i8', -15, 'i64', -15),
|
|
|
|
])
|
|
def test_extend_results(ext_from, ext_to, in_put, exp_out):
|
|
code_py = f"""
|
|
@exported
|
|
def testEntry(x: {ext_from}) -> {ext_to}:
|
|
return extend(x)
|
|
"""
|
|
|
|
result = Suite(code_py).run_code(in_put)
|
|
|
|
assert exp_out == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('ext_from,ext_to', EXTENTABLE)
|
|
def test_wrap_ok(ext_from,ext_to):
|
|
code_py = f"""
|
|
CONSTANT: {ext_to} = 10
|
|
|
|
@exported
|
|
def testEntry() -> {ext_from}:
|
|
return wrap(CONSTANT)
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 10 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('ext_to,in_put,ext_from,exp_out', [
|
|
('u32', 0xF1F1F1F1, 'u8', 0xF1),
|
|
('u64', 0xF1F1F1F1F1F1F1F1, 'u32', 0xF1F1F1F1),
|
|
('u64', 0xF1F1F1F1F1F1F1F1, 'u8', 0xF1),
|
|
|
|
('i32', 0xF1F1F171, 'i8', 113),
|
|
('i32', 0xF1F1F1F1, 'i8', -15),
|
|
('i64', 0x71F1F1F171F1F1F1, 'i32', 1911681521),
|
|
('i64', 0x71F1F1F1F1F1F1F1, 'i32', -235802127),
|
|
('i64', 0xF1F1F1F1F1F1F171, 'i8', 113),
|
|
('i64', 0xF1F1F1F1F1F1F1F1, 'i8', -15),
|
|
])
|
|
def test_wrap_results(ext_from, ext_to, in_put, exp_out):
|
|
code_py = f"""
|
|
@exported
|
|
def testEntry(x: {ext_to}) -> {ext_from}:
|
|
return wrap(x)
|
|
"""
|
|
|
|
result = Suite(code_py).run_code(in_put)
|
|
|
|
assert exp_out == result.returned_value
|