Skip to content

Commit 8ab534b

Browse files
committed
cut: don't merge adjacent ranges
1 parent 913d5d4 commit 8ab534b

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/uucore/src/lib/features/ranges.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Range {
9191
Ok(Self::merge(ranges))
9292
}
9393

94-
/// Merge any overlapping ranges
94+
/// Merge any overlapping ranges. Adjacent ranges are *NOT* merged.
9595
///
9696
/// Is guaranteed to return only disjoint ranges in a sorted order.
9797
fn merge(mut ranges: Vec<Self>) -> Vec<Self> {
@@ -101,10 +101,7 @@ impl Range {
101101
for i in 0..ranges.len() {
102102
let j = i + 1;
103103

104-
// The +1 is a small optimization, because we can merge adjacent Ranges.
105-
// For example (1,3) and (4,6), because in the integers, there are no
106-
// possible values between 3 and 4, this is equivalent to (1,6).
107-
while j < ranges.len() && ranges[j].low <= ranges[i].high + 1 {
104+
while j < ranges.len() && ranges[j].low <= ranges[i].high {
108105
let j_high = ranges.remove(j).high;
109106
ranges[i].high = max(ranges[i].high, j_high);
110107
}
@@ -216,8 +213,8 @@ mod test {
216213
&[r(10, 40), r(50, 60)],
217214
);
218215

219-
// Merge adjacent ranges
220-
m(vec![r(1, 3), r(4, 6)], &[r(1, 6)]);
216+
// Don't merge adjacent ranges
217+
m(vec![r(1, 3), r(4, 6)], &[r(1, 3), r(4, 6)]);
221218
}
222219

223220
#[test]

tests/by-util/test_cut.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ fn test_output_delimiter_with_character_ranges() {
360360
.stdout_only("bc:defg\n");
361361
}
362362

363-
#[ignore = "Not yet implemented"]
364363
#[test]
365364
fn test_output_delimiter_with_adjacent_ranges() {
366365
new_ucmd!()

0 commit comments

Comments
 (0)