Skip to content

Commit 6270492

Browse files
committed
block_string: print multi line for trailing backslash
Replicates graphql/graphql-js@15e43b8
1 parent 190cf85 commit 6270492

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/graphql/language/block_string.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ def print_block_string(
7979
is_single_line = "\n" not in value
8080
has_leading_space = value.startswith(" ") or value.startswith("\t")
8181
has_trailing_quote = value.endswith('"')
82+
has_trailing_slash = value.endswith("\\")
8283
print_as_multiple_lines = (
83-
not is_single_line or has_trailing_quote or prefer_multiple_lines
84+
not is_single_line
85+
or has_trailing_quote
86+
or has_trailing_slash
87+
or prefer_multiple_lines
8488
)
8589

8690
# Format a multi-line block quote to account for leading space.

tests/language/test_block_string.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ def correctly_prints_single_line_with_leading_space_and_quotation():
120120
== '""" space-led value "quoted string"\n"""'
121121
)
122122

123+
def correctly_prints_single_line_with_trailing_backslash():
124+
s = "backslash \\"
125+
126+
assert print_block_string(s) == '"""\nbackslash \\\n"""'
127+
assert print_block_string(s, "", True) == '"""\nbackslash \\\n"""'
128+
123129
def correctly_prints_string_with_a_first_line_indentation():
124130
s = join_lines(" first ", " line ", "indentation", " string")
125131

0 commit comments

Comments
 (0)