emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master ec5af48a18 2/3: Strengthen string-lessp tests


From: Mattias Engdegård
Subject: master ec5af48a18 2/3: Strengthen string-lessp tests
Date: Fri, 30 Sep 2022 10:29:42 -0400 (EDT)

branch: master
commit ec5af48a180f732d04537ef0d5632a50d29e3ce0
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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.
---
 test/src/fns-tests.el | 77 ++++++++++++++++++++++++++++-----------------------
 1 file changed, 42 insertions(+), 35 deletions(-)

diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 3f3d9a0285..9a2bd5cef3 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))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]