zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit db4c15be507a55f63b7f19dd4cdc10717f44eb06 (tree)
parent bf642204b373e01314ecfb0c50a643dc4b05746f
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Tue, 23 Feb 2021 23:01:16 -0700

zig fmt: respect extra newline between fn and pub usingnamespace

Diffstat:
Mlib/std/zig/ast.zig | 9++++++++-
Mlib/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 @@ -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 @@ -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" {