summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMattias Engdegård <mattiase@acm.org>2022-09-30 15:50:59 +0200
committerMattias Engdegård <mattiase@acm.org>2022-09-30 16:28:46 +0200
commitec5af48a180f732d04537ef0d5632a50d29e3ce0 (patch)
tree1ca69deb0aa387284b3a2bc96248a2f8c869fdf0 /test
parent123506f9ca33bbca57baeac74ebe7aaf462eddc5 (diff)
downloademacs-ec5af48a180f732d04537ef0d5632a50d29e3ce0.tar.gz
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.
Diffstat (limited to 'test')
-rw-r--r--test/src/fns-tests.el77
1 files changed, 42 insertions, 35 deletions
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))