53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
import pytest
|
|
|
|
from phasm.type3.entry import Type3Exception
|
|
|
|
from ..helpers import Suite
|
|
|
|
@pytest.mark.integration_test
|
|
def test_bytes_length():
|
|
code_py = """
|
|
@exported
|
|
def testEntry(f: bytes) -> u32:
|
|
return len(f)
|
|
"""
|
|
|
|
result = Suite(code_py).run_code(b'This yet is another test')
|
|
|
|
assert 24 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_bytes_index_ok():
|
|
code_py = """
|
|
@exported
|
|
def testEntry(f: bytes) -> u8:
|
|
return f[8]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code(b'This is another test')
|
|
|
|
assert 0x61 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_bytes_index_out_of_bounds():
|
|
code_py = """
|
|
@exported
|
|
def testEntry(f: bytes, g: bytes) -> u8:
|
|
return f[50]
|
|
"""
|
|
|
|
result = Suite(code_py).run_code(b'Short', b'Long' * 100)
|
|
|
|
assert 0 == result.returned_value
|
|
|
|
@pytest.mark.integration_test
|
|
def test_bytes_index_invalid_type():
|
|
code_py = """
|
|
@exported
|
|
def testEntry(f: bytes, g: bytes) -> u64:
|
|
return f[50]
|
|
"""
|
|
|
|
with pytest.raises(Type3Exception, match=r'u64 must be u8 instead'):
|
|
Suite(code_py).run_code(b'Short', b'Long' * 100)
|