Skip to content

Commit

Permalink
Add some more tests to pin down comment indentation in switches. (#1180)
Browse files Browse the repository at this point in the history
I spent a bunch of time investigating whether comments in switches that
aren't inside a case body (i.e. not between the "case" line and some
statement inside the case) should be indented to align with the cases
or the bodies.

After trying a bunch of alternatives and running them on a big corpus,
I concluded that the current behavior (always align to the cases)
actually works very well in almost all real-world code. But it's not
pinned down well by tests, so this does that.
  • Loading branch information
munificent authored Feb 23, 2023
1 parent fc29f83 commit 35a5d9f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion test/comments/switch.stmt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,39 @@ switch (n) {
case 1: one; // comment
case 2: two; // comment
}
>>> keeps one blank line around case comments in switch expression
>>> line comment indentation
switch (n) {
// before first
case 0: zero;
// between
case 1: one;
// after last
}
<<<
switch (n) {
// before first
case 0: zero;
// between
case 1: one;
// after last
}
>>> line comment in empty cases
switch (n) {
case 0: // comment 0
case 1:
// comment 1
case 2:
// comment 2
}
<<<
switch (n) {
case 0: // comment 0
case 1:
// comment 1
case 2:
// comment 2
}
>>> keeps one blank line around case comments in switch expression
e = switch (n) {


Expand Down

0 comments on commit 35a5d9f

Please sign in to comment.