Skip to content

Commit

Permalink
mformat: A triple string with a ' in it cannot be simplified
Browse files Browse the repository at this point in the history
The following is valid meson:
```meson
a = '''This string can't be simplified'''
```
which cannot be simplified because of the `'` in it, as
```meson
a = 'This string can't be simplified'
```
Is invalid.

Potentially we could convert that with escapes, but it seems reasonable
to me to leave this, since it may be desirable to not have lots of
escapes in a string. `'''I can't believe it's her's!'''` is much more
readable than `'I can\'t believe it\'s her\'s!'`, for example.

Closes: #13564
(cherry picked from commit df70680)
  • Loading branch information
dcbaker authored and eli-schwartz committed Sep 16, 2024
1 parent c7031bd commit b429aa4
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/mformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def visit_StringNode(self, node: mparser.StringNode) -> None:
self.enter_node(node)

if self.config.simplify_string_literals:
if node.is_multiline and '\n' not in node.value:
if node.is_multiline and not any(x in node.value for x in ['\n', "'"]):
node.is_multiline = False
node.value = node.escape()

Expand Down
1 change: 1 addition & 0 deletions test cases/format/5 transform/default.expected.meson
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'This is not a multiline'
'This is not a fstring'
'''This isn't convertible'''

# group arg value
arguments = [
Expand Down
1 change: 1 addition & 0 deletions test cases/format/5 transform/muon.expected.meson
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'''This is not a multiline'''
f'This is not a fstring'
'''This isn't convertible'''

# group arg value
arguments = [
Expand Down
1 change: 1 addition & 0 deletions test cases/format/5 transform/options.expected.meson
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ d = {
# string conversion
'This is not a multiline'
'This is not a fstring'
'''This isn't convertible'''

# group arg value
arguments = [
Expand Down
1 change: 1 addition & 0 deletions test cases/format/5 transform/source.meson
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ d = {'a': 1, 'b': 2, 'c': 3}
# string conversion
'''This is not a multiline'''
f'This is not a fstring'
'''This isn't convertible'''

# group arg value
arguments = ['a', '--opt_a', 'opt_a_value', 'b', 'c', '--opt_d', '--opt_e', 'opt_e_value',
Expand Down

0 comments on commit b429aa4

Please sign in to comment.