Skip to content

Commit 7aa5409

Browse files
nagendramohansylvestre
authored andcommitted
diff: compare full -y stdout in the gutter marker test
Per review, assert the exact stdout for both --expand-tabs and the default tab path instead of a column helper, so the test also pins the exact tabs/spaces emitted.
1 parent 8b9908f commit 7aa5409

1 file changed

Lines changed: 7 additions & 20 deletions

File tree

‎tests/integration.rs‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,21 +344,6 @@ mod diff {
344344
Ok(())
345345
}
346346

347-
// Visual (tab-aware) column of the `-y` gutter marker on the first output line.
348-
fn side_marker_visual_column(output: &[u8], tabsize: usize) -> Option<usize> {
349-
let text = String::from_utf8_lossy(output);
350-
let line = text.lines().next()?;
351-
let mut col = 0;
352-
for c in line.chars() {
353-
match c {
354-
'<' | '|' | '>' => return Some(col),
355-
'\t' => col += tabsize - (col % tabsize),
356-
_ => col += 1,
357-
}
358-
}
359-
None
360-
}
361-
362347
// Regression for #269: the `-y` gutter marker must sit at the middle of the gutter.
363348
#[test]
364349
fn sdiff_gutter_marker_column() -> Result<(), Box<dyn std::error::Error>> {
@@ -367,7 +352,7 @@ mod diff {
367352
let mut file2 = NamedTempFile::new()?;
368353
file2.write_all("bb\n".as_bytes())?;
369354

370-
// --expand-tabs: padding is spaces, marker lands at visual column 19.
355+
// --expand-tabs: padding is spaces.
371356
let mut cmd = cargo_bin_cmd!("diffutils");
372357
cmd.arg("diff")
373358
.arg("-y")
@@ -376,18 +361,20 @@ mod diff {
376361
.arg(file1.path())
377362
.arg(file2.path());
378363
let output = cmd.output().unwrap().stdout;
379-
assert_eq!(side_marker_visual_column(&output, 8), Some(19));
364+
assert_eq!(
365+
output,
366+
b"aa <\n > bb\n"
367+
);
380368

381-
// Default (expand_tabs: false): padding goes through the tab path, but the
382-
// marker must still land at the same visual column.
369+
// Default (expand_tabs: false): padding goes through the tab path.
383370
let mut cmd = cargo_bin_cmd!("diffutils");
384371
cmd.arg("diff")
385372
.arg("-y")
386373
.arg("--width=40")
387374
.arg(file1.path())
388375
.arg(file2.path());
389376
let output = cmd.output().unwrap().stdout;
390-
assert_eq!(side_marker_visual_column(&output, 8), Some(19));
377+
assert_eq!(output, b"aa\t\t <\n\t\t >\tbb\n");
391378

392379
Ok(())
393380
}

0 commit comments

Comments
 (0)