authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-05 12:29:02+01:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-03-05 21:33:27+01:00
logef3adbdb362d5511b05543567c58c5bdfb0cf093
tree7a8da7dbc02462cfdc8dd014cbf14ecccd34d04b
parent9cd038d73a174706ec0a51ab9db0c04b095e019d

zig fmt: fix lastToken() for container_decl_arg


2 files changed, 22 insertions(+), 1 deletions(-)

lib/std/zig/ast.zig+1-1
...@@ -766,7 +766,7 @@ pub const Tree = struct {...@@ -766,7 +766,7 @@ pub const Tree = struct {
766 .container_decl_arg => {766 .container_decl_arg => {
767 const members = tree.extraData(datas[n].rhs, Node.SubRange);767 const members = tree.extraData(datas[n].rhs, Node.SubRange);
768 if (members.end - members.start == 0) {768 if (members.end - members.start == 0) {
769 end_offset += 1; // for the rparen769 end_offset += 3; // for the rparen + lbrace + rbrace
770 n = datas[n].lhs;770 n = datas[n].lhs;
771 } else {771 } else {
772 end_offset += 1; // for the rbrace772 end_offset += 1; // for the rbrace
lib/std/zig/parser_test.zig+21
...@@ -963,6 +963,27 @@ test "zig fmt: allowzero pointer" {...@@ -963,6 +963,27 @@ test "zig fmt: allowzero pointer" {
963 );963 );
964}964}
965965
966test "zig fmt: empty enum decls" {
967 try testCanonical(
968 \\const A = enum {};
969 \\const B = enum(u32) {};
970 \\const C = extern enum(c_int) {};
971 \\const D = packed enum(u8) {};
972 \\
973 );
974}
975
976test "zig fmt: empty union decls" {
977 try testCanonical(
978 \\const A = union {};
979 \\const B = union(enum) {};
980 \\const C = union(Foo) {};
981 \\const D = extern union {};
982 \\const E = packed union {};
983 \\
984 );
985}
986
966test "zig fmt: enum literal" {987test "zig fmt: enum literal" {
967 try testCanonical(988 try testCanonical(
968 \\const x = .hi;989 \\const x = .hi;