mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Format bytes string (#6166)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Format bytes string Closes #6064 ## Test Plan Added a fixture based on string's one
This commit is contained in:
parent
de898c52eb
commit
b95fc6d162
9 changed files with 577 additions and 89 deletions
8
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/bytes.options.json
vendored
Normal file
8
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/bytes.options.json
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
[
|
||||
{
|
||||
"quote_style": "double"
|
||||
},
|
||||
{
|
||||
"quote_style": "single"
|
||||
}
|
||||
]
|
120
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/bytes.py
vendored
Normal file
120
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/bytes.py
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
b"' test"
|
||||
b'" test'
|
||||
|
||||
b"\" test"
|
||||
b'\' test'
|
||||
|
||||
# Prefer single quotes for string with more double quotes
|
||||
b"' \" \" '' \" \" '"
|
||||
|
||||
# Prefer double quotes for string with more single quotes
|
||||
b'\' " " \'\' " " \''
|
||||
|
||||
# Prefer double quotes for string with equal amount of single and double quotes
|
||||
b'" \' " " \'\''
|
||||
b"' \" '' \" \""
|
||||
|
||||
b"\\' \"\""
|
||||
b'\\\' ""'
|
||||
|
||||
|
||||
b"Test"
|
||||
B"Test"
|
||||
|
||||
rb"Test"
|
||||
Rb"Test"
|
||||
|
||||
b'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
if True:
|
||||
b'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
b"""Multiline
|
||||
String \"
|
||||
"""
|
||||
|
||||
b'''Multiline
|
||||
String \'
|
||||
'''
|
||||
|
||||
b'''Multiline
|
||||
String ""
|
||||
'''
|
||||
|
||||
b'''Multiline
|
||||
String """
|
||||
'''
|
||||
|
||||
b'''Multiline
|
||||
String "'''
|
||||
|
||||
b"""Multiline
|
||||
String '''
|
||||
"""
|
||||
|
||||
b"""Multiline
|
||||
String '"""
|
||||
|
||||
b'''Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
|
||||
# String continuation
|
||||
|
||||
b"Let's" b"start" b"with" b"a" b"simple" b"example"
|
||||
|
||||
b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident"
|
||||
|
||||
(
|
||||
b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident"
|
||||
)
|
||||
|
||||
if (
|
||||
a + b"Let's"
|
||||
b"start"
|
||||
b"with"
|
||||
b"a"
|
||||
b"simple"
|
||||
b"example"
|
||||
b"now repeat after me:"
|
||||
b"I am confident"
|
||||
b"I am confident"
|
||||
b"I am confident"
|
||||
b"I am confident"
|
||||
b"I am confident"
|
||||
):
|
||||
pass
|
||||
|
||||
if b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident":
|
||||
pass
|
||||
|
||||
(
|
||||
# leading
|
||||
b"a" # trailing part comment
|
||||
|
||||
# leading part comment
|
||||
|
||||
b"b" # trailing second part comment
|
||||
# trailing
|
||||
)
|
||||
|
||||
test_particular = [
|
||||
# squares
|
||||
b'1.00000000100000000025',
|
||||
b'1.0000000000000000000000000100000000000000000000000' #...
|
||||
b'00025',
|
||||
b'1.0000000000000000000000000000000000000000000010000' #...
|
||||
b'0000000000000000000000000000000000000000025',
|
||||
]
|
||||
|
||||
# Parenthesized string continuation with messed up indentation
|
||||
{
|
||||
"key": (
|
||||
[],
|
||||
b'a'
|
||||
b'b'
|
||||
b'c'
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue