Skip to content

test: add fuzz test to check for idempotency#166

Open
mgeisler wants to merge 3 commits intodprint:mainfrom
mgeisler:fuzz-test
Open

test: add fuzz test to check for idempotency#166
mgeisler wants to merge 3 commits intodprint:mainfrom
mgeisler:fuzz-test

Conversation

@mgeisler
Copy link
Copy Markdown

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.

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.
@mgeisler
Copy link
Copy Markdown
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.

@mgeisler
Copy link
Copy Markdown
Author

Feel free to tear the code here apart, maintainer edits are enabled!

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