diff --git a/parser_test.zig b/parser_test.zig index 0bcd3a0b0f..75f6446d93 100644 --- a/parser_test.zig +++ b/parser_test.zig @@ -222,11 +222,11 @@ fn zigData(tag: Ast.Node.Tag, lhs: u32, rhs: u32) Ast.Node.Data { .address_of, .@"try", .deref, + .optional_type, => .{ .node = toIndex(lhs) }, // .opt_node (single optional node) .@"return", - .optional_type, => .{ .opt_node = toOptIndex(lhs) }, // .node_and_node @@ -649,3 +649,88 @@ test "zig fmt: respect line breaks after var declarations" { \\ ); } + +test "zig fmt: multiline string mixed with comments" { + try testCanonical( + \\const s1 = + \\ //\\one + \\ \\two) + \\ \\three + \\; + \\const s2 = + \\ \\one + \\ \\two) + \\ //\\three + \\; + \\const s3 = + \\ \\one + \\ //\\two) + \\ \\three + \\; + \\const s4 = + \\ \\one + \\ //\\two + \\ \\three + \\ //\\four + \\ \\five + \\; + \\const a = + \\ 1; + \\ + ); +} + +test "zig fmt: empty file" { + try testCanonical( + \\ + ); +} + +test "zig fmt: file ends in comment" { + try testTransform( + \\ //foobar + , + \\//foobar + \\ + ); +} + +test "zig fmt: file ends in multi line comment" { + try testTransform( + \\ \\foobar + , + \\\\foobar + \\ + ); +} + +test "zig fmt: file ends in comment after var decl" { + try testTransform( + \\const x = 42; + \\ //foobar + , + \\const x = 42; + \\//foobar + \\ + ); +} + +test "zig fmt: top-level fields" { + try testCanonical( + \\a: did_you_know, + \\b: all_files_are, + \\structs: ?x, + \\ + ); +} + +test "zig fmt: container declaration, single line" { + try testCanonical( + \\const X = struct { foo: i32 }; + \\const X = struct { foo: i32, bar: i32 }; + \\const X = struct { foo: i32 = 1, bar: i32 = 2 }; + \\const X = struct { foo: i32 align(4), bar: i32 align(4) }; + \\const X = struct { foo: i32 align(4) = 1, bar: i32 align(4) = 2 }; + \\ + ); +}