pxp-lang / pxp

A suite of high-performance tools for PHP developers – includes a code formatter, static analyser, language server and superset language.
https://pxplang.org
Other
784 stars 0 forks source link

Write a format-preserving AST printer #47

Closed ryangjchandler closed 4 months ago

ryangjchandler commented 8 months ago

The current test suite is using snapshot testing to ensure the AST we generate for a particular fixture file doesn't change. This approach works well but requires manual validation, since we want to make sure that the snapshot generated is indeed correct.

Another approach to testing the parser that I'd like to try out is comparing the original code with a format-preserved print of the AST that we generate.

The idea here is to take the AST and use the Span information for each node to generate a 1:1 copy of the original code. This will make testing much easier since we'd just need to compare the two strings and will help us catch any precedence bugs, etc.