import pytest from .helpers import Suite @pytest.mark.integration_test def test_return_i32(): code_py = """ @exported def testEntry() -> i32: return 13 """ result = Suite(code_py, 'test_return').run_code() assert 13 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_return_i64(): code_py = """ @exported def testEntry() -> i64: return 13 """ result = Suite(code_py, 'test_return').run_code() assert 13 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_return_f32(): code_py = """ @exported def testEntry() -> f32: return 13.5 """ result = Suite(code_py, 'test_return').run_code() assert 13.5 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_return_f64(): code_py = """ @exported def testEntry() -> f64: return 13.5 """ result = Suite(code_py, 'test_return').run_code() assert 13.5 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_arg(): code_py = """ @exported def testEntry(a: i32) -> i32: return a """ result = Suite(code_py, 'test_return').run_code(125) assert 125 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_i32_to_i64(): code_py = """ @exported def testEntry(a: i32) -> i64: return a """ result = Suite(code_py, 'test_return').run_code(125) assert 125 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_i32_plus_i64(): code_py = """ @exported def testEntry(a: i32, b: i64) -> i64: return a + b """ result = Suite(code_py, 'test_return').run_code(125, 100) assert 225 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_f32_to_f64(): code_py = """ @exported def testEntry(a: f32) -> f64: return a """ result = Suite(code_py, 'test_return').run_code(125.5) assert 125.5 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_f32_plus_f64(): code_py = """ @exported def testEntry(a: f32, b: f64) -> f64: return a + b """ result = Suite(code_py, 'test_return').run_code(125.5, 100.25) assert 225.75 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_uadd(): code_py = """ @exported def testEntry() -> i32: return +523 """ result = Suite(code_py, 'test_addition').run_code() assert 523 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_usub(): code_py = """ @exported def testEntry() -> i32: return -19 """ result = Suite(code_py, 'test_addition').run_code() assert -19 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_addition(): code_py = """ @exported def testEntry() -> i32: return 10 + 3 """ result = Suite(code_py, 'test_addition').run_code() assert 13 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_if_simple(): code_py = """ @exported def testEntry(a: i32) -> i32: if a > 10: return 1 return 0 """ suite = Suite(code_py, 'test_return') result = suite.run_code(10) assert 0 == result.returned_value assert [] == result.log_int32_list result = suite.run_code(11) assert 1 == result.returned_value @pytest.mark.integration_test def test_if_complex(): code_py = """ @exported def testEntry(a: i32) -> i32: if a > 10: return 10 elif a > 0: return a else: return 0 return -1 # Required due to function type """ suite = Suite(code_py, 'test_return') assert 10 == suite.run_code(20).returned_value assert 10 == suite.run_code(10).returned_value assert 8 == suite.run_code(8).returned_value assert 0 == suite.run_code(0).returned_value assert 0 == suite.run_code(-1).returned_value @pytest.mark.integration_test def test_call_pre_defined(): code_py = """ def helper(left: i32, right: i32) -> i32: return left + right @exported def testEntry() -> i32: return helper(10, 3) """ result = Suite(code_py, 'test_call').run_code() assert 13 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_call_post_defined(): code_py = """ @exported def testEntry() -> i32: return helper(10, 3) def helper(left: i32, right: i32) -> i32: return left - right """ result = Suite(code_py, 'test_call').run_code() assert 7 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_assign(): code_py = """ @exported def testEntry() -> i32: a: i32 = 8947 return a """ result = Suite(code_py, 'test_call').run_code() assert 8947 == result.returned_value assert [] == result.log_int32_list @pytest.mark.integration_test def test_struct(): code_py = """ class Rectangle: height: i32 width: i32 border: i32 # = 5 @exported def testEntry() -> i32: return helper(Rectangle(100, 150, 2)) def helper(shape: Rectangle) -> i32: return shape.height + shape.width + shape.border """ result = Suite(code_py, 'test_call').run_code() assert 100 == result.returned_value assert [] == result.log_int32_list