Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refuse to translate if set2 contains more than one unique characters and set1 contains a character class #6472

Merged

Conversation

cvonelm
Copy link
Contributor

@cvonelm cvonelm commented Jun 15, 2024

If complementing and translating with a character class, there can only be one unique character in set2.

The underlying issue, [y*] not being expanded to "" was fixed "accidentally" in a previous restructuring of tr. I have simply added the error check here.

@cvonelm cvonelm force-pushed the issue-6344-complement-error-if-2-uniques branch 2 times, most recently from f570cdb to 202f5b6 Compare June 15, 2024 12:31
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tr/tr is no longer failing!

@cvonelm cvonelm force-pushed the issue-6344-complement-error-if-2-uniques branch from 202f5b6 to 4c450c8 Compare June 16, 2024 19:32
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tr/tr is no longer failing!

@sylvestre
Copy link
Contributor

GNU testsuite comparison:

Congrats! The gnu test tests/tr/tr is no longer failing!

wahou, bravo :)

@@ -1386,3 +1386,22 @@ fn check_set1_longer_set2_ends_in_class_with_trunc() {
.args(&["-t", "[:lower:]a", "[:upper:]"])
.succeeds();
}

fn check_complement_2_unique_in_set2() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn check_complement_2_unique_in_set2() {
#[test]
fn check_complement_2_unique_in_set2() {

@@ -262,6 +265,17 @@ impl Sequence {
.flat_map(Self::flatten_all)
.filter_map(to_u8)
.collect();
let mut set2_uniques = set2_solved.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut set2_uniques = set2_solved.clone();
// Ensure set2_solved contains unique elements only
let mut set2_uniques = set2_solved.clone();

set2_uniques.sort();
set2_uniques.dedup();

if set1.iter().any(|x| matches!(x, Self::Class(_)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if set1.iter().any(|x| matches!(x, Self::Class(_)))
// Validate the complement condition
if set1.iter().any(|x| matches!(x, Self::Class(_)))

@cvonelm cvonelm force-pushed the issue-6344-complement-error-if-2-uniques branch from 4c450c8 to bd772bc Compare June 21, 2024 12:49
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/tr/tr is no longer failing!

@sylvestre sylvestre merged commit 0ae6d43 into uutils:main Jun 22, 2024
64 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants