By annotating types with the constructor application that was used to create them. Later on we can use the router to replace compiler's INSTANCES or for user defined types.
99 lines
2.2 KiB
Python
99 lines
2.2 KiB
Python
import pytest
|
|
|
|
from phasm.type3.entry import Type3Exception
|
|
|
|
from ..helpers import Suite
|
|
|
|
|
|
@pytest.mark.integration_test
|
|
def test_function_call_element_ok():
|
|
code_py = """
|
|
CONSTANT: (u8, u32, u64, ) = (250, 250000, 250000000, )
|
|
|
|
@exported
|
|
def testEntry() -> u64:
|
|
return helper(CONSTANT[2])
|
|
|
|
def helper(x: u64) -> u64:
|
|
return x
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 250000000 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.skip('SIMD support is but a dream')
|
|
def test_tuple_i32x4():
|
|
code_py = """
|
|
@exported
|
|
def testEntry() -> i32x4:
|
|
return (51, 153, 204, 0, )
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert (1, 2, 3, 0) == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_assign_to_tuple_with_tuple():
|
|
code_py = """
|
|
CONSTANT: (u32, ) = 0
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Must be tuple'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_constant_too_few_values():
|
|
code_py = """
|
|
CONSTANT: (u32, u8, u8, ) = (24, 57, )
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Tuple element count mismatch'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_constant_too_many_values():
|
|
code_py = """
|
|
CONSTANT: (u32, u8, u8, ) = (24, 57, 1, 1, )
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Tuple element count mismatch'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_constant_type_mismatch():
|
|
code_py = """
|
|
CONSTANT: (u32, u8, u8, ) = (24, 4000, 1, )
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match=r'Must fit in 1 byte\(s\)'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_export_constant():
|
|
code_py = """
|
|
CONSTANT: (u32, u8, u8, ) = (4000, 20, 20, )
|
|
|
|
@exported
|
|
def testEntry() -> (u32, u8, u8, ):
|
|
return CONSTANT
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert (4000, 20, 20, ) == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_export_instantiation():
|
|
code_py = """
|
|
@exported
|
|
def testEntry() -> (u32, u8, u8, ):
|
|
return (4000, 20, 20, )
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert (4000, 20, 20, ) == result.returned_value
|