authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-28 21:28:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-28 21:28:32-04:00
log71badebd08a1e5da9326fc7126c4de0fba4ae3d0
tree41d485179551ec61344789793d32a01853bdf9ec
parent354ab1c5c8ec62c485fbc297817a0e70ab625a71

zig fmt: respect line breaks after infix operators


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

std/zig/parser_test.zig+17
......@@ -1,3 +1,20 @@
1test "zig fmt: respect line breaks after infix operators" {
2 try testCanonical(
3 \\comptime {
4 \\ self.crc =
5 \\ lookup_tables[0][p[7]] ^
6 \\ lookup_tables[1][p[6]] ^
7 \\ lookup_tables[2][p[5]] ^
8 \\ lookup_tables[3][p[4]] ^
9 \\ lookup_tables[4][@truncate(u8, self.crc >> 24)] ^
10 \\ lookup_tables[5][@truncate(u8, self.crc >> 16)] ^
11 \\ lookup_tables[6][@truncate(u8, self.crc >> 8)] ^
12 \\ lookup_tables[7][@truncate(u8, self.crc >> 0)];
13 \\}
14 \\
15 );
16}
17
118test "zig fmt: fn decl with trailing comma" {
219 try testTransform(
320 \\fn foo(a: i32, b: i32,) void {}
std/zig/render.zig+11-1
......@@ -254,7 +254,17 @@ fn renderExpression(allocator: &mem.Allocator, stream: var, tree: &ast.Tree, ind
254254 else => Space.Space,
255255 };
256256 try renderExpression(allocator, stream, tree, indent, infix_op_node.lhs, op_space);
257 try renderToken(tree, stream, infix_op_node.op_token, indent, op_space);
257
258 const after_op_space = blk: {
259 const loc = tree.tokenLocation(tree.tokens.at(infix_op_node.op_token).end,
260 tree.nextToken(infix_op_node.op_token));
261 break :blk if (loc.line == 0) op_space else Space.Newline;
262 };
263
264 try renderToken(tree, stream, infix_op_node.op_token, indent, after_op_space);
265 if (after_op_space == Space.Newline) {
266 try stream.writeByteNTimes(' ', indent + indent_delta);
267 }
258268
259269 switch (infix_op_node.op) {
260270 ast.Node.InfixOp.Op.Catch => |maybe_payload| if (maybe_payload) |payload| {