Port collation tests to glibc 2.27

* test/src/fns-tests.el (fns-tests-collate-strings)
(fns-tests-collate-sort): Don’t make unportable assumptions
about how en_US.UTF-8 collation works.  These assumptions
are not true on Fedora 28, which ships with glibc 2.27.
This commit is contained in:
Paul Eggert 2018-05-02 11:14:07 -07:00
parent 65ac27783a
commit f4b5ff20a6

View file

@ -119,10 +119,9 @@
;; In POSIX or C locales, collation order is lexicographic. ;; In POSIX or C locales, collation order is lexicographic.
(should (string-collate-lessp "XYZZY" "xyzzy" "POSIX")) (should (string-collate-lessp "XYZZY" "xyzzy" "POSIX"))
;; In a language specific locale, collation order is different. ;; In a language specific locale on MS-Windows, collation order is different.
(should (string-collate-lessp (when (eq system-type 'windows-nt)
"xyzzy" "XYZZY" (should (string-collate-lessp "xyzzy" "XYZZY" "enu_USA")))
(if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))
;; Ignore case. ;; Ignore case.
(should (string-collate-equalp "xyzzy" "XYZZY" nil t)) (should (string-collate-equalp "xyzzy" "XYZZY" nil t))
@ -154,8 +153,6 @@
(9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")]))) (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")])))
(ert-deftest fns-tests-collate-sort () (ert-deftest fns-tests-collate-sort ()
;; See https://lists.gnu.org/r/emacs-devel/2015-10/msg02505.html.
:expected-result (if (eq system-type 'cygwin) :failed :passed)
(skip-unless (fns-tests--collate-enabled-p)) (skip-unless (fns-tests--collate-enabled-p))
;; Punctuation and whitespace characters are relevant for POSIX. ;; Punctuation and whitespace characters are relevant for POSIX.
@ -165,15 +162,16 @@
(lambda (a b) (string-collate-lessp a b "POSIX"))) (lambda (a b) (string-collate-lessp a b "POSIX")))
'("1 1" "1 2" "1.1" "1.2" "11" "12"))) '("1 1" "1 2" "1.1" "1.2" "11" "12")))
;; Punctuation and whitespace characters are not taken into account ;; Punctuation and whitespace characters are not taken into account
;; for collation in other locales. ;; for collation in other locales, on MS-Windows systems.
(should (when (eq system-type 'windows-nt)
(equal (should
(sort '("11" "12" "1 1" "1 2" "1.1" "1.2") (equal
(lambda (a b) (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
(let ((w32-collate-ignore-punctuation t)) (lambda (a b)
(string-collate-lessp (let ((w32-collate-ignore-punctuation t))
a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8"))))) (string-collate-lessp
'("11" "1 1" "1.1" "12" "1 2" "1.2"))) a b "enu_USA"))))
'("11" "1 1" "1.1" "12" "1 2" "1.2"))))
;; Diacritics are different letters for POSIX, they sort lexicographical. ;; Diacritics are different letters for POSIX, they sort lexicographical.
(should (should
@ -181,15 +179,17 @@
(sort '("Ævar" "Agustín" "Adrian" "Eli") (sort '("Ævar" "Agustín" "Adrian" "Eli")
(lambda (a b) (string-collate-lessp a b "POSIX"))) (lambda (a b) (string-collate-lessp a b "POSIX")))
'("Adrian" "Agustín" "Eli" "Ævar"))) '("Adrian" "Agustín" "Eli" "Ævar")))
;; Diacritics are sorted between similar letters for other locales. ;; Diacritics are sorted between similar letters for other locales,
(should ;; on MS-Windows systems.
(equal (when (eq system-type 'windows-nt)
(sort '("Ævar" "Agustín" "Adrian" "Eli") (should
(lambda (a b) (equal
(let ((w32-collate-ignore-punctuation t)) (sort '("Ævar" "Agustín" "Adrian" "Eli")
(string-collate-lessp (lambda (a b)
a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8"))))) (let ((w32-collate-ignore-punctuation t))
'("Adrian" "Ævar" "Agustín" "Eli")))) (string-collate-lessp
a b "enu_USA"))))
'("Adrian" "Ævar" "Agustín" "Eli")))))
(ert-deftest fns-tests-string-version-lessp () (ert-deftest fns-tests-string-version-lessp ()
(should (string-version-lessp "foo2.png" "foo12.png")) (should (string-version-lessp "foo2.png" "foo12.png"))