commit db999129bdee6ef579e01ff010a08fef26810b94 (tree)
parent b229e001ff650b117f3103502ff4bb4765d226da
Author: Motiejus Jakštys <motiejus.jakstys@chronosphere.io>
Date: Tue, 10 Feb 2026 12:59:51 +0000
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>
Diffstat:
| M | parser_test.zig | | | 180 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 180 insertions(+), 0 deletions(-)
diff --git a/parser_test.zig b/parser_test.zig
@@ -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,
+ \\ };
+ \\}
+ \\
+ );
+}