parser: port misc formatting tests batch
Port tests: - "alignment" - "C main" - "return" - "arrays" - "blocks" - "container doc comments" - "comments before global variables" - "comments before test decl" - "decimal float literals with underscore separators" - "comptime" - "comptime block in container" - "comments before var decl in struct" - "block with same line comment after end brace" - "comment after empty comment" - "comment after params" Fix trailing flag for comptime blocks in parseContainerMembers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2
parser.c
2
parser.c
@@ -2402,7 +2402,7 @@ static Members parseContainerMembers(Parser* p) {
|
||||
.main_token = comptime_token,
|
||||
.data = { .lhs = block_node, .rhs = 0 },
|
||||
}));
|
||||
trailing = p->token_tags[p->tok_i - 1] == TOKEN_R_BRACE;
|
||||
trailing = false;
|
||||
break;
|
||||
}
|
||||
// Otherwise it's a container field with comptime modifier
|
||||
|
||||
150
parser_test.zig
150
parser_test.zig
@@ -1948,6 +1948,156 @@ test "zig fmt: addrspace" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: alignment" {
|
||||
try testCanonical(
|
||||
\\var foo: c_int align(1);
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: C main" {
|
||||
try testCanonical(
|
||||
\\fn main(argc: c_int, argv: **u8) c_int {
|
||||
\\ const a = b;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: return" {
|
||||
try testCanonical(
|
||||
\\fn foo(argc: c_int, argv: **u8) c_int {
|
||||
\\ return 0;
|
||||
\\}
|
||||
\\
|
||||
\\fn bar() void {
|
||||
\\ return;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: arrays" {
|
||||
try testCanonical(
|
||||
\\test "arrays" {
|
||||
\\ const a: [2]u32 = .{ 1, 2 };
|
||||
\\ const b = a ++ a;
|
||||
\\ const c = a[0..];
|
||||
\\ _ = c;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: blocks" {
|
||||
try testCanonical(
|
||||
\\test {
|
||||
\\ {
|
||||
\\ const a = b;
|
||||
\\ }
|
||||
\\ const c = d;
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: container doc comments" {
|
||||
try testCanonical(
|
||||
\\//! tld 1
|
||||
\\//! tld 2
|
||||
\\//! tld 3
|
||||
\\const a = b;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comments before global variables" {
|
||||
try testCanonical(
|
||||
\\/// comment
|
||||
\\var foo: i32 = undefined;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comments before test decl" {
|
||||
try testCanonical(
|
||||
\\/// top level doc comment
|
||||
\\test "hi" {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: decimal float literals with underscore separators" {
|
||||
try testCanonical(
|
||||
\\const x = 1_234_567.89_10_11;
|
||||
\\const y = 1_234_567.89_10_11e1_213_14;
|
||||
\\const z = 1_234_567;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comptime" {
|
||||
try testCanonical(
|
||||
\\fn foo() void {
|
||||
\\ comptime {
|
||||
\\ bar();
|
||||
\\ }
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comptime block in container" {
|
||||
try testCanonical(
|
||||
\\const Foo = struct {
|
||||
\\ comptime {
|
||||
\\ @compileLog("hello comptime");
|
||||
\\ }
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comments before var decl in struct" {
|
||||
try testCanonical(
|
||||
\\const Foo = struct {
|
||||
\\ /// comment
|
||||
\\ bar: bool = true,
|
||||
\\};
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: block with same line comment after end brace" {
|
||||
try testCanonical(
|
||||
\\test {
|
||||
\\ {
|
||||
\\ const a = b;
|
||||
\\ } // end of block
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comment after empty comment" {
|
||||
try testCanonical(
|
||||
\\//
|
||||
\\/// A doc comment
|
||||
\\const a = b;
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: comment after params" {
|
||||
try testCanonical(
|
||||
\\fn foo(
|
||||
\\ a: i32, // comment
|
||||
\\ b: i32, // comment
|
||||
\\) void {}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: sentinel-terminated array type" {
|
||||
try testCanonical(
|
||||
\\pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
|
||||
|
||||
Reference in New Issue
Block a user