parser: add struct/array literal tests (2/3 element variants)

Port tests from upstream parser_test.zig:
- "struct literal 2/3 element" (with and without comma)
- "anon list literal 1/2/3 element" (with and without comma)
- "array literal 0/1/2/3 element" (with and without comma)

All 17 new tests pass without parser changes — the init list
implementation from the previous commit handles all cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-02-10 12:59:51 +00:00
parent cd93f7cffd
commit 8705fd0197

View File

@@ -1026,3 +1026,183 @@ test "zig fmt: struct literal 1 element" {
\\
);
}
test "zig fmt: struct literal 2 element" {
try testCanonical(
\\test {
\\ const x = X{ .a = b, .c = d };
\\}
\\
);
}
test "zig fmt: struct literal 2 element comma" {
try testCanonical(
\\test {
\\ const x = X{
\\ .a = b,
\\ .c = d,
\\ };
\\}
\\
);
}
test "zig fmt: struct literal 3 element" {
try testCanonical(
\\test {
\\ const x = X{ .a = b, .c = d, .e = f };
\\}
\\
);
}
test "zig fmt: struct literal 3 element comma" {
try testCanonical(
\\test {
\\ const x = X{
\\ .a = b,
\\ .c = d,
\\ .e = f,
\\ };
\\}
\\
);
}
test "zig fmt: anon list literal 1 element" {
try testCanonical(
\\test {
\\ const x = .{a};
\\}
\\
);
}
test "zig fmt: anon list literal 1 element comma" {
try testCanonical(
\\test {
\\ const x = .{
\\ a,
\\ };
\\}
\\
);
}
test "zig fmt: anon list literal 2 element" {
try testCanonical(
\\test {
\\ const x = .{ a, b };
\\}
\\
);
}
test "zig fmt: anon list literal 2 element comma" {
try testCanonical(
\\test {
\\ const x = .{
\\ a,
\\ b,
\\ };
\\}
\\
);
}
test "zig fmt: anon list literal 3 element" {
try testCanonical(
\\test {
\\ const x = .{ a, b, c };
\\}
\\
);
}
test "zig fmt: anon list literal 3 element comma" {
try testCanonical(
\\test {
\\ const x = .{
\\ a,
\\ // foo
\\ b,
\\
\\ c,
\\ };
\\}
\\
);
}
test "zig fmt: array literal 0 element" {
try testCanonical(
\\test {
\\ const x = [_]u32{};
\\}
\\
);
}
test "zig fmt: array literal 1 element" {
try testCanonical(
\\test {
\\ const x = [_]u32{a};
\\}
\\
);
}
test "zig fmt: array literal 1 element comma" {
try testCanonical(
\\test {
\\ const x = [1]u32{
\\ a,
\\ };
\\}
\\
);
}
test "zig fmt: array literal 2 element" {
try testCanonical(
\\test {
\\ const x = [_]u32{ a, b };
\\}
\\
);
}
test "zig fmt: array literal 2 element comma" {
try testCanonical(
\\test {
\\ const x = [2]u32{
\\ a,
\\ b,
\\ };
\\}
\\
);
}
test "zig fmt: array literal 3 element" {
try testCanonical(
\\test {
\\ const x = [_]u32{ a, b, c };
\\}
\\
);
}
test "zig fmt: array literal 3 element comma" {
try testCanonical(
\\test {
\\ const x = [3]u32{
\\ a,
\\ b,
\\ c,
\\ };
\\}
\\
);
}