test: add fuzz test to check for idempotency#166
Open
mgeisler wants to merge 3 commits intodprint:mainfrom
Open
test: add fuzz test to check for idempotency#166mgeisler wants to merge 3 commits intodprint:mainfrom
mgeisler wants to merge 3 commits intodprint:mainfrom
Conversation
This introduces a fuzz test which looks for cases where the Markdown
formatter is not reaching a fix point in it’s first attempt.
The idea is that a well-formatted Markdown file should not be changed
if formatted again.
Running
QUICKCHECK_TESTS=1000000 cargo test --test fuzz_test check -- --ignored
will typically find a failure case. I’ve added a few failing tests
already.
Previously, the plugin would panic when encountering certain control
characters like null bytes or vertical tabs within the text. This was
because these characters were being sent raw to `dprint-core`, which
expects only specific whitespace characters or valid text content,
raising a debug panic for unexpected characters to prevent column
tracking issues.
This change updates `TextBuilder` to treat these
characters (specifically `\t`, `\r`, `\n`, `\u{000b}`, `\u{000c}`) as
whitespace. They will now be handled correctly by the whitespace
collapsing logic or emitted as appropriate whitespace signals/items,
preventing the panic and ensuring robust handling of arbitrary input.
This ensures that block quotes with no children (e.g. '>') are still printed.
Author
|
For fun, I let Gemini lose on the task of fixing the failing tests found by the fuzz test. It wrote two fixes, added as separate commits — I don't know if they're helpful, but I added them just in case! The main part is still the concept of the formatting being idempotent. |
Author
|
Feel free to tear the code here apart, maintainer edits are enabled! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces a fuzz test which looks for cases where the Markdown formatter is not reaching a fix point in it’s first attempt.
The idea is that a well-formatted Markdown file should not be changed if formatted again.
Running
will typically find a failure case. I’ve added a few failing tests already.