1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-15 16:26:01 +02:00

tests: add tests for locale ordering

* tests/sort/sort-locale.sh: Check sort,ls have the same (non C) order.
* tests/local.mk: Reference the new test.
This commit is contained in:
Pádraig Brady
2025-11-07 20:49:25 +00:00
parent f7be1e51a3
commit d6fc91f37a
2 changed files with 52 additions and 0 deletions

View File

@@ -413,6 +413,7 @@ all_tests = \
tests/sort/sort-files0-from.pl \
tests/sort/sort-float.sh \
tests/sort/sort-h-thousands-sep.sh \
tests/sort/sort-locale.sh \
tests/sort/sort-merge.pl \
tests/sort/sort-merge-fdlimit.sh \
tests/sort/sort-month.sh \

51
tests/sort/sort-locale.sh Executable file
View File

@@ -0,0 +1,51 @@
#!/bin/sh
# Test sort locale ordering
# Copyright (C) 2025 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
print_ver_ sort ls
check_different_from_C() {
test "$(printf '%s\n' "$1" "$2" | LC_ALL=C sort)" != \
"$(printf '%s\n' "$1" "$2" | sort)"
}
check_hard_collate() {
# Correlate with ls
touch "$1" "$2" || framework_failure_
test "$(printf '%s\n' "$1" "$2" | sort)" = "$(ls -1 "$1" "$2")" || fail=1
if test "$fail" != 1; then
check_different_from_C "$1" "$2" ||
skip_ "Strings '$1' '$2' sort the same in C and $LC_ALL locales"
fi
}
export LC_ALL=en_US.iso8859-1 # only lowercase form works on macOS 10.15.7
if test "$(locale charmap 2>/dev/null | sed 's/iso/ISO-/')" = ISO-8859-1; then
check_hard_collate 'a_a' 'a b' # underscore and space considered equal
check_hard_collate 'aaa' 'BBB' # case insensitive ordering
check_hard_collate "$(printf 'aa\xe9')" 'aaf' # é comes before f
fi
export LC_ALL=$LOCALE_FR_UTF8
if test "$(locale charmap 2>/dev/null)" = UTF-8; then
check_hard_collate 'aaé' 'aaf' # é comes before f
check_hard_collate 'aéY' "$(printf 'ae\u0301Z')" # NFC/NFD é are equal
fi
Exit $fail