Skip to content

Commit

Permalink
Fix formatting for CHAR node when single_quotes plugin is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nobuyo committed Jun 12, 2023
1 parent 909b45a commit cdc6209
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/syntax_tree/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def format(q)
q.text(value)
else
q.text(q.quote)
q.text(value[1] == "\"" ? "\\\"" : value[1])
double_quotation = q.quote == "'" ? "\"" : "\\\""
q.text(value[1] == "\"" ? double_quotation : value[1])
q.text(q.quote)
end
end
Expand Down
4 changes: 4 additions & 0 deletions test/plugin/single_quotes_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def test_empty_string_literal
assert_format("''\n", "\"\"")
end

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

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

0 comments on commit cdc6209

Please sign in to comment.