Merge pull request #5999 from BenWiederhake/dev-tr-squeeze-last-set

tr: Properly handle deleting and squeezing
This commit is contained in:
Sylvestre Ledru 2024-02-23 08:33:13 +01:00 committed by GitHub
commit 9af65c0397
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -64,6 +64,16 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
));
}
if delete_flag & squeeze_flag && sets_len < 2 {
return Err(UUsageError::new(
1,
format!(
"missing operand after {}\nTwo strings must be given when deleting and squeezing.",
sets[0].quote()
),
));
}
if sets_len > 1 {
let start = "extra operand";
if delete_flag && !squeeze_flag {
@ -117,7 +127,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}
{
let mut squeeze_reader = BufReader::new(delete_buffer.as_bytes());
let op = SqueezeOperation::new(set2, complement_flag);
let op = SqueezeOperation::new(set2, false);
translate_input(&mut squeeze_reader, &mut buffered_stdout, op);
}
} else {

View file

@ -2,7 +2,7 @@
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore aabbaa aabbcc aabc abbb abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn
// spell-checker:ignore aabbaa aabbcc aabc abbb abbbcddd abcc abcdefabcdef abcdefghijk abcdefghijklmn abcdefghijklmnop ABCDEFGHIJKLMNOPQRS abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFZZ abcxyz ABCXYZ abcxyzabcxyz ABCXYZABCXYZ acbdef alnum amzamz AMZXAMZ bbbd cclass cefgm cntrl compl dabcdef dncase Gzabcdefg PQRST upcase wxyzz xdigit XXXYYY xycde xyyye xyyz xyzzzzxyzzzz ZABCDEF Zamz Cdefghijkl Cdefghijklmn
use crate::common::util::TestScenario;
#[test]
@ -163,6 +163,15 @@ fn test_translate_and_squeeze_multiple_lines() {
.stdout_is("yaay\nyaay"); // spell-checker:disable-line
}
#[test]
fn test_delete_and_squeeze_one_set() {
new_ucmd!()
.args(&["-ds", "a-z"])
.fails()
.stderr_contains("missing operand after 'a-z'")
.stderr_contains("Two strings must be given when deleting and squeezing.");
}
#[test]
fn test_delete_and_squeeze() {
new_ucmd!()
@ -181,6 +190,15 @@ fn test_delete_and_squeeze_complement() {
.stdout_is("abc");
}
#[test]
fn test_delete_and_squeeze_complement_squeeze_set2() {
new_ucmd!()
.args(&["-dsc", "abX", "XYZ"])
.pipe_in("abbbcdddXXXYYY")
.succeeds()
.stdout_is("abbbX");
}
#[test]
fn test_set1_longer_than_set2() {
new_ucmd!()