| author | |
| committer | |
| log | 15c7c6ab970830a87b6aa502a369fb2b29b933c5 |
| tree | d169f38dd855e286559b3f2c9883e2cb61ca3247 |
| parent | 1b8eca030e9dac51361d80428f8276a09f31a8c2 |
| signature |
2 files changed, 34 insertions(+), 1 deletions(-)
lib/std/zig/parser_test.zig+31| ... | ... | @@ -4202,6 +4202,37 @@ test "zig fmt: respect extra newline between switch items" { |
| 4202 | 4202 | ); |
| 4203 | 4203 | } |
| 4204 | 4204 | |
| 4205 | test "zig fmt: insert trailing comma if there are comments between switch values" { | |
| 4206 | try testTransform( | |
| 4207 | \\const a = switch (b) { | |
| 4208 | \\ .c => {}, | |
| 4209 | \\ | |
| 4210 | \\ .d, // foobar | |
| 4211 | \\ .e | |
| 4212 | \\ => f, | |
| 4213 | \\ | |
| 4214 | \\ .g, .h | |
| 4215 | \\ // comment | |
| 4216 | \\ => i, | |
| 4217 | \\}; | |
| 4218 | \\ | |
| 4219 | , | |
| 4220 | \\const a = switch (b) { | |
| 4221 | \\ .c => {}, | |
| 4222 | \\ | |
| 4223 | \\ .d, // foobar | |
| 4224 | \\ .e, | |
| 4225 | \\ => f, | |
| 4226 | \\ | |
| 4227 | \\ .g, | |
| 4228 | \\ .h, | |
| 4229 | \\ // comment | |
| 4230 | \\ => i, | |
| 4231 | \\}; | |
| 4232 | \\ | |
| 4233 | ); | |
| 4234 | } | |
| 4235 | ||
| 4205 | 4236 | test "zig fmt: error for invalid bit range" { |
| 4206 | 4237 | try testError( |
| 4207 | 4238 | \\var x: []align(0:0:0)u8 = bar; |
lib/std/zig/render.zig+3-1| ... | ... | @@ -1533,7 +1533,9 @@ fn renderSwitchCase( |
| 1533 | 1533 | } else if (switch_case.ast.values.len == 1) { |
| 1534 | 1534 | // render on one line and drop the trailing comma if any |
| 1535 | 1535 | try renderExpression(gpa, ais, tree, switch_case.ast.values[0], .space); |
| 1536 | } else if (trailing_comma) { | |
| 1536 | } else if (trailing_comma or | |
| 1537 | hasComment(tree, tree.firstToken(switch_case.ast.values[0]), switch_case.ast.arrow_token)) | |
| 1538 | { | |
| 1537 | 1539 | // Render each value on a new line |
| 1538 | 1540 | try renderExpressions(gpa, ais, tree, switch_case.ast.values, .comma); |
| 1539 | 1541 | } else { |