Updating test cases & documentation

This commit is contained in:
Xinlong Hu
2025-07-11 19:24:19 -05:00
committed by Joel-Flores123
parent b8e0c934fb
commit f681d4d05f
3 changed files with 262 additions and 156 deletions
+96 -117
View File
@@ -1,12 +1,18 @@
def a_TryExcept():
def a0_bare_try_except():
try:
print(1)
except:
print(2)
def a1_bare_try_except_fallthrough():
try:
print(1)
except:
print(2)
print(3)
def b_TryExceptBareNested():
# 3.11/3.12/3.13 Duplicate blocks causing blocks to not match
def b0_nested_try_except():
try:
print(1)
except:
@@ -16,8 +22,7 @@ def b_TryExceptBareNested():
except:
print(4)
def b1_TryExceptBareNestedFallthrough():
def b1_nested_try_except_fallthrough():
try:
print(1)
except:
@@ -28,8 +33,8 @@ def b1_TryExceptBareNestedFallthrough():
print(4)
print(5)
def b2_TryExceptBareNestedEarlyFallthrough():
# 3.13 Duplicate blocks
def b2_nested_try_except_early_fallthrough():
try:
print(1)
except:
@@ -40,8 +45,7 @@ def b2_TryExceptBareNestedEarlyFallthrough():
print(4)
print(5)
def b3_TryExceptBareNestedDoubleFallthrough():
def b3_nested_try_except_double_fallthrough():
try:
print(1)
except:
@@ -53,8 +57,8 @@ def b3_TryExceptBareNestedDoubleFallthrough():
print(5)
print(6)
def c_TryExceptBareMultiNested():
# 3.11/3.12/3.13 Duplicate blocks causing blocks to not match
def c0_multi_except_nested():
try:
print(1)
except a:
@@ -70,8 +74,8 @@ def c_TryExceptBareMultiNested():
except:
print(7)
def c1_TryExceptBareMultiNestedFallthrough():
# 3.11/3.12/3.13 Duplicate blocks causing blocks to not match
def c1_multi_except_nested_fallthrough():
try:
print(1)
except a:
@@ -88,8 +92,7 @@ def c1_TryExceptBareMultiNestedFallthrough():
except:
print(8)
def c2_TryExceptBareMultiNestedFallthrough2():
def c2_multi_except_nested_fallthrough2():
try:
print(1)
except a:
@@ -107,8 +110,8 @@ def c2_TryExceptBareMultiNestedFallthrough2():
print(8)
print(9)
def c3_TryExceptBareMultiNestedEarlyFallthrough():
# 3.13 Duplicate blocks
def c3_multi_except_nested_early_fallthrough():
try:
print(1)
except a:
@@ -125,8 +128,7 @@ def c3_TryExceptBareMultiNestedEarlyFallthrough():
print(7)
print(8)
def c4_TryExceptBareMultiNestedAllFallthrough():
def c4_multi_except_nested_all_fallthrough():
try:
print(1)
except a:
@@ -145,8 +147,9 @@ def c4_TryExceptBareMultiNestedAllFallthrough():
print(9)
print(10)
def d_TryExceptBareNestedNamed():
# 3.10/3.11/3.12/3.13 Duplicate blocks causing templates to not match
# Discussed in issue 41
def d0_named_except_nested():
try:
print(1)
except A as a:
@@ -156,8 +159,7 @@ def d_TryExceptBareNestedNamed():
except:
print(4)
def d1_TryExceptBareNestedNamedFallthrough():
def d1_named_except_nested_fallthrough():
try:
print(1)
except A as a:
@@ -168,8 +170,8 @@ def d1_TryExceptBareNestedNamedFallthrough():
print(4)
print(5)
def d2_TryExceptBareNestedNamedEarlyFallthrough():
# 3.13 Duplicate blocks
def d2_named_except_nested_early_fallthrough():
try:
print(1)
except A as a:
@@ -180,8 +182,7 @@ def d2_TryExceptBareNestedNamedEarlyFallthrough():
print(4)
print(5)
def d3_TryExceptBareNestedNamedDoubleFallthrough():
def d3_named_except_nested_double_fallthrough():
try:
print(1)
except A as a:
@@ -193,8 +194,7 @@ def d3_TryExceptBareNestedNamedDoubleFallthrough():
print(5)
print(6)
def e_TryExceptElseBare():
def e0_try_except_else():
try:
print(1)
except:
@@ -203,8 +203,7 @@ def e_TryExceptElseBare():
print(3)
print(4)
def f_TryExceptElseFinallyBare():
def f0_try_except_else_finally():
try:
print(1)
except:
@@ -215,8 +214,7 @@ def f_TryExceptElseFinallyBare():
print(4)
print(5)
def g_TryExceptElseMulti():
def g0_multi_except_with_else():
try:
print(1)
except a:
@@ -227,8 +225,7 @@ def g_TryExceptElseMulti():
print(4)
print(5)
def h_TryExceptElseMultiFallback():
def h0_multi_except_fallback_with_else():
try:
print(1)
except a:
@@ -241,8 +238,7 @@ def h_TryExceptElseMultiFallback():
print(5)
print(6)
def i_TryExceptElseMultiNamedAndUnnamed():
def i0_mixed_named_unnamed_except_with_else():
try:
print(1)
except A as a:
@@ -255,8 +251,7 @@ def i_TryExceptElseMultiNamedAndUnnamed():
print(5)
print(6)
def j_TryExceptElseNamed():
def j0_named_except_with_else():
try:
print(1)
except A as a:
@@ -267,8 +262,7 @@ def j_TryExceptElseNamed():
print(4)
print(5)
def k_TryExceptFinallyBare():
def k0_try_except_finally():
try:
print(1)
except:
@@ -277,8 +271,7 @@ def k_TryExceptFinallyBare():
print(3)
print(4)
def l_TryExceptFinallyBareSpecific():
def l0_specific_except_finally():
try:
print(1)
except a:
@@ -287,8 +280,7 @@ def l_TryExceptFinallyBareSpecific():
print(3)
print(4)
def m_TryExceptMulti():
def m0_multi_except():
try:
print(1)
except a:
@@ -299,8 +291,7 @@ def m_TryExceptMulti():
print(4)
print(5)
def n_TryExceptMultiFallback():
def n0_multi_except_with_fallback():
try:
print(1)
except a:
@@ -311,8 +302,7 @@ def n_TryExceptMultiFallback():
print(4)
print(5)
def o_TryExceptMultiFallbackFinally():
def o0_multi_except_fallback_finally():
try:
print(1)
except a:
@@ -323,8 +313,7 @@ def o_TryExceptMultiFallbackFinally():
print(4)
print(5)
def p_TryExceptMultiNamed():
def p0_multi_named_except():
try:
print(1)
except A as a:
@@ -335,8 +324,7 @@ def p_TryExceptMultiNamed():
print(4)
print(5)
def q_TryExceptMultiNamedAndUnnamed():
def q0_mixed_named_unnamed_except():
try:
print(1)
except A as a:
@@ -347,8 +335,7 @@ def q_TryExceptMultiNamedAndUnnamed():
print(4)
print(5)
def r_TryExceptMultiNamedAndUnnamedFinally():
def r0_mixed_named_unnamed_except_finally():
try:
print(1)
except A as a:
@@ -361,8 +348,7 @@ def r_TryExceptMultiNamedAndUnnamedFinally():
print(5)
print(6)
def s_TryExceptMultiNamedFallback():
def s0_named_except_fallback():
try:
print(1)
except A as a:
@@ -371,8 +357,7 @@ def s_TryExceptMultiNamedFallback():
print(3)
print(4)
def t_TryExceptMultiNamedFallbackFinally():
def t0_named_except_fallback_finally():
try:
print(1)
except A as a:
@@ -383,8 +368,7 @@ def t_TryExceptMultiNamedFallbackFinally():
print(4)
print(5)
def u_TryExceptMultiNamedFinally():
def u0_multi_named_except_finally():
try:
print(1)
except A as a:
@@ -395,8 +379,7 @@ def u_TryExceptMultiNamedFinally():
print(4)
print(5)
def v_TryExceptMultiFinally():
def v0_multi_except_finally():
try:
print(1)
except a:
@@ -407,16 +390,14 @@ def v_TryExceptMultiFinally():
print(4)
print(5)
def w_TryExceptRaise():
def w0_try_except_raise():
try:
print(1)
except:
print(2)
raise Exc
def x_TryExceptRaiseMulti():
def x0_multi_except_raise():
try:
print(1)
except a:
@@ -426,24 +407,23 @@ def x_TryExceptRaiseMulti():
print(3)
raise Exc
def y_TryExceptRaiseNamed():
def y0_named_except_raise():
try:
print(1)
except A as a:
print(2)
raise Exc
def z_TryExceptReturn():
# 3.11 Try return getting left outside of TryExcept
def z0_try_except_return():
try:
print(1)
return 2
except:
print(2)
def z1_TryExceptReturn():
# 3.11 Try return getting left outside of TryExcept
def z1_try_except_return_both():
try:
print(1)
return 2
@@ -451,8 +431,8 @@ def z1_TryExceptReturn():
print(2)
return 3
def aa_TryExceptReturnMulti():
# 3.11 Try return getting left outside of TryExcept
def aa0_multi_except_return():
try:
print(1)
return 2
@@ -461,8 +441,10 @@ def aa_TryExceptReturnMulti():
except b:
print(3)
def aa1_TryExceptReturnMulti():
# 3.6/3.7/3.8 ExceptExc abandons tail node.
# Could be fixed (?) but breaks other test cases
# 3.11 Try return getting left outside of TryExcept
def aa1_multi_except_return_both():
try:
print(1)
return 2
@@ -472,8 +454,8 @@ def aa1_TryExceptReturnMulti():
except b:
print(3)
def ab_TryExceptReturnNamed():
# 3.11 Try return getting left outside of TryExcept
def ab0_named_except_raise_return():
try:
print(1)
return 2
@@ -484,15 +466,24 @@ def ab_TryExceptReturnNamed():
print(3)
raise Exc
# 3.8 Double natural edge graph error (?)
# 3.11 Try return getting left outside of TryExcept
def ab1_named_except_return():
try:
print(1)
return 2
except A as a:
print(2)
return 3
def TryEmptryFinally():
# 3.11/3.12/3.13 No template match
def ac0_empty_try_finally():
try:
pass
finally:
print(1)
def TryMultiple():
def ad0_multiple_try_blocks():
try:
print(1)
except:
@@ -503,8 +494,8 @@ def TryMultiple():
except:
print(4)
def TryExceptElseTry():
# 3.10/3.11 Try matching before TryElse
def ae0_try_except_else_nested_try():
try:
print(1)
except:
@@ -515,8 +506,9 @@ def TryExceptElseTry():
except:
print(4)
def TryFinallyNestedExcept():
# 3.9 Duplicate blocks (?)
# 3.11/3.12/3.13 Matching priority TryElse TryFinally (?)
def af0_try_finally_nested_except():
try:
print(1)
finally:
@@ -525,45 +517,44 @@ def TryFinallyNestedExcept():
except:
print(3)
def TryExceptTuple():
def ag0_try_except_tuple():
try:
print(1)
except (A, B):
print(2)
def TryFinallyReturn():
# 3.9 Difficult template ambiguity between Try/TryFinally
# 3.11/3.12/3.13 Matching priority TryElse TryFinally (?)
def ah0_try_finally_return():
try:
print(1)
finally:
return 2
def TryReturnFinally():
# 3.11/3.12/3.13 No template match (?)
def ai0_try_return_finally():
try:
return 1
finally:
print(2)
def TryReturnFinallyReturn():
# 3.9/3.10 Difficult template ambiguity between Try/TryFinally
# 3.11/3.12/3.13 No template match (?)
def aj0_try_return_finally_return():
try:
return 1
finally:
return 2
def TryExceptRaise():
def ak0_try_except_raise_return():
try:
print(1)
return 2
except:
raise Exception()
"""
def TryExceptReturnFinally():
# 3.8/3.9/3.10 No template match
def al0_try_except_return_finally():
try:
raise Exception()
except:
@@ -571,37 +562,25 @@ def TryExceptReturnFinally():
return 2
finally:
print(3)
"""
"""
def TryFinallyRaise():
# 3.8/3.9/3.10 No template match
# 3.11/3.12/3.13 Matching priority TryElse TryFinally (?)
def am0_try_finally_raise():
try:
print(1)
return 2
finally:
raise Exception()
"""
def ab1_TryExceptReturnNamed():
try:
print(1)
return 2
except A as a:
print(2)
return 3
def ac_TryFinallyBareFallthrough():
def an0_try_finally_fallthrough():
try:
print(1)
finally:
print(2)
print(3)
def ad_TryFinallyBare():
def ao0_try_finally_simple():
try:
print(1)
finally:
print(2)
print(2)
+149 -22
View File
@@ -1,4 +1,4 @@
def a_for_over_list():
def a0_for_over_list():
for x in [1, 2, 3]:
print("for over list")
@@ -7,7 +7,7 @@ def a1_for_over_list_nofallthru():
print("for over list")
print("end")
def b_for_over_tuples():
def b0_for_over_tuples():
for a, b in [(1, 2), (3, 4)]:
print("tuples")
@@ -16,7 +16,7 @@ def b1_for_over_tuples_nofallthru():
print("tuples")
print("end")
def c_for_else():
def c0_for_else():
for i in range(3):
print("for body")
else:
@@ -29,12 +29,14 @@ def c1_for_else_nofallthru():
print("for else")
print("end")
def d_for_with_break():
# Fails due to no break
def d0_for_with_break():
for x in range(10):
if x == 5:
print("breaking")
break
# Fails due to no break
def d1_for_with_break_nofallthru():
for x in range(10):
if x == 5:
@@ -42,7 +44,22 @@ def d1_for_with_break_nofallthru():
break
print("end")
def e_for_with_continue():
# Help to implement break
def d2_for_without_break():
for x in range(10):
if x == 5:
print("not breaking")
print("end")
# Help to implement break
def d3_for_return():
for x in range(10):
if x == 5:
print("not breaking")
return
print("end")
def e0_for_with_continue():
for x in range(5):
if x % 2 == 0:
print("continuing")
@@ -57,7 +74,7 @@ def e1_for_with_continue_nofallthru():
print("after continue")
print("end")
def f_nested_for_loops():
def f0_nested_for_loops():
for i in range(2):
for j in range(3):
print(f"nested {i},{j}")
@@ -68,7 +85,7 @@ def f1_nested_for_loops_nofallthru():
print(f"nested {i},{j}")
print("end")
def g_for_with_try_except():
def g0_for_with_try_except():
for x in range(2):
try:
print("try block")
@@ -83,7 +100,7 @@ def g1_for_with_try_except_nofallthru():
print("except block")
print("end")
def h_for_with_with_statement():
def h0_for_with_with_statement():
for _ in range(1):
with a:
print("inside with")
@@ -94,7 +111,7 @@ def h1_for_with_with_statement_nofallthru():
print("inside with")
print("end")
def i_for_with_function_call_iterable():
def i0_for_with_function_call_iterable():
def get_items():
return [1, 2, 3]
@@ -109,7 +126,7 @@ def i1_for_with_function_call_iterable_nofallthru():
print(f"item: {item}")
print("end")
def j_for_with_empty_body_ellipsis():
def j0_for_with_empty_body_ellipsis():
for _ in range(3):
...
@@ -118,18 +135,24 @@ def j1_for_with_empty_body_ellipsis_nofallthru():
...
print("end")
def k_while_true_with_break():
def k0_while_true_with_break():
x = 0
while True:
print("while true")
break
x += 1
if x >= 1:
break
def k1_while_true_with_break_nofallthru():
x = 0
while True:
print("while true")
break
x += 1
if x >= 1:
break
print("end")
def l_while_with_else():
def l0_while_with_else():
i = 0
while i < 3:
print(f"looping {i}")
@@ -146,7 +169,7 @@ def l1_while_with_else_nofallthru():
print("while else")
print("end")
def m_while_with_continue():
def m0_while_with_continue():
i = 0
while i < 5:
i += 1
@@ -165,7 +188,7 @@ def m1_while_with_continue_nofallthru():
print("after continue")
print("end")
def n_while_with_break():
def n0_while_with_break():
i = 0
while True:
print("break in while")
@@ -178,7 +201,7 @@ def n1_while_with_break_nofallthru():
break
print("end")
def o_nested_while_loops():
def o0_nested_while_loops():
i = 0
while i < 2:
j = 0
@@ -197,7 +220,7 @@ def o1_nested_while_loops_nofallthru():
i += 1
print("end")
def p_while_with_try_except():
def p0_while_with_try_except():
while True:
try:
print("try in while")
@@ -212,7 +235,7 @@ def p1_while_with_try_except_nofallthru():
print("except in while")
print("end")
def q_while_with_with_statement():
def q0_while_with_with_statement():
while True:
with a:
print("inside while with")
@@ -223,7 +246,7 @@ def q1_while_with_with_statement_nofallthru():
print("inside while with")
print("end")
def r_for_inside_while():
def r0_for_inside_while():
while True:
for x in [1, 2]:
print("for in while")
@@ -234,7 +257,7 @@ def r1_for_inside_while_nofallthru():
print("for in while")
print("end")
def s_while_inside_for():
def s0_while_inside_for():
for _ in range(1):
while True:
print("while in for")
@@ -247,11 +270,115 @@ def s1_while_inside_for_nofallthru():
break
print("end")
def t_while_with_empty_body_ellipsis():
def t0_while_with_empty_body_ellipsis():
while True:
...
def t1_while_with_empty_body_ellipsis_nofallthru():
while True:
...
print("end")
def u0_break_in_nested_for():
for i in range(3):
for j in range(3):
if i == 1 and j == 1:
print("Breaking inner loop")
break
print(f"i={i}, j={j}")
def u1_break_in_nested_for_nofallthru():
for i in range(3):
for j in range(3):
if i == 1 and j == 1:
print("Breaking inner loop")
break
print(f"i={i}, j={j}")
print("end")
def v0_continue_in_nested_for():
for i in range(3):
for j in range(3):
if j == 1:
continue
print(f"Processing i={i}, j={j}")
def v1_continue_in_nested_for_nofallthru():
for i in range(3):
for j in range(3):
if j == 1:
continue
print(f"Processing i={i}, j={j}")
print("end")
def w0_break_with_else():
for i in range(5):
if i == 3:
print("Breaking before else")
break
else:
print("This won't execute due to break")
def w1_break_with_else_nofallthru():
for i in range(5):
if i == 3:
print("Breaking before else")
break
else:
print("This won't execute due to break")
print("end")
def x0_continue_with_else():
for i in range(3):
if i == 1:
continue
print(f"Processing {i}")
else:
print("Else clause still executes after continue")
def x1_continue_with_else_nofallthru():
for i in range(3):
if i == 1:
continue
print(f"Processing {i}")
else:
print("Else clause still executes after continue")
print("end")
def y0_break_in_try_except():
for i in range(5):
try:
if i == 3:
break
print(f"Value: {i}")
except:
print("Exception occurred")
def y1_break_in_try_except_nofallthru():
for i in range(5):
try:
if i == 3:
break
print(f"Value: {i}")
except:
print("Exception occurred")
print("end")
def z0_continue_in_try_except():
for i in range(5):
try:
if i == 2:
continue
print(f"Value: {i}")
except:
print("Exception occurred")
def z1_continue_in_try_except_nofallthru():
for i in range(5):
try:
if i == 2:
continue
print(f"Value: {i}")
except:
print("Exception occurred")
print("end")
+17 -17
View File
@@ -1,4 +1,4 @@
def a_bare_with():
def a0_bare_with():
with a:
print(1)
@@ -8,7 +8,7 @@ def a1_bare_with_fallthrough():
print(2)
# Fails in 3.10, duplicate blocks explained further in issue 32
def b_multi_with():
def b0_multi_with():
with a, b:
print(1)
@@ -17,7 +17,7 @@ def b1_multi_with_fallthrough():
print(1)
print(2)
def c_with_as():
def c0_with_as():
with a as c:
print(1)
@@ -27,7 +27,7 @@ def c1_with_as_fallthrough():
print(2)
# Fails in 3.10, same issue as b
def d_multi_with_as():
def d0_multi_with_as():
with a, b as c:
print(1)
@@ -37,7 +37,7 @@ def d1_multi_with_as_fallthrough():
print(2)
# Fails in 3.10, same issue as b
def e_with_multi_as():
def e0_with_multi_as():
with a as b, c:
print(1)
@@ -47,7 +47,7 @@ def e1_with_multi_as_fallthrough():
print(2)
# Fails in 3.10, same issue as b
def f_multi_with_multi_as():
def f0_multi_with_multi_as():
with a as b, c as d:
print(1)
@@ -57,7 +57,7 @@ def f1_multi_with_multi_as_fallthrough():
print(2)
# Fails in 3.10, same issue as b
def g_multi_with_multi_as_alt():
def g0_multi_with_multi_as_alt():
with a, b as c, d:
print(1)
@@ -67,7 +67,7 @@ def g1_multi_with_multi_as_fallthrough_alt():
print(2)
# Fails in 3.13, unexpected JUMP_BACKWARD_NO_INTERRUPT messes up the template
def h_try_with_except():
def h0_try_with_except():
try:
with a:
print(1)
@@ -75,17 +75,17 @@ def h_try_with_except():
print(2)
print(3)
def i_with_return():
def i0_with_return():
with a:
return 1
print(1)
def j_with_raise():
def j0_with_raise():
with a:
raise Exc
print(1)
async def k_bare_async_with():
async def k0_bare_async_with():
async with a:
print(1)
@@ -94,7 +94,7 @@ async def k1_bare_async_with_fallthrough():
print(1)
print(2)
async def l_multi_async_with():
async def l0_multi_async_with():
async with a, b:
print(1)
@@ -103,7 +103,7 @@ async def l1_multi_async_with_fallthrough():
print(1)
print(2)
async def m_async_with_as():
async def m0_async_with_as():
async with a as c:
print(1)
@@ -112,7 +112,7 @@ async def m1_async_with_as_fallthrough():
print(1)
print(2)
async def n_multi_async_with_as():
async def n0_multi_async_with_as():
async with a, b as c:
print(1)
@@ -121,7 +121,7 @@ async def n1_multi_async_with_as_fallthrough():
print(1)
print(2)
async def o_async_with_multi_as():
async def o0_async_with_multi_as():
async with a as b, c:
print(1)
@@ -130,7 +130,7 @@ async def o1_async_with_multi_as_fallthrough():
print(1)
print(2)
async def p_multi_async_with_multi_as():
async def p0_multi_async_with_multi_as():
async with a as b, c as d:
print(1)
@@ -139,7 +139,7 @@ async def p1_multi_async_with_multi_as_fallthrough():
print(1)
print(2)
async def q_multi_async_with_multi_as_alt():
async def q0_multi_async_with_multi_as_alt():
async with a, b as c, d:
print(1)