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

split: edge case for obs lines within combined shorts + test

This commit is contained in:
zhitkoff 2023-08-29 16:35:00 -04:00
parent 15c7170d20
commit 7f905a3b8d
2 changed files with 25 additions and 5 deletions

View file

@ -88,13 +88,20 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, 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 mut obs_lines_end_reached = false;
let filtered_slice: Vec<char> = slice
.chars()
.filter(|c| {
if c.is_ascii_digit() {
// To correctly process scenario like '-x200a4'
// we need to stop extracting digits once alphabetic character is encountered
// after we already have something in obs_lines_extracted
if c.is_ascii_digit() && !obs_lines_end_reached {
obs_lines_extracted.push(*c);
false
} else {
if !obs_lines_extracted.is_empty() {
obs_lines_end_reached = true;
}
true
}
})

View file

@ -170,7 +170,7 @@ fn test_split_str_prefixed_chunks_by_bytes() {
assert_eq!(glob.collate(), at.read_bytes(name));
}
// Test short bytes option concatenated with value
/// Test short bytes option concatenated with value
#[test]
fn test_split_by_bytes_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
@ -342,7 +342,7 @@ fn test_split_lines_number() {
.stderr_only("split: invalid number of lines: 'file'\n");
}
// Test short lines option with value concatenated
/// Test short lines option with value concatenated
#[test]
fn test_split_lines_short_concatenated_with_value() {
let (at, mut ucmd) = at_and_ucmd!();
@ -401,6 +401,19 @@ fn test_split_obs_lines_within_combined_shorts() {
assert_eq!(glob.collate(), at.read_bytes(name))
}
/// Test for obsolete lines option as part of combined short options with tailing suffix length with value
#[test]
fn test_split_obs_lines_within_combined_shorts_tailing_suffix_length() {
let (at, mut ucmd) = at_and_ucmd!();
let name = "obs-lines-combined-shorts-tailing-suffix-length";
RandomFile::new(&at, name).add_lines(1000);
ucmd.args(&["-d200a4", name]).succeeds();
let glob = Glob::new(&at, ".", r"x\d\d\d\d$");
assert_eq!(glob.count(), 5);
assert_eq!(glob.collate(), at.read_bytes(name));
}
/// Test for obsolete lines option starts as part of combined short options
#[test]
fn test_split_obs_lines_starts_combined_shorts() {
@ -721,7 +734,7 @@ fn test_invalid_suffix_length() {
.stderr_contains("invalid suffix length: 'xyz'");
}
// Test short suffix length option with value concatenated
/// 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!();
@ -752,7 +765,7 @@ fn test_include_newlines() {
assert_eq!(s, "5\n");
}
// Test short number of chunks option concatenated with value
/// 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!();