commit 2761cc8be0ef89772a41cb0aaf512ac463aa5c23 (tree) parent be51d69dc7cff9d2c2a1de55c94ff92f5a897fe7 Author: Justus Klausecker <justus@klausecker.de> Date: Wed, 13 Aug 2025 11:42:58 +0200 zig fmt: add tests for cast builtin canonicalization Diffstat:
| M | lib/std/zig/parser_test.zig | | | 19 | +++++++++++++++++++ |
1 file changed, 19 insertions(+), 0 deletions(-)
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig @@ -6056,6 +6056,25 @@ test "zig fmt: indentation of comments within catch, else, orelse" { ); } +test "zig fmt: canonicalize cast builtins" { + try testTransform( + \\const foo = @alignCast(@ptrCast(bar)); + \\const baz = @constCast(@ptrCast(@addrSpaceCast(@volatileCast(@alignCast(bar))))); + \\ + , + \\const foo = @ptrCast(@alignCast(bar)); + \\const baz = @ptrCast(@alignCast(@addrSpaceCast(@constCast(@volatileCast(bar))))); + \\ + ); +} + +test "zig fmt: do not canonicalize invalid cast builtins" { + try testCanonical( + \\const foo = @alignCast(@volatileCast(@ptrCast(@alignCast(bar)))); + \\ + ); +} + test "recovery: top level" { try testError( \\test "" {inline}