parser: port formatting, declaration, fn attribute tests

Port tests:
- "preserve spacing"
- "return types"
- "imports"
- "global declarations"
- "extern declaration"
- "function attributes"
- "nested pointers with ** tokens"
- "test declaration"

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-10 19:46:58 +00:00
parent 37ae8b01d1
commit a1fef56b95

View File

@@ -3151,6 +3151,104 @@ test "zig fmt: first line comment in struct initializer" {
);
}
test "zig fmt: preserve spacing" {
try testCanonical(
\\const std = @import("std");
\\
\\pub fn main() !void {
\\ var stdout_file = std.lol.abcd;
\\ var stdout_file = std.lol.abcd;
\\
\\ var stdout_file = std.lol.abcd;
\\ var stdout_file = std.lol.abcd;
\\}
\\
);
}
test "zig fmt: return types" {
try testCanonical(
\\pub fn main() !void {}
\\pub fn main() FooBar {}
\\pub fn main() i32 {}
\\
);
}
test "zig fmt: imports" {
try testCanonical(
\\const std = @import("std");
\\const std = @import();
\\
);
}
test "zig fmt: global declarations" {
try testCanonical(
\\const a = b;
\\pub const a = b;
\\var a = b;
\\pub var a = b;
\\const a: i32 = b;
\\pub const a: i32 = b;
\\var a: i32 = b;
\\pub var a: i32 = b;
\\extern const a: i32 = b;
\\pub extern const a: i32 = b;
\\extern var a: i32 = b;
\\pub extern var a: i32 = b;
\\extern "a" const a: i32 = b;
\\pub extern "a" const a: i32 = b;
\\extern "a" var a: i32 = b;
\\pub extern "a" var a: i32 = b;
\\
);
}
test "zig fmt: extern declaration" {
try testCanonical(
\\extern var foo: c_int;
\\
);
}
test "zig fmt: function attributes" {
try testCanonical(
\\export fn foo() void {}
\\pub export fn foo() void {}
\\extern fn foo() void;
\\pub extern fn foo() void;
\\extern "c" fn foo() void;
\\pub extern "c" fn foo() void;
\\noinline fn foo() void {}
\\pub noinline fn foo() void {}
\\
);
}
test "zig fmt: nested pointers with ** tokens" {
try testCanonical(
\\const x: *u32 = undefined;
\\const x: **u32 = undefined;
\\const x: ***u32 = undefined;
\\const x: ****u32 = undefined;
\\const x: *****u32 = undefined;
\\const x: ******u32 = undefined;
\\const x: *******u32 = undefined;
\\
);
}
test "zig fmt: test declaration" {
try testCanonical(
\\test "test name" {
\\ const a = 1;
\\ var b = 1;
\\}
\\
);
}
test "zig fmt: error set declaration" {
try testCanonical(
\\const E = error{