Edge case fixes

This commit is contained in:
Johan B.W. de Vries 2022-12-24 17:43:05 +01:00
parent 1ab6dfd333
commit 08b1d78faf
3 changed files with 18 additions and 25 deletions

View File

@ -6,8 +6,3 @@ class StaticError(Exception):
""" """
An error found during static analysis An error found during static analysis
""" """
class TypingError(Exception):
"""
An error found during the typing phase
"""

View File

@ -1,10 +1,9 @@
import pytest import pytest
from phasm.exceptions import TypingError
from phasm.type3.entry import Type3Exception from phasm.type3.entry import Type3Exception
from ..helpers import Suite from ..helpers import Suite
from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, TYPE_MAP
@pytest.mark.integration_test @pytest.mark.integration_test
@pytest.mark.parametrize('type_', ALL_INT_TYPES) @pytest.mark.parametrize('type_', ALL_INT_TYPES)
@ -86,7 +85,7 @@ def testEntry() -> u32:
return 14 return 14
""" """
with pytest.raises(TypingError, match='u8.*1000'): with pytest.raises(Type3Exception, match='u8.*1000'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test

View File

@ -1,6 +1,6 @@
import pytest import pytest
from phasm.exceptions import TypingError from phasm.type3.entry import Type3Exception
from ..constants import ( from ..constants import (
ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP
@ -101,7 +101,7 @@ def test_module_constant_type_mismatch_bitwidth():
CONSTANT: u8[3] = (24, 57, 280, ) CONSTANT: u8[3] = (24, 57, 280, )
""" """
with pytest.raises(TypingError, match='u8.*280'): with pytest.raises(Type3Exception, match=r'Must fit in 1 byte\(s\)'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
@ -113,7 +113,7 @@ def testEntry() -> u32:
return CONSTANT return CONSTANT
""" """
with pytest.raises(TypingError, match=r'u32.*u8\[3\]'): with pytest.raises(Type3Exception, match=r'static_array \(u8\) must be u32 instead'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
@ -126,7 +126,7 @@ def testEntry() -> u8:
return CONSTANT[0] return CONSTANT[0]
""" """
with pytest.raises(TypingError, match='Type cannot be subscripted:'): with pytest.raises(Type3Exception, match='Type cannot be subscripted:'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
@ -139,38 +139,37 @@ def testEntry() -> u8:
return CONSTANT[3] return CONSTANT[3]
""" """
with pytest.raises(TypingError, match='Type cannot be subscripted with index 3:'): with pytest.raises(Type3Exception, match='Type cannot be subscripted with index 3:'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
def test_static_array_constant_too_few_values(): def test_static_array_constant_too_few_values():
code_py = """ code_py = """
CONSTANT: u8[3] = (24, 57, ) CONSTANT: u8[3] = (24, 57, )
@exported
def testEntry() -> i32:
return 0
""" """
with pytest.raises(TypingError, match='Member count does not match'): with pytest.raises(Type3Exception, match='Member count does not match'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
def test_static_array_constant_too_many_values(): def test_static_array_constant_too_many_values():
code_py = """ code_py = """
CONSTANT: u8[3] = (24, 57, 1, 1, ) CONSTANT: u8[3] = (24, 57, 1, 1, )
@exported
def testEntry() -> i32:
return 0
""" """
with pytest.raises(TypingError, match='Member count does not match'): with pytest.raises(Type3Exception, match='Member count does not match'):
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
def test_static_array_constant_type_mismatch(): @pytest.mark.skip('To decide: What to do on out of index? Should be a panic.')
code_py = """
CONSTANT: u8[3] = (24, 4000, 1, )
"""
with pytest.raises(TypingError, match='u8.*4000'):
Suite(code_py).run_code()
@pytest.mark.integration_test
@pytest.mark.skip('To decide: What to do on out of index?')
def test_static_array_index_out_of_bounds(): def test_static_array_index_out_of_bounds():
code_py = """ code_py = """
CONSTANT0: u32[3] = (24, 57, 80, ) CONSTANT0: u32[3] = (24, 57, 80, )