Skip to content

Commit c7de3f6

Browse files
committed
Fix formatting for CHAR node when single_quotes plugin is enabled
1 parent 909b45a commit c7de3f6

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Diff for: lib/syntax_tree/node.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def format(q)
288288
q.text(value)
289289
else
290290
q.text(q.quote)
291-
q.text(value[1] == "\"" ? "\\\"" : value[1])
291+
q.text(value[1] == q.quote ? "\\#{q.quote}" : value[1])
292292
q.text(q.quote)
293293
end
294294
end

Diff for: test/plugin/single_quotes_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ def test_empty_string_literal
88
assert_format("''\n", "\"\"")
99
end
1010

11+
def test_character_literal_with_double_quote
12+
assert_format("'\"'\n", "?\"")
13+
end
14+
15+
def test_character_literal_with_singlee_quote
16+
assert_format("'\\''\n", "?'")
17+
end
18+
1119
def test_string_literal
1220
assert_format("'string'\n", "\"string\"")
1321
end

0 commit comments

Comments
 (0)