1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

split: fix for GNU Tests regression + tests

This commit is contained in:
zhitkoff 2023-08-29 15:49:47 -04:00
parent e79753c1cf
commit 15c7170d20
2 changed files with 76 additions and 4 deletions

View file

@ -76,8 +76,16 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
let filtered_args = args
.iter()
.filter_map(|slice| {
if slice.starts_with('-') && !slice.starts_with("--") {
if slice.starts_with('-')
&& !slice.starts_with("--")
&& !slice.starts_with("-a")
&& !slice.starts_with("-b")
&& !slice.starts_with("-C")
&& !slice.starts_with("-l")
&& !slice.starts_with("-n")
{
// start of the short option string
// that can have obsolete lines option value in it
// extract numeric part and filter it out
let mut obs_lines_extracted: Vec<char> = vec![];
let filtered_slice: Vec<char> = slice
@ -102,15 +110,14 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
// there were some short options in front of or after obsolete lines value
// i.e. '-xd100' or '-100de' or similar, which after extraction of obsolete lines value
// would look like '-xd' or '-de' or similar
// preserve it
Some(filtered_slice.iter().collect())
} else {
None
}
}
} else {
// not a short option
// preserve it
// either not a short option
// or a short option that cannot have obsolete lines value in it
Some(slice.to_owned())
}
})

View file

@ -170,6 +170,22 @@ fn test_split_str_prefixed_chunks_by_bytes() {
assert_eq!(glob.collate(), at.read_bytes(name));
}
// Test short bytes option concatenated with value
#[test]
fn test_split_by_bytes_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
let name = "split_by_bytes_short_concatenated_with_value";
RandomFile::new(&at, name).add_bytes(10000);
ucmd.args(&["-b1000", name]).succeeds();
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$");
assert_eq!(glob.count(), 10);
for filename in glob.collect() {
assert_eq!(glob.directory.metadata(&filename).len(), 1000);
}
assert_eq!(glob.collate(), at.read_bytes(name));
}
// This is designed to test what happens when the desired part size is not a
// multiple of the buffer size and we hopefully don't overshoot the desired part
// size.
@ -326,6 +342,19 @@ fn test_split_lines_number() {
.stderr_only("split: invalid number of lines: 'file'\n");
}
// Test short lines option with value concatenated
#[test]
fn test_split_lines_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
let name = "split_num_prefixed_chunks_by_lines";
RandomFile::new(&at, name).add_lines(10000);
ucmd.args(&["-l1000", name]).succeeds();
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]]$");
assert_eq!(glob.count(), 10);
assert_eq!(glob.collate(), at.read_bytes(name));
}
/// Test for obsolete lines option standalone
#[test]
fn test_split_obs_lines_standalone() {
@ -692,6 +721,19 @@ fn test_invalid_suffix_length() {
.stderr_contains("invalid suffix length: 'xyz'");
}
// Test short suffix length option with value concatenated
#[test]
fn test_split_suffix_length_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
let name = "split_num_prefixed_chunks_by_lines";
RandomFile::new(&at, name).add_lines(10000);
ucmd.args(&["-a4", name]).succeeds();
let glob = Glob::new(&at, ".", r"x[[:alpha:]][[:alpha:]][[:alpha:]][[:alpha:]]$");
assert_eq!(glob.count(), 10);
assert_eq!(glob.collate(), at.read_bytes(name));
}
#[test]
fn test_include_newlines() {
let (at, mut ucmd) = at_and_ucmd!();
@ -710,6 +752,19 @@ fn test_include_newlines() {
assert_eq!(s, "5\n");
}
// Test short number of chunks option concatenated with value
#[test]
fn test_split_number_chunks_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-n3", "threebytes.txt"])
.succeeds()
.no_stdout()
.no_stderr();
assert_eq!(at.read("xaa"), "a");
assert_eq!(at.read("xab"), "b");
assert_eq!(at.read("xac"), "c");
}
#[test]
fn test_allow_empty_files() {
let (at, mut ucmd) = at_and_ucmd!();
@ -784,6 +839,16 @@ fn test_line_bytes() {
assert_eq!(at.read("xad"), "ee\n");
}
#[test]
fn test_line_bytes_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
ucmd.args(&["-C8", "letters.txt"]).succeeds();
assert_eq!(at.read("xaa"), "aaaaaaaa");
assert_eq!(at.read("xab"), "a\nbbbb\n");
assert_eq!(at.read("xac"), "cccc\ndd\n");
assert_eq!(at.read("xad"), "ee\n");
}
#[test]
fn test_line_bytes_no_final_newline() {
let (at, mut ucmd) = at_and_ucmd!();