| author | |
| committer | |
| log | 4081e0a475670cf3c0301c795c67e1bc692024e1 |
| tree | f992406e5315d31f6572223dcd0b09666bd61ad0 |
| parent | 8e6865c8eeff477375113f3c56f378d0e40ffecd |
Currently an indented `// zig fmt: on` will be indented an additional
time on every run of zig fmt.2 files changed, 23 insertions(+), 2 deletions(-)
lib/std/zig/parser_test.zig+21| ... | @@ -1315,6 +1315,27 @@ test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" { | ... | @@ -1315,6 +1315,27 @@ test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" { |
| 1315 | ); | 1315 | ); |
| 1316 | } | 1316 | } |
| 1317 | 1317 | ||
| 1318 | test "zig fmt: 'zig fmt: on' indentation is unchanged" { | ||
| 1319 | try testCanonical( | ||
| 1320 | \\fn initOptionsAndLayouts(output: *Output, context: *Context) !void { | ||
| 1321 | \\ // zig fmt: off | ||
| 1322 | \\ try output.main_amount.init(output, "main_amount"); errdefer optput.main_amount.deinit(); | ||
| 1323 | \\ try output.main_factor.init(output, "main_factor"); errdefer optput.main_factor.deinit(); | ||
| 1324 | \\ try output.view_padding.init(output, "view_padding"); errdefer optput.view_padding.deinit(); | ||
| 1325 | \\ try output.outer_padding.init(output, "outer_padding"); errdefer optput.outer_padding.deinit(); | ||
| 1326 | \\ // zig fmt: on | ||
| 1327 | \\ | ||
| 1328 | \\ // zig fmt: off | ||
| 1329 | \\ try output.top.init(output, .top); errdefer optput.top.deinit(); | ||
| 1330 | \\ try output.right.init(output, .right); errdefer optput.right.deinit(); | ||
| 1331 | \\ try output.bottom.init(output, .bottom); errdefer optput.bottom.deinit(); | ||
| 1332 | \\ try output.left.init(output, .left); errdefer optput.left.deinit(); | ||
| 1333 | \\ // zig fmt: on | ||
| 1334 | \\} | ||
| 1335 | \\ | ||
| 1336 | ); | ||
| 1337 | } | ||
| 1338 | |||
| 1318 | test "zig fmt: pointer of unknown length" { | 1339 | test "zig fmt: pointer of unknown length" { |
| 1319 | try testCanonical( | 1340 | try testCanonical( |
| 1320 | \\fn foo(ptr: [*]u8) void {} | 1341 | \\fn foo(ptr: [*]u8) void {} |
lib/std/zig/render.zig+2-2| ... | @@ -2311,9 +2311,9 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo | ... | @@ -2311,9 +2311,9 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo |
| 2311 | // to the underlying writer, fixing up invaild whitespace. | 2311 | // to the underlying writer, fixing up invaild whitespace. |
| 2312 | const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; | 2312 | const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; |
| 2313 | try writeFixingWhitespace(ais.underlying_writer, disabled_source); | 2313 | try writeFixingWhitespace(ais.underlying_writer, disabled_source); |
| 2314 | ais.disabled_offset = null; | ||
| 2315 | // Write with the canonical single space. | 2314 | // Write with the canonical single space. |
| 2316 | try ais.writer().writeAll("// zig fmt: on\n"); | 2315 | try ais.underlying_writer.writeAll("// zig fmt: on\n"); |
| 2316 | ais.disabled_offset = null; | ||
| 2317 | } else if (ais.disabled_offset == null and mem.eql(u8, comment_content, "zig fmt: off")) { | 2317 | } else if (ais.disabled_offset == null and mem.eql(u8, comment_content, "zig fmt: off")) { |
| 2318 | // Write with the canonical single space. | 2318 | // Write with the canonical single space. |
| 2319 | try ais.writer().writeAll("// zig fmt: off\n"); | 2319 | try ais.writer().writeAll("// zig fmt: off\n"); |