-
Notifications
You must be signed in to change notification settings - Fork 882
/
string.py
140 lines (106 loc) · 2.71 KB
/
string.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"' test"
'" test'
"\" test"
'\' test'
# Prefer single quotes for string with more double quotes
"' \" \" '' \" \" '"
# Prefer double quotes for string with more single quotes
'\' " " \'\' " " \''
# Prefer double quotes for string with equal amount of single and double quotes
'" \' " " \'\''
"' \" '' \" \""
"\\' \"\""
'\\\' ""'
u"Test"
U"Test"
r"Test"
R"Test"
# Block conversion if there is an unescaped quote just before the end of the triple
# quoted string
r'''\""'''
r'''""'''
r'\""'
'This string will not include \
backslashes or newline characters.'
if True:
'This string will not include \
backslashes or newline characters.'
"""Multiline
String \"
"""
'''Multiline
String \'
'''
'''Multiline
String ""
'''
'''Multiline
String """
'''
'''Multiline
String "'''
"""Multiline
String '''
"""
"""Multiline
String '"""
'''Multiline
String \"\"\"
'''
# String continuation
"Let's" "start" "with" "a" "simple" "example"
"Let's" "start" "with" "a" "simple" "example" "now repeat after me:" "I am confident" "I am confident" "I am confident" "I am confident" "I am confident"
(
"Let's" "start" "with" "a" "simple" "example" "now repeat after me:" "I am confident" "I am confident" "I am confident" "I am confident" "I am confident"
)
if (
a + "Let's"
"start"
"with"
"a"
"simple"
"example"
"now repeat after me:"
"I am confident"
"I am confident"
"I am confident"
"I am confident"
"I am confident"
):
pass
if "Let's" "start" "with" "a" "simple" "example" "now repeat after me:" "I am confident" "I am confident" "I am confident" "I am confident" "I am confident":
pass
(
# leading
"a" # trailing part comment
# leading part comment
"b" # trailing second part comment
# trailing
)
test_particular = [
# squares
'1.00000000100000000025',
'1.0000000000000000000000000100000000000000000000000' #...
'00025',
'1.0000000000000000000000000000000000000000000010000' #...
'0000000000000000000000000000000000000000025',
]
# Parenthesized string continuation with messed up indentation
{
"key": (
[],
'a'
'b'
'c'
)
}
# Regression test for https://github.com/astral-sh/ruff/issues/5893
x = ("""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""" """bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb""")
x = (f"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""" f"""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb""")
x = (b"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""" b"""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb""")
# https://github.com/astral-sh/ruff/issues/7460
trailing_preferred_quote_texts = [''' "''', ''' ""''', ''' """''', ''' """"''']
a = f"""\x1F"""
a = """\x1F"""
a = """\\x1F"""
a = """\\\x1F"""