diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-23 23:01:16 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-23 23:01:16 -0700 |
| commit | db4c15be507a55f63b7f19dd4cdc10717f44eb06 (patch) | |
| tree | a8cb11233a939fb1f6187cbbdd60df43c08c1789 | |
| parent | bf642204b373e01314ecfb0c50a643dc4b05746f (diff) | |
| download | zig-db4c15be507a55f63b7f19dd4cdc10717f44eb06.tar.gz zig-db4c15be507a55f63b7f19dd4cdc10717f44eb06.zip | |
zig fmt: respect extra newline between fn and pub usingnamespace
| -rw-r--r-- | lib/std/zig/ast.zig | 9 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 21 |
2 files changed, 18 insertions, 12 deletions
diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 98ffe26818..f2418f7c11 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -321,7 +321,6 @@ pub const Tree = struct { while (true) switch (tags[n]) { .root => return 0, - .@"usingnamespace", .test_decl, .@"errdefer", .@"defer", @@ -468,6 +467,14 @@ pub const Tree = struct { return i - end_offset; }, + .@"usingnamespace" => { + const main_token = main_tokens[n]; + if (main_token > 0 and token_tags[main_token - 1] == .keyword_pub) { + end_offset += 1; + } + return main_token - end_offset; + }, + .async_call_one, .async_call_one_comma, .async_call, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 3f25b570c3..6b81f9a16e 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -4178,17 +4178,16 @@ test "zig fmt: for loop with ptr payload and index" { // ); //} -// TODO -//test "zig fmt: respect extra newline between fn and pub usingnamespace" { -// try testCanonical( -// \\fn foo() void { -// \\ bar(); -// \\} -// \\ -// \\pub usingnamespace baz; -// \\ -// ); -//} +test "zig fmt: respect extra newline between fn and pub usingnamespace" { + try testCanonical( + \\fn foo() void { + \\ bar(); + \\} + \\ + \\pub usingnamespace baz; + \\ + ); +} // TODO //test "zig fmt: respect extra newline between switch items" { |
