aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorMattias Engdegård2022-09-30 15:50:59 +0200
committerMattias Engdegård2022-09-30 16:28:46 +0200
commitec5af48a180f732d04537ef0d5632a50d29e3ce0 (patch)
tree1ca69deb0aa387284b3a2bc96248a2f8c869fdf0 /test/src
parent123506f9ca33bbca57baeac74ebe7aaf462eddc5 (diff)
downloademacs-ec5af48a180f732d04537ef0d5632a50d29e3ce0.tar.gz
emacs-ec5af48a180f732d04537ef0d5632a50d29e3ce0.zip
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/src')
-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 @@
131 (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A)))))) 131 (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))
132 132
133(defconst fns-tests--string-lessp-cases 133(defconst fns-tests--string-lessp-cases
134 '((a 97 error) 134 `(("abc" < "abd")
135 (97 "a" error) 135 (abc < "abd")
136 ("abc" "abd" t) 136 (abc < abd)
137 ("abd" "abc" nil) 137 ("" = "")
138 (abc "abd" t) 138 ("" < " ")
139 ("abd" abc nil) 139 ("abc" < "abcd")
140 (abc abd t) 140 ("abc" = "abc")
141 (abd abc nil) 141 (abc = abc)
142 ("" "" nil) 142 ("" < "\0")
143 ("" " " t) 143 ("~" < "\x80")
144 (" " "" nil) 144 ("\x80" = "\x80")
145 ("abc" "abcd" t) 145 ("\xfe" < "\xff")
146 ("abcd" "abc" nil) 146 ("Munchen" < "München")
147 ("abc" "abc" nil) 147 ("München" = "München")
148 (abc abc nil) 148 ("Ré" < "Réunion")
149 ("\0" "" nil) 149 ("abc" = ,(string-to-multibyte "abc"))
150 ("" "\0" t) 150 (,(string-to-multibyte "abc") = ,(string-to-multibyte "abc"))
151 ("~" "\x80" t) 151 ("abc" < ,(string-to-multibyte "abd"))
152 ("\x80" "\x80" nil) 152 (,(string-to-multibyte "abc") < "abd")
153 ("\xfe" "\xff" t) 153 (,(string-to-multibyte "abc") < ,(string-to-multibyte "abd"))
154 ("Munchen" "München" t) 154 (,(string-to-multibyte "\x80") = ,(string-to-multibyte "\x80"))
155 ("München" "Munchen" nil) 155
156 ("München" "München" nil) 156 ;; Cases concerning the ordering of raw bytes: these are
157 ("Ré" "Réunion" t))) 157 ;; troublesome because the current `string<' order is not very useful as
158 158 ;; it equates unibyte 80..FF with multibyte U+0080..00FF, and is also
159 ;; inconsistent with `string=' (see bug#58168).
160 ;;("\x80" < ,(string-to-multibyte "\x80"))
161 ;;("\xff" < ,(string-to-multibyte "\x80"))
162 ;;("ü" < "\xfc")
163 ;;("ü" < ,(string-to-multibyte "\xfc"))
164 )
165 "List of (A REL B) where REL is the relation (`<' or `=') between A and B.")
159 166
160(ert-deftest fns-tests-string-lessp () 167(ert-deftest fns-tests-string-lessp ()
161 ;; Exercise both `string-lessp' and its alias `string<', both directly 168 ;; Exercise both `string-lessp' and its alias `string<', both directly
162 ;; and in a function (exercising its bytecode). 169 ;; and in a function (exercising its bytecode).
163 (dolist (lessp (list #'string-lessp #'string< 170 (dolist (fun (list #'string-lessp #'string<
164 (lambda (a b) (string-lessp a b)) 171 (lambda (a b) (string-lessp a b))
165 (lambda (a b) (string< a b)))) 172 (lambda (a b) (string< a b))))
166 (ert-info ((prin1-to-string lessp) :prefix "function: ") 173 (ert-info ((prin1-to-string fun) :prefix "function: ")
174 (should-error (funcall fun 'a 97))
175 (should-error (funcall fun 97 "a"))
167 (dolist (case fns-tests--string-lessp-cases) 176 (dolist (case fns-tests--string-lessp-cases)
168 (ert-info ((prin1-to-string case) :prefix "case: ") 177 (ert-info ((prin1-to-string case) :prefix "case: ")
169 (pcase case 178 (pcase-let ((`(,x ,rel ,y) case))
170 (`(,x ,y error) 179 (cl-assert (memq rel '(< =)))
171 (should-error (funcall lessp x y))) 180 (should (equal (funcall fun x y) (eq rel '<)))
172 (`(,x ,y ,expected) 181 (should (equal (funcall fun y x) nil))))))))
173 (should (equal (funcall lessp x y) expected)))))))))
174
175 182
176(ert-deftest fns-tests-compare-strings () 183(ert-deftest fns-tests-compare-strings ()
177 (should-error (compare-strings)) 184 (should-error (compare-strings))