| author | |
| committer | |
| log | c477df98bbddb35e3abb7d88fbe7e250660458b8 |
| tree | 8b537d7f131859370d8f437165c6e3ff69525995 |
| parent | 9014daedbbb0630ee438ab64302dd0e0697759ba |
2 files changed, 19 insertions(+), 2 deletions(-)
lib/std/zig/Ast/Render.zig+2-2| ... | @@ -3883,8 +3883,8 @@ const AutoIndentingStream = struct { | ... | @@ -3883,8 +3883,8 @@ const AutoIndentingStream = struct { |
| 3883 | /// Writes ' ' bytes if the current line is empty | 3883 | /// Writes ' ' bytes if the current line is empty |
| 3884 | fn applyIndent(ais: *AutoIndentingStream) Error!void { | 3884 | fn applyIndent(ais: *AutoIndentingStream) Error!void { |
| 3885 | const current_indent = ais.currentIndent(); | 3885 | const current_indent = ais.currentIndent(); |
| 3886 | if (ais.current_line_empty and current_indent > 0) { | 3886 | if (ais.current_line_empty) { |
| 3887 | if (ais.disabled_offset == null) { | 3887 | if (current_indent > 0 and ais.disabled_offset == null) { |
| 3888 | try ais.underlying_writer.splatByteAll(' ', current_indent); | 3888 | try ais.underlying_writer.splatByteAll(' ', current_indent); |
| 3889 | } | 3889 | } |
| 3890 | ais.applied_indent = current_indent; | 3890 | ais.applied_indent = current_indent; |
lib/std/zig/parser_test.zig+17| ... | @@ -6676,6 +6676,23 @@ test "zig fmt: doc comments on fn parameters" { | ... | @@ -6676,6 +6676,23 @@ test "zig fmt: doc comments on fn parameters" { |
| 6676 | ); | 6676 | ); |
| 6677 | } | 6677 | } |
| 6678 | 6678 | ||
| 6679 | test "zig fmt: proper tracking of indentation" { | ||
| 6680 | try testCanonical( | ||
| 6681 | \\const a = { | ||
| 6682 | \\ {} | ||
| 6683 | \\}; | ||
| 6684 | \\const b = if (x) {}; | ||
| 6685 | \\const c = .{ | ||
| 6686 | \\ { | ||
| 6687 | \\ {} | ||
| 6688 | \\ } // | ||
| 6689 | \\ , | ||
| 6690 | \\ if (x) {}, | ||
| 6691 | \\}; | ||
| 6692 | \\ | ||
| 6693 | ); | ||
| 6694 | } | ||
| 6695 | |||
| 6679 | test "zig fmt: canonicalize stray backslashes in identifiers" { | 6696 | test "zig fmt: canonicalize stray backslashes in identifiers" { |
| 6680 | try testTransform( | 6697 | try testTransform( |
| 6681 | \\const @"\x" = undefined; | 6698 | \\const @"\x" = undefined; |