Skip to content

Commit

Permalink
add literal test
Browse files Browse the repository at this point in the history
  • Loading branch information
tserg committed Nov 28, 2024
1 parent bebf6db commit d260dcf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tests/functional/codegen/types/numbers/test_unsigned_ints.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ def foo(x: {typ}, y: {typ}) -> bool:


@pytest.mark.parametrize("typ", types)
def test_uint_literal(get_contract, typ):
@pytest.mark.parametrize("is_hex_int", [True, False])
def test_uint_literal(get_contract, typ, is_hex_int):
lo, hi = typ.ast_bounds

good_cases = [0, 1, 2, 3, hi // 2 - 1, hi // 2, hi // 2 + 1, hi - 1, hi]
Expand All @@ -222,11 +223,21 @@ def test() -> {typ}:
return o
"""

def _to_hex_int(v):
n_nibbles = typ.bits // 4
return "0x" + hex(v)[2:].rjust(n_nibbles, "0")

for val in good_cases:
c = get_contract(code_template.format(typ=typ, val=val))
input_val = val
if is_hex_int:
n_nibbles = typ.bits // 4
input_val = "0x" + hex(val)[2:].rjust(n_nibbles, "0")
c = get_contract(code_template.format(typ=typ, val=input_val))
assert c.test() == val

for val in bad_cases:
if is_hex_int:
return
exc = (
TypeMismatch
if SizeLimits.MIN_INT256 <= val <= SizeLimits.MAX_UINT256
Expand Down

0 comments on commit d260dcf

Please sign in to comment.