Skip to content

Commit 8dd7995

Browse files
committed
std.zig.parser_test: add test cases
1 parent 97645f3 commit 8dd7995

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

lib/std/zig/parser_test.zig

+33
Original file line numberDiff line numberDiff line change
@@ -6107,6 +6107,39 @@ test "zig fmt: indentation of comments within catch, else, orelse" {
61076107
);
61086108
}
61096109

6110+
test "zig fmt: array initializer with switch expression - canonical" {
6111+
try testCanonical(
6112+
\\const bar = .{
6113+
\\ .{switch ({}) {
6114+
\\ else => {},
6115+
\\ }},
6116+
\\ .{},
6117+
\\ .{},
6118+
\\ .{},
6119+
\\};
6120+
\\
6121+
);
6122+
}
6123+
6124+
test "zig fmt: array initializer with switch expression - transformation" {
6125+
try testTransform(
6126+
\\const bar = .{ .{ switch ({}) {
6127+
\\ else => {},
6128+
\\ } }, .{}, .{}, .{},
6129+
\\};
6130+
\\
6131+
,
6132+
\\const bar = .{
6133+
\\ .{switch ({}) {
6134+
\\ else => {},
6135+
\\ }},
6136+
\\ .{}, .{},
6137+
\\ .{},
6138+
\\};
6139+
\\
6140+
);
6141+
}
6142+
61106143
test "recovery: top level" {
61116144
try testError(
61126145
\\test "" {inline}

test/tests.zig

-44
Original file line numberDiff line numberDiff line change
@@ -1299,50 +1299,6 @@ pub fn addCliTests(b: *std.Build) *Step {
12991299
});
13001300
check6.step.dependOn(&run6.step);
13011301

1302-
// Test `zig fmt` handling switch expressions in array initializers
1303-
const switch_in_array_code =
1304-
\\const bar = .{ .{ switch ({}) {
1305-
\\ else => {},
1306-
\\ } }, .{}, .{}, .{},
1307-
\\};
1308-
\\
1309-
;
1310-
1311-
const fmt7_path = b.pathJoin(&.{ tmp_path, "fmt7.zig" });
1312-
const write7 = b.addUpdateSourceFiles();
1313-
write7.addBytesToSource(switch_in_array_code, fmt7_path);
1314-
write7.step.dependOn(&check6.step);
1315-
1316-
// Test `zig fmt` handling switch expressions in array initializers
1317-
const run7 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt7.zig" });
1318-
run7.setName("run zig fmt on array with switch");
1319-
run7.setCwd(.{ .cwd_relative = tmp_path });
1320-
run7.has_side_effects = true;
1321-
run7.expectStdOutEqual("fmt7.zig\n");
1322-
run7.step.dependOn(&write7.step);
1323-
1324-
// Check that the file is formatted correctly after a single fmt invocation
1325-
const check7 = b.addCheckFile(.{ .cwd_relative = fmt7_path }, .{
1326-
.expected_matches = &.{
1327-
"const bar = .{",
1328-
" .{switch ({}) {",
1329-
" else => {},",
1330-
" }},",
1331-
" .{},",
1332-
" .{},",
1333-
" .{},",
1334-
"};",
1335-
},
1336-
});
1337-
check7.step.dependOn(&run7.step);
1338-
1339-
// Run fmt again to verify that no further changes are made (idempotence)
1340-
const run8 = b.addSystemCommand(&.{ b.graph.zig_exe, "fmt", "fmt7.zig" });
1341-
run8.setName("run zig fmt again on array with switch");
1342-
run8.setCwd(.{ .cwd_relative = tmp_path });
1343-
run8.has_side_effects = true;
1344-
run8.step.dependOn(&check7.step);
1345-
13461302
const cleanup = b.addRemoveDirTree(.{ .cwd_relative = tmp_path });
13471303
cleanup.step.dependOn(&check6.step);
13481304

0 commit comments

Comments
 (0)