type5 is much more first principles based, so we get a lot of weird quirks removed: - FromLiteral no longer needs to understand AST - Type unifications works more like Haskell - Function types are just ordinary types, saving a lot of manual busywork and more.
99 lines
2.2 KiB
Python
99 lines
2.2 KiB
Python
import pytest
|
|
|
|
from phasm.type5.solver import Type5SolverException
|
|
|
|
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(Type5SolverException, match='Cannot convert from literal integer'):
|
|
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(Type5SolverException, 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(Type5SolverException, 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(Type5SolverException, 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
|