Add more test cases

This commit is contained in:
Tim Sweet
2025-06-30 13:25:21 -05:00
committed by Joel-Flores123
parent 190c065a70
commit f4db48c276
3 changed files with 592 additions and 0 deletions
+266
View File
@@ -0,0 +1,266 @@
def a_if():
if a > b:
print(1)
def b_elif():
if a > b:
print(1)
elif a == b:
print(2)
def c_else():
if a > b:
print(1)
else:
print(2)
def d_elif_else():
if a > b:
print(1)
elif a == b:
print(2)
else:
print(3)
def e_oneline():
print(1) if a > b else print(2) if a == b else print(3)
def a1_if_and():
if a > b and c > d:
print(1)
def b1_elif_and():
if a > b and c > d:
print(1)
elif a == b:
print(2)
def c1_else_and():
if a > b and c > d:
print(1)
else:
print(2)
def d1_elif_else_and():
if a > b and c > d:
print(1)
elif a == b:
print(2)
else:
print(3)
def a2_if_or():
if a > b or c > d:
print(1)
def b2_elif_or():
if a > b or c > d:
print(1)
elif a == b:
print(2)
def c2_else_or():
if a > b or c > d:
print(1)
else:
print(2)
def d2_elif_else_or():
if a > b or c > d:
print(1)
elif a == b:
print(2)
else:
print(3)
def a3_if_not():
if not a > b:
print(1)
def b3_elif_not():
if not a > b:
print(1)
elif a == b:
print(2)
def c3_else_not():
if not a > b:
print(1)
else:
print(2)
def d3_elif_else_not():
if not a > b:
print(1)
elif a == b:
print(2)
else:
print(3)
def e_nested_if():
if a > b:
print(1)
if a == b:
print(2)
else:
print(3)
else:
print(4)
def e_nested_else():
if a > b:
print(1)
else:
print(2)
if a == b:
print(3)
else:
print(4)
def f_if_pass():
if a > b:
pass
def a_nofallthru_if():
if a > b:
print(1)
print("end")
def b_nofallthru_elif():
if a > b:
print(1)
elif a == b:
print(2)
print("end")
def c_nofallthru_else():
if a > b:
print(1)
else:
print(2)
print("end")
def d_nofallthru_elif_else():
if a > b:
print(1)
elif a == b:
print(2)
else:
print(3)
print("end")
def e_nofallthru_oneline():
print(1) if a > b else print(2) if a == b else print(3)
print("end")
def a_nofallthru1_if_and():
if a > b and c > d:
print(1)
print("end")
def b_nofallthru1_elif_and():
if a > b and c > d:
print(1)
elif a == b:
print(2)
print("end")
def c_nofallthru1_else_and():
if a > b and c > d:
print(1)
else:
print(2)
print("end")
def d_nofallthru1_elif_else_and():
if a > b and c > d:
print(1)
elif a == b:
print(2)
else:
print(3)
print("end")
def a_nofallthru2_if_or():
if a > b or c > d:
print(1)
print("end")
def b_nofallthru2_elif_or():
if a > b or c > d:
print(1)
elif a == b:
print(2)
print("end")
def c_nofallthru2_else_or():
if a > b or c > d:
print(1)
else:
print(2)
print("end")
def d_nofallthru2_elif_else_or():
if a > b or c > d:
print(1)
elif a == b:
print(2)
else:
print(3)
print("end")
def a_nofallthru3_if_not():
if not a > b:
print(1)
print("end")
def b_nofallthru3_elif_not():
if not a > b:
print(1)
elif a == b:
print(2)
print("end")
def c_nofallthru3_else_not():
if not a > b:
print(1)
else:
print(2)
print("end")
def d_nofallthru3_elif_else_not():
if not a > b:
print(1)
elif a == b:
print(2)
else:
print(3)
print("end")
def e_nofallthru_nested_if():
if a > b:
print(1)
if a == b:
print(2)
else:
print(3)
else:
print(4)
print("end")
def e_nofallthru_nested_else():
if a > b:
print(1)
else:
print(2)
if a == b:
print(3)
else:
print(4)
print("end")
def f_nofallthru_if_pass():
if a > b:
pass
print("end")
+66
View File
@@ -0,0 +1,66 @@
import asyncio
# Test 1: Simple async generator
async def gen1():
yield 1
yield 2
# Test 2: Async generator with await
async def gen2():
await asyncio.sleep(0)
yield "done"
# Test 3: Async generator using a loop
async def gen3():
for i in range(3):
yield i
# Test 4: Async generator with async for loop (consuming another async generator)
async def gen4():
async for x in gen3():
yield x
# Test 5: Async generator with async with
class DummyContext:
async def __aenter__(self): return self
async def __aexit__(self, exc_type, exc, tb): pass
async def gen5():
async with DummyContext():
yield "inside context"
# Test 6: Async generator that returns (implicitly ends)
async def gen6():
yield "hello"
return # Ends the generator
# Test 7: Nested yield and await
async def gen7():
yield await asyncio.sleep(0, result="nested")
# Test 8: Function using 'yield' but not 'async def' (should be a regular generator)
def regular_gen():
yield "normal generator"
# Test 9: Coroutine consuming async generator
async def consume_gen():
async for item in gen2():
pass
# Test 10: Calling an async generator (should return an async generator object)
g = gen1()
assert hasattr(g, '__anext__') # Just to test that it's an async generator object
# Test 11: Async generator with try/finally
async def gen11():
try:
yield "try"
finally:
await asyncio.sleep(0)
# Test 12: Async generator with exception handling
async def gen12():
try:
raise ValueError("fail")
except ValueError:
yield "handled"
+260
View File
@@ -0,0 +1,260 @@
# FOR LOOP TESTS
def a_for_over_list():
for x in [1, 2, 3]:
print("for over list")
def b_for_over_tuples():
for a, b in [(1, 2), (3, 4)]:
print("tuples")
def c_for_else():
for i in range(3):
print("for body")
else:
print("for else")
def d_for_with_break():
for x in range(10):
if x == 5:
print("breaking")
break
def e_for_with_continue():
for x in range(5):
if x % 2 == 0:
print("continuing")
continue
print("after continue")
def f_nested_for_loops():
for i in range(2):
for j in range(3):
print(f"nested {i},{j}")
def g_for_with_try_except():
for x in range(2):
try:
print("try block")
except Exception:
print("except block")
def h_for_with_with_statement():
for _ in range(1):
with a:
print("inside with")
def i_for_with_function_call_iterable():
def get_items():
return [1, 2, 3]
for item in get_items():
print(f"item: {item}")
def j_for_with_empty_body_ellipsis():
for _ in range(3): ...
def k_while_true_with_break():
while True:
print("while true")
break
def l_while_with_else():
i = 0
while i < 3:
print(f"looping {i}")
i += 1
else:
print("while else")
def m_while_with_continue():
i = 0
while i < 5:
i += 1
if i % 2 == 0:
print("continue")
continue
print("after continue")
def n_while_with_break():
i = 0
while True:
print("break in while")
break
def o_nested_while_loops():
i = 0
while i < 2:
j = 0
while j < 2:
print(f"nested while {i},{j}")
j += 1
i += 1
def p_while_with_try_except():
while True:
try:
print("try in while")
except:
print("except in while")
def q_while_with_with_statement():
while True:
with a:
print("inside while with")
def r_for_inside_while():
while True:
for x in [1, 2]:
print("for in while")
def s_while_inside_for():
for _ in range(1):
while True:
print("while in for")
break
def t_while_with_empty_body_ellipsis():
while True: ...
def a_nofallthru_for_over_list():
for x in [1, 2, 3]:
print("for over list")
print("end")
def b_nofallthru_for_over_tuples():
for a, b in [(1, 2), (3, 4)]:
print("tuples")
print("end")
def c_nofallthru_for_else():
for i in range(3):
print("for body")
else:
print("for else")
print("end")
def d_nofallthru_for_with_break():
for x in range(10):
if x == 5:
print("breaking")
break
print("end")
def e_nofallthru_for_with_continue():
for x in range(5):
if x % 2 == 0:
print("continuing")
continue
print("after continue")
print("end")
def f_nofallthru_nested_for_loops():
for i in range(2):
for j in range(3):
print(f"nested {i},{j}")
print("end")
def g_nofallthru_for_with_try_except():
for x in range(2):
try:
print("try block")
except Exception:
print("except block")
print("end")
def h_nofallthru_for_with_with_statement():
for _ in range(1):
with a:
print("inside with")
print("end")
def i_nofallthru_for_with_function_call_iterable():
def g_nofallthruet_items():
return [1, 2, 3]
for item in get_items():
print(f"item: {item}")
print("end")
def j_nofallthru_for_with_empty_body_ellipsis():
for _ in range(3): ...
print("end")
def k_nofallthru_while_true_with_break():
while True:
print("while true")
break
print("end")
def l_nofallthru_while_with_else():
i = 0
while i < 3:
print(f"looping {i}")
i += 1
else:
print("while else")
print("end")
def m_nofallthru_while_with_continue():
i = 0
while i < 5:
i += 1
if i % 2 == 0:
print("continue")
continue
print("after continue")
print("end")
def n_nofallthru_while_with_break():
i = 0
while True:
print("break in while")
break
print("end")
def o_nofallthru_nested_while_loops():
i = 0
while i < 2:
j = 0
while j < 2:
print(f"nested while {i},{j}")
j += 1
i += 1
print("end")
def p_nofallthru_while_with_try_except():
while True:
try:
print("try in while")
except:
print("except in while")
print("end")
def q_nofallthru_while_with_with_statement():
while True:
with a:
print("inside while with")
print("end")
def r_nofallthru_for_inside_while():
while True:
for x in [1, 2]:
print("for in while")
print("end")
def s_nofallthru_while_inside_for():
for _ in range(1):
while True:
print("while in for")
break
print("end")
def t_nofallthru_while_with_empty_body_ellipsis():
while True: ...
print("end")