phasm/tests/integration/test_lang/test_promotable.py
2025-05-02 21:05:07 +02:00

52 lines
911 B
Python

import pytest
from phasm.type3.entry import Type3Exception
from ..helpers import Suite
@pytest.mark.integration_test
def test_promote_not_implemented():
code_py = """
class Foo:
val: i32
class Baz:
val: i32
@exported
def testEntry(x: Foo) -> Baz:
return promote(x)
"""
with pytest.raises(Type3Exception, match='Missing type class instantation: Promotable Foo Baz'):
Suite(code_py).run_code()
@pytest.mark.integration_test
def test_promote_ok():
code_py = """
CONSTANT: f32 = 10.5
@exported
def testEntry() -> f64:
return promote(CONSTANT)
"""
result = Suite(code_py).run_code()
assert 10.5 == result.returned_value
@pytest.mark.integration_test
def test_demote_ok():
code_py = """
CONSTANT: f64 = 10.5
@exported
def testEntry() -> f32:
return demote(CONSTANT)
"""
result = Suite(code_py).run_code()
assert 10.5 == result.returned_value