First to be more in line with how the literature treats these types. But also to make them workable with type classes.
73 lines
1.6 KiB
Python
73 lines
1.6 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()
|