Add formatting for MatchCase (#6360)

## Summary

This PR adds formatting support for `MatchCase` node with subs for the
`Pattern`
nodes.

## Test Plan

Added test cases for case node handling with comments, newlines.

resolves: #6299
This commit is contained in:
Dhruv Manilawala 2023-08-11 19:20:25 +05:30 committed by GitHub
parent 8b24238d19
commit c434bdd2bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 256 additions and 29 deletions

View file

@ -55,3 +55,56 @@ def foo():
match inside_func: # comment
case "bar":
pass
match newlines:
# case 1 leading comment
case "top level case comment with newlines": # case dangling comment
# pass leading comment
pass
# pass trailing comment
# case 2 leading comment
case "case comment with newlines" if foo == 2: # second
pass
case "one", "newline" if (foo := 1): # third
pass
case "two newlines":
pass
case "three newlines":
pass
case _:
pass
match long_lines:
case "this is a long line for if condition" if aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2: # comment
pass
case "this is a long line for if condition with parentheses" if (aaaaaaaaahhhhhhhh == 1 and bbbbbbaaaaaaaaaaa == 2): # comment
pass
case "named expressions aren't special" if foo := 1:
pass
case "named expressions aren't that special" if (foo := 1):
pass
case "but with already broken long lines" if (
aaaaaaahhhhhhhhhhh == 1 and
bbbbbbbbaaaaaahhhh == 2
): # another comment
pass