@@ -3272,6 +3272,9 @@ def test_invocation(self):
32723272 ('--no-type-comments' , '--no-type-comments' ),
32733273 ('-a' , '--include-attributes' ),
32743274 ('-i=4' , '--indent=4' ),
3275+ ('--feature-version=3.13' , '--feature-version=3.13' ),
3276+ ('-O=-1' , '--optimize=-1' ),
3277+ ('--show-empty' , '--show-empty' ),
32753278 )
32763279 self .set_source ('''
32773280 print(1, 2, 3)
@@ -3389,7 +3392,7 @@ def test_include_attributes_flag(self):
33893392 self .check_output (source , expect , flag )
33903393
33913394 def test_indent_flag (self ):
3392- # test 'python -m ast -i/--indent'
3395+ # test 'python -m ast -i/--indent 0 '
33933396 source = 'pass'
33943397 expect = '''
33953398 Module(
@@ -3400,6 +3403,96 @@ def test_indent_flag(self):
34003403 with self .subTest (flag = flag ):
34013404 self .check_output (source , expect , flag )
34023405
3406+ def test_feature_version_flag (self ):
3407+ # test 'python -m ast --feature-version 3.9/3.10'
3408+ source = '''
3409+ match x:
3410+ case 1:
3411+ pass
3412+ '''
3413+ expect = '''
3414+ Module(
3415+ body=[
3416+ Match(
3417+ subject=Name(id='x', ctx=Load()),
3418+ cases=[
3419+ match_case(
3420+ pattern=MatchValue(
3421+ value=Constant(value=1)),
3422+ body=[
3423+ Pass()])])])
3424+ '''
3425+ self .check_output (source , expect , '--feature-version=3.10' )
3426+ with self .assertRaises (SyntaxError ):
3427+ self .invoke_ast ('--feature-version=3.9' )
3428+
3429+ def test_no_optimize_flag (self ):
3430+ # test 'python -m ast -O/--optimize -1/0'
3431+ source = '''
3432+ match a:
3433+ case 1+2j:
3434+ pass
3435+ '''
3436+ expect = '''
3437+ Module(
3438+ body=[
3439+ Match(
3440+ subject=Name(id='a', ctx=Load()),
3441+ cases=[
3442+ match_case(
3443+ pattern=MatchValue(
3444+ value=BinOp(
3445+ left=Constant(value=1),
3446+ op=Add(),
3447+ right=Constant(value=2j))),
3448+ body=[
3449+ Pass()])])])
3450+ '''
3451+ for flag in ('-O=-1' , '--optimize=-1' , '-O=0' , '--optimize=0' ):
3452+ with self .subTest (flag = flag ):
3453+ self .check_output (source , expect , flag )
3454+
3455+ def test_optimize_flag (self ):
3456+ # test 'python -m ast -O/--optimize 1/2'
3457+ source = '''
3458+ match a:
3459+ case 1+2j:
3460+ pass
3461+ '''
3462+ expect = '''
3463+ Module(
3464+ body=[
3465+ Match(
3466+ subject=Name(id='a', ctx=Load()),
3467+ cases=[
3468+ match_case(
3469+ pattern=MatchValue(
3470+ value=Constant(value=(1+2j))),
3471+ body=[
3472+ Pass()])])])
3473+ '''
3474+ for flag in ('-O=1' , '--optimize=1' , '-O=2' , '--optimize=2' ):
3475+ with self .subTest (flag = flag ):
3476+ self .check_output (source , expect , flag )
3477+
3478+ def test_show_empty_flag (self ):
3479+ # test 'python -m ast --show-empty'
3480+ source = 'print(1, 2, 3)'
3481+ expect = '''
3482+ Module(
3483+ body=[
3484+ Expr(
3485+ value=Call(
3486+ func=Name(id='print', ctx=Load()),
3487+ args=[
3488+ Constant(value=1),
3489+ Constant(value=2),
3490+ Constant(value=3)],
3491+ keywords=[]))],
3492+ type_ignores=[])
3493+ '''
3494+ self .check_output (source , expect , '--show-empty' )
3495+
34033496
34043497class ASTOptimiziationTests (unittest .TestCase ):
34053498 def wrap_expr (self , expr ):
0 commit comments