diff --git a/parser_test.zig b/parser_test.zig index 03fafd8a23..281d01bbab 100644 --- 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, + \\ }; + \\} + \\ + ); +}