Skip to content

Commit 2761cc8

Browse files
Justus2308andrewrk
authored andcommitted
zig fmt: add tests for cast builtin canonicalization
1 parent be51d69 commit 2761cc8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/std/zig/parser_test.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6056,6 +6056,25 @@ test "zig fmt: indentation of comments within catch, else, orelse" {
60566056
);
60576057
}
60586058

6059+
test "zig fmt: canonicalize cast builtins" {
6060+
try testTransform(
6061+
\\const foo = @alignCast(@ptrCast(bar));
6062+
\\const baz = @constCast(@ptrCast(@addrSpaceCast(@volatileCast(@alignCast(bar)))));
6063+
\\
6064+
,
6065+
\\const foo = @ptrCast(@alignCast(bar));
6066+
\\const baz = @ptrCast(@alignCast(@addrSpaceCast(@constCast(@volatileCast(bar)))));
6067+
\\
6068+
);
6069+
}
6070+
6071+
test "zig fmt: do not canonicalize invalid cast builtins" {
6072+
try testCanonical(
6073+
\\const foo = @alignCast(@volatileCast(@ptrCast(@alignCast(bar))));
6074+
\\
6075+
);
6076+
}
6077+
60596078
test "recovery: top level" {
60606079
try testError(
60616080
\\test "" {inline}

0 commit comments

Comments
 (0)