(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))