Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix formatting for CHAR node when single_quotes plugin is enabled
  • Loading branch information
nobuyo committed Jun 17, 2023
commit c7de3f653cec55ac5aa9d71b46ccca19430e00d8
2 changes: 1 addition & 1 deletion lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def format(q)
q.text(value)
else
q.text(q.quote)
q.text(value[1] == "\"" ? "\\\"" : value[1])
q.text(value[1] == q.quote ? "\\#{q.quote}" : value[1])
q.text(q.quote)
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/plugin/single_quotes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ def test_empty_string_literal
assert_format("''\n", "\"\"")
end

def test_character_literal_with_double_quote
assert_format("'\"'\n", "?\"")
end

def test_character_literal_with_singlee_quote
assert_format("'\\''\n", "?'")
end

def test_string_literal
assert_format("'string'\n", "\"string\"")
end
Expand Down