tr: fix test to assert rejection of -ct with complemented class

This commit is contained in:
can1357
2026-04-20 23:28:28 +02:00
committed by Sylvestre Ledru
parent 85af4e8159
commit 98f6b0187b
2 changed files with 9 additions and 4 deletions
+6 -2
View File
@@ -319,8 +319,7 @@ impl Sequence {
// GNU applies -t before complementing a character class.
// That means we must first truncate the expanded, non-complemented
// source set, then complement the truncated prefix to recover the
// final translation domain. Complementing first would incorrectly
// shrink the complemented domain to the prefix length.
// final translation domain.
let truncated_set1: Vec<_> = set1
.iter()
.flat_map(Self::flatten)
@@ -329,6 +328,11 @@ impl Sequence {
set1_solved = (0..=u8::MAX)
.filter(|x| !truncated_set1.contains(x))
.collect();
// After expansion the complemented domain may be larger than set2.
// Re-check the complement validity constraint.
if set2_uniques.len() > 1 || set1_solved.len() > set2_solved.len() {
return Err(BadSequence::ComplementMoreThanOneUniqueInSet2);
}
} else {
set1_solved.truncate(set2_solved.len());
}
+3 -2
View File
@@ -386,9 +386,10 @@ fn test_truncate_applies_before_complement_with_class() {
new_ucmd!()
.args(&["-ct", "[:digit:]", "X"])
.pipe_in("A")
.succeeds()
.stdout_is("X");
.fails()
.stderr_contains("when translating with complemented character classes,\nstring2 must map all characters in the domain to one");
}
#[test]
fn missing_args_fails() {
let (_, mut ucmd) = at_and_ucmd!();