From 0249c557705abb7033a70e5b578d5efabda5001e Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 28 Jun 2026 09:16:51 +0200 Subject: [PATCH] sort: test punctuation-only differences are kept by -u under locale --- tests/by-util/test_sort.rs | 54 +++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/tests/by-util/test_sort.rs b/tests/by-util/test_sort.rs index 801e43d89a1..0e9e5ffa743 100644 --- a/tests/by-util/test_sort.rs +++ b/tests/by-util/test_sort.rs @@ -3025,22 +3025,46 @@ fn test_consistent_sorting_with_i18n_collate() { } #[test] -fn test_sort_locale_punctuation_weights() { - // Test for issue #12542 - let input = "file10\nfile-10\n"; - let expected_output = "file-10\nfile10\n"; - - new_ucmd!() - .env("LC_ALL", "en_US.UTF-8") - .pipe_in(input) - .succeeds() - .stdout_is(expected_output); +fn test_sort_locale_punctuation() { + // Punctuation gets a distinguishing collation weight, so lines differing + // only by punctuation sort in a stable order (issue #12542) and are never + // merged by -u. This holds across the plain, explicit-key and stable paths, + // and in both locales. The wildcard-domain case comes from dehydrated, which + // relied on -u keeping a `*.domain.com` alias distinct from the bare domain. + // (input, expected, [(locale, args)...]) + let cases = [ + ( + "file10\nfile-10\n", + "file-10\nfile10\n", + &[("en_US.UTF-8", &[][..]), ("C", &[][..])][..], + ), + ( + "EU\nE.U\nE-U\n", + "E-U\nE.U\nEU\n", + &[ + ("en_US.UTF-8", &["-u"][..]), + ("C", &["-u"][..]), + ("en_US.UTF-8", &["-u", "-k1,1"][..]), + ("en_US.UTF-8", &["-s", "-k1,1"][..]), + ][..], + ), + ( + "domain.com\n*.domain.com\ndomain.com\n", + "*.domain.com\ndomain.com\n", + &[("en_US.UTF-8", &["-u"][..]), ("C", &["-u"][..])][..], + ), + ]; - new_ucmd!() - .env("LC_ALL", "C") - .pipe_in(input) - .succeeds() - .stdout_is(expected_output); + for (input, expected, runs) in cases { + for (locale, args) in runs { + new_ucmd!() + .env("LC_ALL", *locale) + .args(args) + .pipe_in(input) + .succeeds() + .stdout_is(expected); + } + } } /* spell-checker: enable */