From 08b1d78faf19ac2231c54fab83e830546ad70251 Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Sat, 24 Dec 2022 17:43:05 +0100 Subject: [PATCH] Edge case fixes --- phasm/exceptions.py | 5 --- .../integration/test_lang/test_primitives.py | 5 ++- .../test_lang/test_static_array.py | 33 +++++++++---------- 3 files changed, 18 insertions(+), 25 deletions(-) diff --git a/phasm/exceptions.py b/phasm/exceptions.py index 77c75e7..b459c22 100644 --- a/phasm/exceptions.py +++ b/phasm/exceptions.py @@ -6,8 +6,3 @@ class StaticError(Exception): """ An error found during static analysis """ - -class TypingError(Exception): - """ - An error found during the typing phase - """ diff --git a/tests/integration/test_lang/test_primitives.py b/tests/integration/test_lang/test_primitives.py index 640a898..2c3565a 100644 --- a/tests/integration/test_lang/test_primitives.py +++ b/tests/integration/test_lang/test_primitives.py @@ -1,10 +1,9 @@ import pytest -from phasm.exceptions import TypingError from phasm.type3.entry import Type3Exception 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.parametrize('type_', ALL_INT_TYPES) @@ -86,7 +85,7 @@ def testEntry() -> u32: return 14 """ - with pytest.raises(TypingError, match='u8.*1000'): + with pytest.raises(Type3Exception, match='u8.*1000'): Suite(code_py).run_code() @pytest.mark.integration_test diff --git a/tests/integration/test_lang/test_static_array.py b/tests/integration/test_lang/test_static_array.py index 5c83943..cb0e4a9 100644 --- a/tests/integration/test_lang/test_static_array.py +++ b/tests/integration/test_lang/test_static_array.py @@ -1,6 +1,6 @@ import pytest -from phasm.exceptions import TypingError +from phasm.type3.entry import Type3Exception from ..constants import ( 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, ) """ - with pytest.raises(TypingError, match='u8.*280'): + with pytest.raises(Type3Exception, match=r'Must fit in 1 byte\(s\)'): Suite(code_py).run_code() @pytest.mark.integration_test @@ -113,7 +113,7 @@ def testEntry() -> u32: 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() @pytest.mark.integration_test @@ -126,7 +126,7 @@ def testEntry() -> u8: 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() @pytest.mark.integration_test @@ -139,38 +139,37 @@ def testEntry() -> u8: 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() @pytest.mark.integration_test def test_static_array_constant_too_few_values(): code_py = """ 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() @pytest.mark.integration_test def test_static_array_constant_too_many_values(): code_py = """ 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() @pytest.mark.integration_test -def test_static_array_constant_type_mismatch(): - 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?') +@pytest.mark.skip('To decide: What to do on out of index? Should be a panic.') def test_static_array_index_out_of_bounds(): code_py = """ CONSTANT0: u32[3] = (24, 57, 80, )