Commit graph

42 commits

Author SHA1 Message Date
Joshua Warner
a046428ce6
Add fuzzing for the formatter and fix bugs
This commit adds fuzzing for the (expr) formatter, with the same invariants that we use for fmt tests:
  * We start with text, which we parse
  * We format the AST, which must succeed
  * We parse back the AST and make sure it's identical igoring whitespace+comments
  * We format the new AST and assert it's equal to the first formatted version ("idempotency")

Interestingly, while a lot of bugs this found were in the formatter, it also found some parsing bugs.

It then fixes a bunch of bugs that fell out:
* Some small oversights in RemoveSpaces
* Make sure `_a` doesn't parse as an inferred type (`_`) followed by an identifier (parsing bug!)
* Call `extract_spaces` on a parsed expr before matching on it, lest it be Expr::SpaceBefore - when parsing aliases
* A few cases where the formatter generated invalid/different code
* Numerous formatting bugs that caused the formatting to not be idempotent

The last point there is worth talking further about. There were several cases where the old code was trying to enforce strong
opinions about how to insert newlines in function types and defs. In both of those cases, it looked like the goals of
(1) idempotency, (2) giving the user some say in the output, and (3) these strong opinions - were often in conflict.

For these cases, I erred on the side of following the user's existing choices about where to put newlines.

We can go back and re-add this strong opinionation later - but this seemed the right approach for now.
2022-12-17 09:52:09 -08:00
Ayaz Hafiz
aab509c5c1
Make sure to escape formatting of char literals
Closes #4682
2022-12-05 14:09:28 -06:00
Ayaz Hafiz
1011ce9fba
Format crash 2022-11-24 14:46:49 -06:00
Joshua Warner
d4bf946327
Assert formatting for parse tests 2022-11-15 19:47:28 -05:00
Joshua Warner
1efd7260de
Add fmt test to make sure formatting works for all parser test cases 2022-11-14 08:20:35 -05:00
Joshua Warner
6c15cc750f
Change test to use single backpassing instead of multi 2022-11-11 08:13:13 -05:00
Richard Feldman
50d9755758
Merge pull request #4429 from austinclem1/main
add missing indent when formatting single-quoted char in pattern
2022-10-31 17:56:06 -07:00
Joshua Warner
07be8ec000
Refactor Parser trait to pass min_indent
This removes the need to explicitly pass thru min_indent when using the parser combinators.

My ultimate goal here is to evolve the current parser closer toward a purely combinator-based parser,
at which point we can more easily transition smoothly to a formal(ish) grammar, or expand the meanings of combinators
to include things like:
* Incremental (re)parsing
* Unified parsing and formatting code
* Better error recovery
* Using the main parser directly for syntax highlighting
2022-10-31 13:31:47 -07:00
Austin Clements
5d19d28e56 formatting 2022-10-28 18:13:03 -05:00
Austin Clements
ec81ce5ebc add test for formatter: single-quoted char pattern 2022-10-28 16:36:24 -05:00
Ayaz Hafiz
9bb523ce97
Format list patterns 2022-10-26 17:08:10 -05:00
Ayaz Hafiz
1053c11907
Basic formatting of multi-abilities 2022-10-24 14:00:46 -05:00
Joshua Warner
e39a385f5f
Allow parsing when cases with python-like indentation 2022-10-18 19:13:20 -07:00
Ayaz Hafiz
df3b7cb1b4
Preserve comments before header
Closes #4212
2022-10-05 08:34:30 -05:00
Ayaz Hafiz
f6c21cc933
Correctly format abilities with comments 2022-10-04 10:03:51 -05:00
Ayaz Hafiz
bbb2083dd6
Correctly format nested pipeline operators
Closes #4151
2022-10-03 14:18:17 -05:00
Ayaz Hafiz
3883867b5c
Properly format characters with escape sequences
Ran into this just now
2022-10-02 17:10:34 -05:00
Ayaz Hafiz
fc6561ecb6
Format string literals in patterns 2022-09-07 17:30:52 -05:00
raleng
85eda83398
Enable and add multi-line string formatting tests 2022-08-26 12:19:14 +02:00
Richard Feldman
0d0cebc40d
Reproduce expect formatting bugs 2022-08-04 23:14:16 -04:00
Richard Feldman
f575807834
Merge remote-tracking branch 'origin/trunk' into outdent-infix 2022-07-16 16:08:36 -04:00
Ayaz Hafiz
be9944a7e1
Improve indent of has-abilities clauses 2022-07-15 11:59:03 -04:00
Ayaz Hafiz
3c65fbcf35
Format has clauses with impls 2022-07-15 11:45:53 -04:00
Ayaz Hafiz
85cbab0193
Add fmt test for empty has abilities block 2022-07-15 11:17:21 -04:00
Richard Feldman
897c6b17df
cargo fmt 2022-07-14 10:22:40 -04:00
Richard Feldman
87bb1d7b3d
Update formatting tests 2022-07-13 23:19:28 -04:00
Richard Feldman
b9a314dcd9
Update formatter tests 2022-07-11 13:14:35 -04:00
Richard Feldman
57260d53f9
Allow single-line comments in multiline annotations 2022-07-09 23:06:45 -04:00
Folkert de Vries
8c5f798f4e
Merge pull request #3454 from rtfeldman/fix-opaque-formatting
Fix unstable formatting of opaque tag unions
2022-07-08 22:22:00 +02:00
Richard Feldman
5f0e3c72c5
Fix unstable formatting on opaque unions 2022-07-08 15:29:08 -04:00
Richard Feldman
1d07d9efa1
Reproduce unstable formatting on opaque unions 2022-07-08 15:17:15 -04:00
Richard Feldman
dbbbacc32a
Fix comment between multiline annotation args 2022-07-08 14:31:31 -04:00
Richard Feldman
82c81a7039
Allow comments after the -> in a when 2022-07-06 16:48:28 -04:00
Richard Feldman
3c9ad5b24d
Drop obsolete test 2022-07-06 16:42:54 -04:00
Richard Feldman
15932d7d47
Fix comments in when branches 2022-07-06 16:42:54 -04:00
Richard Feldman
f01d6a55f7
Fix multiline_binop_conditional_with_comments 2022-07-06 16:42:53 -04:00
Richard Feldman
d2476099a5
Add some tests for trailing commas in comments 2022-07-06 15:17:19 -04:00
Richard Feldman
9df5802848
Update formatter tests 2022-07-06 15:10:17 -04:00
Richard Feldman
87b7a9ba3b
Update formatter tests 2022-07-06 14:01:53 -04:00
Richard Feldman
244a501433
Indent for multiline | patterns 2022-07-03 22:17:13 -04:00
Richard Feldman
3e2f581db4
Reproduce formatter bug 2022-07-03 21:58:59 -04:00
Anton-4
eee85fa45d
moved all crates into seperate folder + related path fixes 2022-07-01 17:37:43 +02:00
Renamed from compiler/fmt/tests/test_fmt.rs (Browse further)