Skip to content

Commit 35a5d9f

Browse files
authored
Add some more tests to pin down comment indentation in switches. (#1180)
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.
1 parent fc29f83 commit 35a5d9f

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/comments/switch.stmt

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,39 @@ switch (n) {
5555
case 1: one; // comment
5656
case 2: two; // comment
5757
}
58-
>>> keeps one blank line around case comments in switch expression
58+
>>> line comment indentation
59+
switch (n) {
60+
// before first
61+
case 0: zero;
62+
// between
63+
case 1: one;
64+
// after last
65+
}
66+
<<<
67+
switch (n) {
68+
// before first
69+
case 0: zero;
70+
// between
71+
case 1: one;
72+
// after last
73+
}
74+
>>> line comment in empty cases
75+
switch (n) {
76+
case 0: // comment 0
77+
case 1:
78+
// comment 1
79+
case 2:
80+
// comment 2
81+
}
82+
<<<
83+
switch (n) {
84+
case 0: // comment 0
85+
case 1:
86+
// comment 1
87+
case 2:
88+
// comment 2
89+
}
90+
>>> keeps one blank line around case comments in switch expression
5991
e = switch (n) {
6092

6193

0 commit comments

Comments
 (0)