Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting for CHAR node when single_quotes plugin is enabled #385

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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