diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 0513bd9f0325..37d90a68df58 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -2230,6 +2230,10 @@ test "zig fmt: switch cases trailing comma" { \\ 1,2,3 => {}, \\ 4,5, => {}, \\ 6... 8, => {}, + \\ 9 ... + \\ 10 => {}, + \\ 11 => {}, + \\ 12, => {}, \\ else => {}, \\ } \\} @@ -2240,7 +2244,12 @@ test "zig fmt: switch cases trailing comma" { \\ 4, \\ 5, \\ => {}, - \\ 6...8 => {}, + \\ 6...8, + \\ => {}, + \\ 9...10 => {}, + \\ 11 => {}, + \\ 12, + \\ => {}, \\ else => {}, \\ } \\} diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index 4b57ab69aac0..a87f28964242 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1894,9 +1894,6 @@ fn renderSwitchCase( // Render everything before the arrow if (switch_case.ast.values.len == 0) { try renderToken(r, switch_case.ast.arrow_token - 1, .space); // else keyword - } else if (switch_case.ast.values.len == 1 and !has_comment_before_arrow) { - // render on one line and drop the trailing comma if any - try renderExpression(r, switch_case.ast.values[0], .space); } else if (trailing_comma or has_comment_before_arrow) { // Render each value on a new line try renderExpressions(r, switch_case.ast.values, .comma);