ruff/crates/ruff_python_formatter/tests
Charlie Marsh d574fcd1ac
Compare formatted and unformatted ASTs during formatter tests (#8624)
## Summary

This PR implements validation in the formatter tests to ensure that we
don't modify the AST during formatting. Black has similar logic.

In implementing this, I learned that Black actually _does_ modify the
AST, and their test infrastructure normalizes the AST to wipe away those
differences. Specifically, Black changes the indentation of docstrings,
which _does_ modify the AST; and it also inserts parentheses in `del`
statements, which changes the AST too.

Ruff also does both these things, so we _also_ implement the same
normalization using a new visitor that allows for modifying the AST.

Closes https://github.com/astral-sh/ruff/issues/8184.

## Test Plan

`cargo test`
2023-11-13 17:43:27 +00:00
..
snapshots Apply consistent code block labels (#8563) 2023-11-09 01:49:24 +00:00
fixtures.rs Compare formatted and unformatted ASTs during formatter tests (#8624) 2023-11-13 17:43:27 +00:00
normalizer.rs Compare formatted and unformatted ASTs during formatter tests (#8624) 2023-11-13 17:43:27 +00:00