parser: port misc formatting tests batch

Port tests:
- "fix single statement if/for/while line breaks"
- "fn type"
- "nosuspend"
- "Block after if"
- "string identifier"
- "error return"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-11 05:04:18 +00:00
parent df10e2f885
commit 106430e6e9

View File

@@ -4238,6 +4238,112 @@ test "zig fmt: decimal float literals with underscore separators" {
);
}
test "zig fmt: fix single statement if/for/while line breaks" {
try testTransform(
\\test {
\\ if (cond) a
\\ else b;
\\
\\ if (cond)
\\ a
\\ else b;
\\
\\ for (xs) |x| foo()
\\ else bar();
\\
\\ for (xs) |x|
\\ foo()
\\ else bar();
\\
\\ while (a) : (b) foo()
\\ else bar();
\\
\\ while (a) : (b)
\\ foo()
\\ else bar();
\\}
\\
,
\\test {
\\ if (cond) a else b;
\\
\\ if (cond)
\\ a
\\ else
\\ b;
\\
\\ for (xs) |x| foo() else bar();
\\
\\ for (xs) |x|
\\ foo()
\\ else
\\ bar();
\\
\\ while (a) : (b) foo() else bar();
\\
\\ while (a) : (b)
\\ foo()
\\ else
\\ bar();
\\}
\\
);
}
test "zig fmt: fn type" {
try testCanonical(
\\fn a(i: u8) u8 {
\\ return i + 1;
\\}
\\
\\const a: fn (u8) u8 = undefined;
\\const b: fn (u8) callconv(.naked) u8 = undefined;
\\const ap: fn (u8) u8 = a;
\\
);
}
test "zig fmt: nosuspend" {
try testCanonical(
\\const a = nosuspend foo();
\\
);
}
test "zig fmt: Block after if" {
try testCanonical(
\\test {
\\ if (true) {
\\ const a = 0;
\\ }
\\
\\ {
\\ const a = 0;
\\ }
\\}
\\
);
}
test "zig fmt: string identifier" {
try testCanonical(
\\const @"a b" = @"c d".@"e f";
\\fn @"g h"() void {}
\\
);
}
test "zig fmt: error return" {
try testCanonical(
\\fn err() anyerror {
\\ call();
\\ return error.InvalidArgs;
\\}
\\
);
}
test "Ast header smoke test" {
try std.testing.expectEqual(zigNode(c.AST_NODE_IF), Ast.Node.Tag.@"if");
}