UAdd, tests
This commit is contained in:
parent
e972b37149
commit
0c64973b2b
@ -219,13 +219,19 @@ class Visitor:
|
||||
"""
|
||||
Visits a UnaryOp node as (part of) an expression
|
||||
"""
|
||||
del module
|
||||
del wlocals
|
||||
if isinstance(node.op, ast.UAdd):
|
||||
return self.visit_expr(module, wlocals, exp_type, node.operand)
|
||||
|
||||
if isinstance(node.op, ast.USub):
|
||||
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(
|
||||
self,
|
||||
|
||||
@ -28,6 +28,32 @@ def testEntry(a: i32) -> i32:
|
||||
assert 125 == 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 = """
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user