diff --git a/parser_test.zig b/parser_test.zig index 11a8f119e4..bb2d945fcf 100644 --- a/parser_test.zig +++ b/parser_test.zig @@ -4238,6 +4238,112 @@ test "zig fmt: decimal float literals with underscore separators" { ); } +test "zig fmt: fix single statement if/for/while line breaks" { + try testTransform( + \\test { + \\ if (cond) a + \\ else b; + \\ + \\ if (cond) + \\ a + \\ else b; + \\ + \\ for (xs) |x| foo() + \\ else bar(); + \\ + \\ for (xs) |x| + \\ foo() + \\ else bar(); + \\ + \\ while (a) : (b) foo() + \\ else bar(); + \\ + \\ while (a) : (b) + \\ foo() + \\ else bar(); + \\} + \\ + , + \\test { + \\ if (cond) a else b; + \\ + \\ if (cond) + \\ a + \\ else + \\ b; + \\ + \\ for (xs) |x| foo() else bar(); + \\ + \\ for (xs) |x| + \\ foo() + \\ else + \\ bar(); + \\ + \\ while (a) : (b) foo() else bar(); + \\ + \\ while (a) : (b) + \\ foo() + \\ else + \\ bar(); + \\} + \\ + ); +} + + +test "zig fmt: fn type" { + try testCanonical( + \\fn a(i: u8) u8 { + \\ return i + 1; + \\} + \\ + \\const a: fn (u8) u8 = undefined; + \\const b: fn (u8) callconv(.naked) u8 = undefined; + \\const ap: fn (u8) u8 = a; + \\ + ); +} + +test "zig fmt: nosuspend" { + try testCanonical( + \\const a = nosuspend foo(); + \\ + ); +} + +test "zig fmt: Block after if" { + try testCanonical( + \\test { + \\ if (true) { + \\ const a = 0; + \\ } + \\ + \\ { + \\ const a = 0; + \\ } + \\} + \\ + ); +} + +test "zig fmt: string identifier" { + try testCanonical( + \\const @"a b" = @"c d".@"e f"; + \\fn @"g h"() void {} + \\ + ); +} + +test "zig fmt: error return" { + try testCanonical( + \\fn err() anyerror { + \\ call(); + \\ return error.InvalidArgs; + \\} + \\ + ); +} + test "Ast header smoke test" { try std.testing.expectEqual(zigNode(c.AST_NODE_IF), Ast.Node.Tag.@"if"); }