Merge pull request #7636 from karlmcdowall/cat_find_a_bug_fix_a_bug

cat: bugfix when running with -T option
This commit is contained in:
Daniel Hofstetter 2025-04-03 09:35:09 +02:00 committed by GitHub
commit 7af2c94678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View file

@ -644,7 +644,7 @@ fn write_tab_to_end<W: Write>(mut in_buf: &[u8], writer: &mut W) -> usize {
}
None => {
writer.write_all(in_buf).unwrap();
return in_buf.len();
return in_buf.len() + count;
}
};
}
@ -688,6 +688,20 @@ fn write_end_of_line<W: Write>(
mod tests {
use std::io::{BufWriter, stdout};
#[test]
fn test_write_tab_to_end_with_newline() {
let mut writer = BufWriter::with_capacity(1024 * 64, stdout());
let in_buf = b"a\tb\tc\n";
assert_eq!(super::write_tab_to_end(in_buf, &mut writer), 5);
}
#[test]
fn test_write_tab_to_end_no_newline() {
let mut writer = BufWriter::with_capacity(1024 * 64, stdout());
let in_buf = b"a\tb\tc";
assert_eq!(super::write_tab_to_end(in_buf, &mut writer), 5);
}
#[test]
fn test_write_nonprint_to_end_new_line() {
let mut writer = BufWriter::with_capacity(1024 * 64, stdout());

View file

@ -414,6 +414,15 @@ fn test_stdin_nonprinting_and_tabs_repeated() {
.stdout_only("^I^@\n");
}
#[test]
fn test_stdin_tabs_no_newline() {
new_ucmd!()
.args(&["-T"])
.pipe_in("\ta")
.succeeds()
.stdout_only("^Ia");
}
#[test]
fn test_stdin_squeeze_blank() {
for same_param in ["-s", "--squeeze-blank", "--squeeze"] {