Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: cobalt <61329810+cobaltt7@users.noreply.github.com>
  • Loading branch information
cobaltt7 committed Nov 10, 2024
1 parent 42864d7 commit c87d237
Show file tree
Hide file tree
Showing 3 changed files with 326 additions and 83 deletions.
1 change: 1 addition & 0 deletions src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ def maybe_make_parens_invisible_in_atom(
if first.prefix.strip():
# Preserve comments before first paren
middle.prefix = first.prefix + middle.prefix
first.prefix = ""
last.value = ""
maybe_make_parens_invisible_in_atom(
middle,
Expand Down
162 changes: 79 additions & 83 deletions tests/data/cases/preview_remove_lone_list_item_parens.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,81 @@
# flags: --unstable
# flags: --preview
items = [(123)]
items = [(True)]
items = [(((((True)))))]
items = [(((((True,)))))]
items = [((((()))))]
items = [(x for x in [1])]

# Requires `hug_parens_with_braces_and_square_brackets` unstable style to remove parentheses
# around multiline values
items = [
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
),
]
items = [
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
]
items = [
(
{"key1": "val1", "key2": "val2"}
if some_var == ""
else {"key": "val"}
)
]
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}]

# Comments should not cause crashes
items = [
(
"123456890123457890123468901234567890"
( # comment
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else "123467890123467890"
else {"key": "val"}
)
]

items = [
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
and some_var == "long strings"
and {"key": "val"}
)
if some_var == "long strings"
else {"key": "val"}
) # comment
]
items = [

items = [ # comment
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
and some_var == "long strings"
and {"key": "val"}
),
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
"123456890123457890123468901234567890"
and some_var == "long strings"
and "123467890123467890"
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
] # comment

items = [
(
"123456890123457890123468901234567890"
and some_var == "long strings"
and "123467890123467890"
),
{"key1": "val1", "key2": "val2", "key3": "val3"} # comment
if some_var == "long strings"
else {"key": "val"}
)
]

items = [
(
long_variable_name
and even_longer_variable_name
and yet_another_very_long_variable_name
items = [ # comment
( # comment
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
long_variable_name
and even_longer_variable_name
and yet_another_very_long_variable_name
),
]
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
) # comment
] # comment


# output
Expand All @@ -91,66 +84,69 @@
items = [True]
items = [(True,)]
items = [()]
items = [(x for x in [1])]

items = [
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
]
# Requires `hug_parens_with_braces_and_square_brackets` unstable style to remove parentheses
# around multiline values
items = [
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
),
]
items = [
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}]
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}]
items = [
"123456890123457890123468901234567890"
if some_var == "long strings"
else "123467890123467890"
]

# Comments should not cause crashes
items = [
{"key1": "val1", "key2": "val2", "key3": "val3"}
and some_var == "long strings"
and {"key": "val"}
( # comment
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
and some_var == "long strings"
and {"key": "val"}
),
if some_var == "long strings"
else {"key": "val"}
) # comment
]
items = [
"123456890123457890123468901234567890"
and some_var == "long strings"
and "123467890123467890"

items = [ # comment
(
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
"123456890123457890123468901234567890"
and some_var == "long strings"
and "123467890123467890"
),
]
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
] # comment

items = [
long_variable_name
and even_longer_variable_name
and yet_another_very_long_variable_name
(
{"key1": "val1", "key2": "val2", "key3": "val3"} # comment
if some_var == "long strings"
else {"key": "val"}
)
]

items = [ # comment
( # comment
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
)
]
items = [
(
long_variable_name
and even_longer_variable_name
and yet_another_very_long_variable_name
),
]
{"key1": "val1", "key2": "val2", "key3": "val3"}
if some_var == "long strings"
else {"key": "val"}
) # comment
] # comment
Loading

0 comments on commit c87d237

Please sign in to comment.