parser: implement switch, port switch comment tests

Implement parseSwitchExpr in parser.c:
- switch(expr) { cases... } with case items, ranges, else
- switch_case_one and switch_case node types
- Proper scratch management for nested case items

Port tests:
- "switch comment before prong"
- "switch comment after prong"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-10 18:47:50 +00:00
parent 2dc5993a29
commit fe86388d1e
2 changed files with 131 additions and 1 deletions

View File

@@ -2137,6 +2137,31 @@ test "zig fmt: function call with multiline argument" {
);
}
test "zig fmt: switch comment before prong" {
try testCanonical(
\\comptime {
\\ switch (a) {
\\ // hi
\\ 0 => {},
\\ }
\\}
\\
);
}
test "zig fmt: switch comment after prong" {
try testCanonical(
\\comptime {
\\ switch (a) {
\\ 0,
\\ // hi
\\ => {},
\\ }
\\}
\\
);
}
test "zig fmt: if-else with comment before else" {
try testCanonical(
\\comptime {