Skip to content

Commit 98f6b01

Browse files
can1357sylvestre
authored andcommitted
tr: fix test to assert rejection of -ct with complemented class
1 parent 85af4e8 commit 98f6b01

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

src/uu/tr/src/operation.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ impl Sequence {
319319
// GNU applies -t before complementing a character class.
320320
// That means we must first truncate the expanded, non-complemented
321321
// source set, then complement the truncated prefix to recover the
322-
// final translation domain. Complementing first would incorrectly
323-
// shrink the complemented domain to the prefix length.
322+
// final translation domain.
324323
let truncated_set1: Vec<_> = set1
325324
.iter()
326325
.flat_map(Self::flatten)
@@ -329,6 +328,11 @@ impl Sequence {
329328
set1_solved = (0..=u8::MAX)
330329
.filter(|x| !truncated_set1.contains(x))
331330
.collect();
331+
// After expansion the complemented domain may be larger than set2.
332+
// Re-check the complement validity constraint.
333+
if set2_uniques.len() > 1 || set1_solved.len() > set2_solved.len() {
334+
return Err(BadSequence::ComplementMoreThanOneUniqueInSet2);
335+
}
332336
} else {
333337
set1_solved.truncate(set2_solved.len());
334338
}

tests/by-util/test_tr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,10 @@ fn test_truncate_applies_before_complement_with_class() {
386386
new_ucmd!()
387387
.args(&["-ct", "[:digit:]", "X"])
388388
.pipe_in("A")
389-
.succeeds()
390-
.stdout_is("X");
389+
.fails()
390+
.stderr_contains("when translating with complemented character classes,\nstring2 must map all characters in the domain to one");
391391
}
392+
392393
#[test]
393394
fn missing_args_fails() {
394395
let (_, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)