authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2025-08-13 11:42:58+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-14 14:44:35-07:00
log2761cc8be0ef89772a41cb0aaf512ac463aa5c23
tree3d0375b58d72fcb5237d952315a0fef15572cb90
parentbe51d69dc7cff9d2c2a1de55c94ff92f5a897fe7

zig fmt: add tests for cast builtin canonicalization


1 files changed, 19 insertions(+), 0 deletions(-)

lib/std/zig/parser_test.zig+19
...@@ -6056,6 +6056,25 @@ test "zig fmt: indentation of comments within catch, else, orelse" {...@@ -6056,6 +6056,25 @@ test "zig fmt: indentation of comments within catch, else, orelse" {
6056 );6056 );
6057}6057}
60586058
6059test "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
6071test "zig fmt: do not canonicalize invalid cast builtins" {
6072 try testCanonical(
6073 \\const foo = @alignCast(@volatileCast(@ptrCast(@alignCast(bar))));
6074 \\
6075 );
6076}
6077
6059test "recovery: top level" {6078test "recovery: top level" {
6060 try testError(6079 try testError(
6061 \\test "" {inline}6080 \\test "" {inline}