diff: place -y gutter marker at the middle of the gutter - #277
nagendramohan wants to merge 2 commits into
Conversation
In side-by-side output the gutter marker was written wherever process_half_line stopped padding the left half (one column past sdiff_half_width), not at separator_pos (the middle of the gutter). Those agree only when the gutter is 3 or 4 columns wide, so the default --width=130 --tabsize=8 (gutter 3) looked right while other widths/tab sizes drifted (e.g. --width=40 placed '<' at column 17 instead of 19). Pad from half_width + 1 up to separator_pos before writing the marker so it lands at the gutter middle, matching GNU sdiff. format_tabs_and_spaces is a no-op when already at/past separator_pos, so narrow gutters are unaffected. Add a regression test at --width=40. Fixes uutils#269
|
GNU diffutils testsuite comparison: |
| // `process_half_line` left the cursor one column past the half width. The gutter marker | ||
| // belongs at the middle of the gutter (`separator_pos`), which is only `half_width + 1` | ||
| // when the gutter is 3 or 4 columns wide; pad up to it for wider gutters so the marker | ||
| // doesn't drift (see #269). `format_tabs_and_spaces` is a no-op when already at/past it. |
There was a problem hiding this comment.
4 lines of comment for a one-liner, could you please make it shorter? :)
| // Regression test for #269: the `-y` gutter marker must sit at the middle of the gutter | ||
| // (separator_pos) regardless of gutter width. At the default width (gutter 3) the marker | ||
| // was already correct; at other widths it drifted. Here width=40 yields a wider gutter, so | ||
| // the marker must land at column 19 (matching GNU), not the old `half_width + 1`. |
There was a problem hiding this comment.
same here, please make it shorter
| // (separator_pos) regardless of gutter width. At the default width (gutter 3) the marker | ||
| // was already correct; at other widths it drifted. Here width=40 yields a wider gutter, so | ||
| // the marker must land at column 19 (matching GNU), not the old `half_width + 1`. | ||
| #[test] |
There was a problem hiding this comment.
please also add a test in tests/integration.rs with -y --width=40
There was a problem hiding this comment.
Thanks! Shortened both comments and added an integration test covering -y --width=40 in both --expand-tabs and the default (tab-path) modes, asserting the marker sits at the gutter middle.
| let params = Params { | ||
| tabsize: 8, | ||
| expand_tabs: true, | ||
| width: 40, |
There was a problem hiding this comment.
could you please also test with expand_tabs: false?
that is the default, and the padding goes through the tab path
Shorten the two long comments per review, and add an integration test in tests/integration.rs exercising `-y --width=40` in both the default (expand_tabs: false, tab-padding path) and --expand-tabs modes, asserting the gutter marker lands at the middle of the gutter.
| } | ||
|
|
||
| // Visual (tab-aware) column of the `-y` gutter marker on the first output line. | ||
| fn side_marker_visual_column(output: &[u8], tabsize: usize) -> Option<usize> { |
There was a problem hiding this comment.
could we just compare the whole stdout instead of this helper?
simpler, and it would also check the exact tabs/spaces emitted
In side-by-side (
-y) output the gutter marker was written whereverprocess_half_linestoppedpadding the left half (one column past
sdiff_half_width), not atseparator_pos(the middle ofthe gutter). Those agree only when the gutter is 3–4 columns wide, so the default
--width=130 --tabsize=8(gutter 3) looked right while other widths/tab sizes drifted — e.g.--width=40placed<at column 17 instead of 19.Pad from
half_width + 1up toseparator_posbefore writing the marker so it lands at the guttermiddle, matching GNU sdiff.
format_tabs_and_spacesis a no-op when already at/pastseparator_pos,so narrow gutters are unaffected. Added a regression test at
--width=40.Fixes #269.