phasm/tests/integration/test_lang/test_foldable.py
Johan B.W. de Vries 8a027a0b10 Implements sum for Foldable types
Foldable take a TypeConstructor. The first argument must be a
NatNum.
2025-05-05 14:09:38 +02:00

42 lines
879 B
Python

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_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: u8) -> u8:
return sum(x)
"""
with pytest.raises(Type3Exception, match='Missing type class instantation: Foldable u8'):
Suite(code_py).run_code()