Prior to this PR, each type would have its own handwritten test suite. The end result was that not all types were tested for all situations. This PR adds a framework based on a Markdown file, which generates the basic tests for the types defined in json files. These are auto generated and updated by the Makefile before the test suite is run. Also, a number of unsupported type combinations are now supported. Also, we now support negative literals. Also, allocation calculation fixes for nested types. Also, the test helpers can now properly import and export typed variables such as bytes, static arrays and tuples. This may come in handy when it comes to phasm platform wanting to route data. Also, adds better support for i8 type. Also, started on a runtime.py, since there's quite some code now that deals with compile time handling of WebAssembly stuff. Also, minor improvement to the type constrains, namely we better match 'tuple' literals with static array types. Also, reduced spam when printing the type analysis results; constraints that go back on the backlog are now no longer printed one by one. It now also prints the end results of the typing analysis. Also, reorganized the big test_primitives test into type classes. Also, replaced pylint with ruff.
97 lines
2.2 KiB
Python
97 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_must_use_literal_for_indexing():
|
|
code_py = """
|
|
CONSTANT: u32 = 0
|
|
|
|
@exported
|
|
def testEntry(x: (u8, u32, u64)) -> u64:
|
|
return x[CONSTANT]
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Must index with literal'):
|
|
Suite(code_py).run_code()
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_must_use_integer_for_indexing():
|
|
code_py = """
|
|
@exported
|
|
def testEntry(x: (u8, u32, u64)) -> u64:
|
|
return x[0.0]
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match='Must index with integer literal'):
|
|
Suite(code_py).run_code()
|