Doesn't give right answer yet and out of bound check fails. No constructor yet for static arrays, but module constants work. Which don't work yet for tuples and structs. Also, u32 for indexing please. Also, more module constant types.
88 lines
1.7 KiB
Python
88 lines
1.7 KiB
Python
import pytest
|
|
|
|
from .helpers import Suite
|
|
|
|
@pytest.mark.integration_test
|
|
def test_i32():
|
|
code_py = """
|
|
CONSTANT: i32 = 13
|
|
|
|
@exported
|
|
def testEntry() -> i32:
|
|
return CONSTANT * 5
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 65 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('type_', ['u8', 'u32', 'u64', ])
|
|
def test_tuple_1(type_):
|
|
code_py = f"""
|
|
CONSTANT: ({type_}, ) = (65, )
|
|
|
|
@exported
|
|
def testEntry() -> {type_}:
|
|
return helper(CONSTANT)
|
|
|
|
def helper(vector: ({type_}, )) -> {type_}:
|
|
return vector[0]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 65 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_tuple_6():
|
|
code_py = """
|
|
CONSTANT: (u8, u8, u32, u32, u64, u64, ) = (11, 22, 3333, 4444, 555555, 666666, )
|
|
|
|
@exported
|
|
def testEntry() -> u32:
|
|
return helper(CONSTANT)
|
|
|
|
def helper(vector: (u8, u8, u32, u32, u64, u64, )) -> u32:
|
|
return vector[2]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 3333 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
@pytest.mark.parametrize('type_', ['u8', 'u32', 'u64', ])
|
|
def test_static_array_1(type_):
|
|
code_py = f"""
|
|
CONSTANT: {type_}[1] = (65, )
|
|
|
|
@exported
|
|
def testEntry() -> {type_}:
|
|
return helper(CONSTANT)
|
|
|
|
def helper(vector: {type_}[1]) -> {type_}:
|
|
return vector[0]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 65 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_static_array_6():
|
|
code_py = """
|
|
CONSTANT: u32[6] = (11, 22, 3333, 4444, 555555, 666666, )
|
|
|
|
@exported
|
|
def testEntry() -> u32:
|
|
return helper(CONSTANT)
|
|
|
|
def helper(vector: u32[6]) -> u32:
|
|
return vector[2]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code()
|
|
|
|
assert 3333 == result.returned_value
|