UAdd, tests

This commit is contained in:
Johan B.W. de Vries 2021-08-07 14:40:15 +02:00
parent e972b37149
commit 0c64973b2b
2 changed files with 37 additions and 5 deletions

View File

@ -219,13 +219,19 @@ class Visitor:
""" """
Visits a UnaryOp node as (part of) an expression Visits a UnaryOp node as (part of) an expression
""" """
del module if isinstance(node.op, ast.UAdd):
del wlocals return self.visit_expr(module, wlocals, exp_type, node.operand)
if isinstance(node.op, ast.USub):
if not isinstance(node.operand, ast.Constant): if not isinstance(node.operand, ast.Constant):
raise NotImplementedError raise NotImplementedError(node.operand)
return self.visit_Constant(exp_type, node.operand) if not isinstance(node.operand.value, int):
raise NotImplementedError(node.operand.value)
return self.visit_Constant(exp_type, ast.Constant(-node.operand.value))
raise NotImplementedError(node.op)
def visit_BinOp( def visit_BinOp(
self, self,

View File

@ -28,6 +28,32 @@ def testEntry(a: i32) -> i32:
assert 125 == result.returned_value assert 125 == result.returned_value
assert [] == result.log_int32_list 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 @pytest.mark.integration_test
def test_addition(): def test_addition():
code_py = """ code_py = """