import pytest from phasm.type3.entry import Type3Exception from ..helpers import Suite @pytest.mark.integration_test def test_foldable_sum(): code_py = """ @exported def testEntry(x: i32[5]) -> i32: return sum(x) """ result = Suite(code_py).run_code((4, 5, 6, 7, 8, )) assert 30 == result.returned_value @pytest.mark.integration_test def test_foldable_sum_not_natnum(): code_py = """ class Foo: bar: i32 @exported def testEntry(x: Foo[4]) -> Foo: return sum(x) """ with pytest.raises(Type3Exception, match='Missing type class instantation: NatNum Foo'): Suite(code_py).run_code() @pytest.mark.integration_test def test_foldable_invalid_return_type(): code_py = """ @exported def testEntry(x: i32[5]) -> f64: return sum(x) """ with pytest.raises(Type3Exception, match='f64 must be i32 instead'): Suite(code_py).run_code((4, 5, 6, 7, 8, )) @pytest.mark.integration_test def test_foldable_not_foldable(): code_py = """ @exported def testEntry(x: i32) -> i32: return sum(x) """ with pytest.raises(Type3Exception, match='Missing type class instantation: Foldable i32'): Suite(code_py).run_code()