tr: fix graph/print character class mapping (#11405)

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
This commit is contained in:
Can Bölük
2026-03-26 16:21:28 +01:00
committed by GitHub
parent 230e0cfd65
commit 358063f336
2 changed files with 35 additions and 3 deletions
+3 -3
View File
@@ -185,8 +185,7 @@ impl Sequence {
.chain(33..=47)
.chain(58..=64)
.chain(91..=96)
.chain(123..=126)
.chain(std::iter::once(32)), // space
.chain(123..=126),
),
Class::Print => Box::new(
(48..=57) // digit
@@ -196,7 +195,8 @@ impl Sequence {
.chain(33..=47)
.chain(58..=64)
.chain(91..=96)
.chain(123..=126),
.chain(123..=126)
.chain(std::iter::once(32)), // space
),
Class::Punct => Box::new((33..=47).chain(58..=64).chain(91..=96).chain(123..=126)),
Class::Space => Box::new(unicode_table::SPACES.iter().copied()),
+32
View File
@@ -65,6 +65,38 @@ fn test_delete() {
.stdout_is("BD");
}
#[test]
fn test_delete_graph_and_print_match_gnu() {
let input = [b' ', b'A', b'!', b'\t', b'\n'];
new_ucmd!()
.args(&["-d", "[:graph:]"])
.pipe_in(input)
.succeeds()
.stdout_is_bytes([b' ', b'\t', b'\n']);
new_ucmd!()
.args(&["-d", "[:print:]"])
.pipe_in(input)
.succeeds()
.stdout_is_bytes([b'\t', b'\n']);
}
#[test]
fn test_delete_complement_graph_and_print_match_gnu() {
let input = [b' ', b'A', b'!', b'\t', b'\n'];
new_ucmd!()
.args(&["-d", "-c", "[:graph:]"])
.pipe_in(input)
.succeeds()
.stdout_is_bytes([b'A', b'!']);
new_ucmd!()
.args(&["-d", "-c", "[:print:]"])
.pipe_in(input)
.succeeds()
.stdout_is_bytes([b' ', b'A', b'!']);
}
#[test]
fn test_delete_afterwards_is_not_flag() {
new_ucmd!()