1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #6990 from cakebaker/cut_ob_abut

cut: don't merge adjacent ranges
This commit is contained in:
Sylvestre Ledru 2024-12-22 16:19:07 +01:00 committed by GitHub
commit e736c2ae36
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 9 deletions

View file

@ -91,7 +91,7 @@ impl Range {
Ok(Self::merge(ranges))
}
/// Merge any overlapping ranges
/// Merge any overlapping ranges. Adjacent ranges are *NOT* merged.
///
/// Is guaranteed to return only disjoint ranges in a sorted order.
fn merge(mut ranges: Vec<Self>) -> Vec<Self> {
@ -101,10 +101,7 @@ impl Range {
for i in 0..ranges.len() {
let j = i + 1;
// The +1 is a small optimization, because we can merge adjacent Ranges.
// For example (1,3) and (4,6), because in the integers, there are no
// possible values between 3 and 4, this is equivalent to (1,6).
while j < ranges.len() && ranges[j].low <= ranges[i].high + 1 {
while j < ranges.len() && ranges[j].low <= ranges[i].high {
let j_high = ranges.remove(j).high;
ranges[i].high = max(ranges[i].high, j_high);
}
@ -216,8 +213,8 @@ mod test {
&[r(10, 40), r(50, 60)],
);
// Merge adjacent ranges
m(vec![r(1, 3), r(4, 6)], &[r(1, 6)]);
// Don't merge adjacent ranges
m(vec![r(1, 3), r(4, 6)], &[r(1, 3), r(4, 6)]);
}
#[test]

View file

@ -350,7 +350,6 @@ fn test_newline_preservation_with_f1_option() {
ucmd.args(&["-f1-", "1"]).succeeds().stdout_is(expected);
}
#[ignore = "Not yet implemented"]
#[test]
fn test_output_delimiter_with_character_ranges() {
new_ucmd!()
@ -360,7 +359,6 @@ fn test_output_delimiter_with_character_ranges() {
.stdout_only("bc:defg\n");
}
#[ignore = "Not yet implemented"]
#[test]
fn test_output_delimiter_with_adjacent_ranges() {
new_ucmd!()