diff --git a/tests/integration/constants.py b/tests/integration/constants.py index 07dacbe..c2f8860 100644 --- a/tests/integration/constants.py +++ b/tests/integration/constants.py @@ -13,4 +13,4 @@ TYPE_MAP = { **{x: float for x in ALL_FLOAT_TYPES}, } -COMPLETE_PRIMITIVE_TYPES = COMPLETE_INT_TYPES + COMPLETE_FLOAT_TYPES +COMPLETE_NUMERIC_TYPES = COMPLETE_INT_TYPES + COMPLETE_FLOAT_TYPES diff --git a/tests/integration/test_lang/test_primitives.py b/tests/integration/test_lang/test_primitives.py index 9c3aac2..c93dc7c 100644 --- a/tests/integration/test_lang/test_primitives.py +++ b/tests/integration/test_lang/test_primitives.py @@ -3,7 +3,7 @@ import pytest from phasm.exceptions import TypingError from ..helpers import Suite -from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, TYPE_MAP +from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP @pytest.mark.integration_test @pytest.mark.parametrize('type_', ALL_INT_TYPES) @@ -225,6 +225,20 @@ def testEntry() -> {type_}: assert 32.125 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) +@pytest.mark.integration_test +@pytest.mark.skip('TODO: Runtimes return a signed value, which is difficult to test') +@pytest.mark.parametrize('type_', ('u32', 'u64')) # FIXME: u8 +def test_subtraction_underflow(type_): + code_py = f""" +@exported +def testEntry() -> {type_}: + return 10 - 11 +""" + + result = Suite(code_py).run_code() + + assert 0 < result.returned_value + # TODO: Multiplication @pytest.mark.integration_test @@ -255,6 +269,18 @@ def testEntry() -> {type_}: assert 1.25 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) +@pytest.mark.integration_test +@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES) +def test_division_zero_let_it_crash(type_): + code_py = f""" +@exported +def testEntry() -> {type_}: + return 10 / 0 +""" + + with pytest.raises(Exception): + Suite(code_py).run_code() + @pytest.mark.integration_test @pytest.mark.parametrize('type_', ['f32', 'f64']) def test_builtins_sqrt(type_): diff --git a/tests/integration/test_lang/test_static_array.py b/tests/integration/test_lang/test_static_array.py index 9f549da..39fb1ae 100644 --- a/tests/integration/test_lang/test_static_array.py +++ b/tests/integration/test_lang/test_static_array.py @@ -3,7 +3,7 @@ import pytest from phasm.exceptions import StaticError, TypingError from ..constants import ( - ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_PRIMITIVE_TYPES, TYPE_MAP + ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP ) from ..helpers import Suite @@ -25,7 +25,7 @@ def testEntry() -> {type_}: @pytest.mark.integration_test @pytest.mark.skip('To decide: What to do on out of index?') -@pytest.mark.parametrize('type_', COMPLETE_PRIMITIVE_TYPES) +@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES) def test_static_array_indexed(type_): code_py = f""" CONSTANT: {type_}[3] = (24, 57, 80, ) diff --git a/tests/integration/test_lang/test_tuple.py b/tests/integration/test_lang/test_tuple.py index 5c5321e..6880833 100644 --- a/tests/integration/test_lang/test_tuple.py +++ b/tests/integration/test_lang/test_tuple.py @@ -1,6 +1,6 @@ import pytest -from ..constants import COMPLETE_PRIMITIVE_TYPES, TYPE_MAP +from ..constants import COMPLETE_NUMERIC_TYPES, TYPE_MAP from ..helpers import Suite @pytest.mark.integration_test @@ -39,7 +39,7 @@ def helper(vector: (u8, u8, u32, u32, u64, u64, )) -> u32: assert 3333 == result.returned_value @pytest.mark.integration_test -@pytest.mark.parametrize('type_', COMPLETE_PRIMITIVE_TYPES) +@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES) def test_tuple_simple_constructor(type_): code_py = f""" @exported