Skip to content

Commit

Permalink
add ternary precedence test
Browse files Browse the repository at this point in the history
in case we ever use custom grammar or something
  • Loading branch information
charles-cooper committed May 11, 2023
1 parent ba43429 commit 422442c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tests/parser/features/test_ternary.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,31 @@ def __init__(test: bool):


@pytest.mark.parametrize("test", [True, False])
def test_complex_ternary_expression(get_contract, test):
@pytest.mark.parametrize("x", list(range(8)))
@pytest.mark.parametrize("y", list(range(8)))
def test_complex_ternary_expression(get_contract, test, x, y):
code = """
@external
def foo(t: bool, x: uint256, y: uint256) -> uint256:
return (x * y) if (t and True) else (x + y + convert(t, uint256))
"""
c = get_contract(code)

x, y = 7, 5
assert c.foo(test, x, y) == (x * y if test else x + y)
assert c.foo(test, x, y) == ((x * y) if (test and True) else (x + y + int(test)))


@pytest.mark.parametrize("test", [True, False])
@pytest.mark.parametrize("x", list(range(8)))
@pytest.mark.parametrize("y", list(range(8)))
def test_ternary_precedence(get_contract, test, x, y):
code = """
@external
def foo(t: bool, x: uint256, y: uint256) -> uint256:
return x * y if t else x + y + convert(t, uint256)
"""
c = get_contract(code)

assert c.foo(test, x, y) == (x * y if test else x + y + int(test))


@pytest.mark.parametrize("test1", [True, False])
Expand Down

0 comments on commit 422442c

Please sign in to comment.