Skip to content

Add unit tests for string escape logic#844

Open
reese wants to merge 1 commit intotrunkfrom
reese-string-escape-tests
Open

Add unit tests for string escape logic#844
reese wants to merge 1 commit intotrunkfrom
reese-string-escape-tests

Conversation

@reese
Copy link
Collaborator

@reese reese commented Mar 17, 2026

rubyfmt is almost entirely tested with fixtures. This is mostly fine, but there's a few isolated bits of logic that could use some unit testing. String escaping is the most obvious one -- it's bytes in to bytes out and has quite specific rules that are easy to test in isolation. (Heredocs and some of the comment bits also could use them, but strings are probably the highest value for now.)

This does add one else branch to the actual production code purely as a defense mechanism/future-proof that I saw in unit tests, but I'm fairly confident it's never reachable in real Ruby code (see the word_array_trailing_backslash_preserved test). It covers a trailing slash in a %w array, which in real usages (%w[\]) would escape the closing delimiter and be invalid, so that else is unreachable, but as far as escape_word_array_content is concerned it does the right thing if it ever were to get in that state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant