From: Mattias Engdegård Date: Fri, 30 Sep 2022 13:50:59 +0000 (+0200) Subject: Strengthen string-lessp tests X-Git-Tag: emacs-29.0.90~1856^2~121 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ec5af48a180f732d04537ef0d5632a50d29e3ce0;p=emacs.git Strengthen string-lessp tests * test/src/fns-tests.el (fns-tests--string-lessp-cases) (fns-tests-string-lessp): Check more cases, and in a more robust way. --- diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 3f3d9a02855..9a2bd5cef34 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el @@ -131,47 +131,54 @@ (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A)))))) (defconst fns-tests--string-lessp-cases - '((a 97 error) - (97 "a" error) - ("abc" "abd" t) - ("abd" "abc" nil) - (abc "abd" t) - ("abd" abc nil) - (abc abd t) - (abd abc nil) - ("" "" nil) - ("" " " t) - (" " "" nil) - ("abc" "abcd" t) - ("abcd" "abc" nil) - ("abc" "abc" nil) - (abc abc nil) - ("\0" "" nil) - ("" "\0" t) - ("~" "\x80" t) - ("\x80" "\x80" nil) - ("\xfe" "\xff" t) - ("Munchen" "München" t) - ("München" "Munchen" nil) - ("München" "München" nil) - ("Ré" "Réunion" t))) - + `(("abc" < "abd") + (abc < "abd") + (abc < abd) + ("" = "") + ("" < " ") + ("abc" < "abcd") + ("abc" = "abc") + (abc = abc) + ("" < "\0") + ("~" < "\x80") + ("\x80" = "\x80") + ("\xfe" < "\xff") + ("Munchen" < "München") + ("München" = "München") + ("Ré" < "Réunion") + ("abc" = ,(string-to-multibyte "abc")) + (,(string-to-multibyte "abc") = ,(string-to-multibyte "abc")) + ("abc" < ,(string-to-multibyte "abd")) + (,(string-to-multibyte "abc") < "abd") + (,(string-to-multibyte "abc") < ,(string-to-multibyte "abd")) + (,(string-to-multibyte "\x80") = ,(string-to-multibyte "\x80")) + + ;; Cases concerning the ordering of raw bytes: these are + ;; troublesome because the current `string<' order is not very useful as + ;; it equates unibyte 80..FF with multibyte U+0080..00FF, and is also + ;; inconsistent with `string=' (see bug#58168). + ;;("\x80" < ,(string-to-multibyte "\x80")) + ;;("\xff" < ,(string-to-multibyte "\x80")) + ;;("ü" < "\xfc") + ;;("ü" < ,(string-to-multibyte "\xfc")) + ) + "List of (A REL B) where REL is the relation (`<' or `=') between A and B.") (ert-deftest fns-tests-string-lessp () ;; Exercise both `string-lessp' and its alias `string<', both directly ;; and in a function (exercising its bytecode). - (dolist (lessp (list #'string-lessp #'string< - (lambda (a b) (string-lessp a b)) - (lambda (a b) (string< a b)))) - (ert-info ((prin1-to-string lessp) :prefix "function: ") + (dolist (fun (list #'string-lessp #'string< + (lambda (a b) (string-lessp a b)) + (lambda (a b) (string< a b)))) + (ert-info ((prin1-to-string fun) :prefix "function: ") + (should-error (funcall fun 'a 97)) + (should-error (funcall fun 97 "a")) (dolist (case fns-tests--string-lessp-cases) (ert-info ((prin1-to-string case) :prefix "case: ") - (pcase case - (`(,x ,y error) - (should-error (funcall lessp x y))) - (`(,x ,y ,expected) - (should (equal (funcall lessp x y) expected))))))))) - + (pcase-let ((`(,x ,rel ,y) case)) + (cl-assert (memq rel '(< =))) + (should (equal (funcall fun x y) (eq rel '<))) + (should (equal (funcall fun y x) nil)))))))) (ert-deftest fns-tests-compare-strings () (should-error (compare-strings))