diff options
| author | Yuan Fu | 2022-05-07 01:57:39 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-05-07 01:57:39 -0700 |
| commit | 82d5e902af68695481b8809e511a7913ef9a75aa (patch) | |
| tree | e6a366278590e8906a9282d04e48de2061b6fe3f /test/src | |
| parent | 84847cad82e3b667c82f411627cd58d236f55e84 (diff) | |
| parent | 293a97d61e1977440f96b7fc91f281a06250ea72 (diff) | |
| download | emacs-82d5e902af68695481b8809e511a7913ef9a75aa.tar.gz emacs-82d5e902af68695481b8809e511a7913ef9a75aa.zip | |
; Merge from master.
Diffstat (limited to 'test/src')
| -rw-r--r-- | test/src/fns-tests.el | 113 | ||||
| -rw-r--r-- | test/src/lread-tests.el | 22 | ||||
| -rw-r--r-- | test/src/print-tests.el | 8 | ||||
| -rw-r--r-- | test/src/regex-emacs-tests.el | 12 | ||||
| -rw-r--r-- | test/src/sqlite-tests.el | 25 | ||||
| -rw-r--r-- | test/src/timefns-tests.el | 13 |
6 files changed, 187 insertions, 6 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el index 723ef4c710f..c080c483927 100644 --- a/test/src/fns-tests.el +++ b/test/src/fns-tests.el | |||
| @@ -130,6 +130,49 @@ | |||
| 130 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) | 130 | (should (equal [nil nil nil nil nil t t t t t] (vconcat A))) |
| 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 | ||
| 134 | '((a 97 error) | ||
| 135 | (97 "a" error) | ||
| 136 | ("abc" "abd" t) | ||
| 137 | ("abd" "abc" nil) | ||
| 138 | (abc "abd" t) | ||
| 139 | ("abd" abc nil) | ||
| 140 | (abc abd t) | ||
| 141 | (abd abc nil) | ||
| 142 | ("" "" nil) | ||
| 143 | ("" " " t) | ||
| 144 | (" " "" nil) | ||
| 145 | ("abc" "abcd" t) | ||
| 146 | ("abcd" "abc" nil) | ||
| 147 | ("abc" "abc" nil) | ||
| 148 | (abc abc nil) | ||
| 149 | ("\0" "" nil) | ||
| 150 | ("" "\0" t) | ||
| 151 | ("~" "\x80" t) | ||
| 152 | ("\x80" "\x80" nil) | ||
| 153 | ("\xfe" "\xff" t) | ||
| 154 | ("Munchen" "München" t) | ||
| 155 | ("München" "Munchen" nil) | ||
| 156 | ("München" "München" nil) | ||
| 157 | ("Ré" "Réunion" t))) | ||
| 158 | |||
| 159 | |||
| 160 | (ert-deftest fns-tests-string-lessp () | ||
| 161 | ;; Exercise both `string-lessp' and its alias `string<', both directly | ||
| 162 | ;; and in a function (exercising its bytecode). | ||
| 163 | (dolist (lessp (list #'string-lessp #'string< | ||
| 164 | (lambda (a b) (string-lessp a b)) | ||
| 165 | (lambda (a b) (string< a b)))) | ||
| 166 | (ert-info ((prin1-to-string lessp) :prefix "function: ") | ||
| 167 | (dolist (case fns-tests--string-lessp-cases) | ||
| 168 | (ert-info ((prin1-to-string case) :prefix "case: ") | ||
| 169 | (pcase case | ||
| 170 | (`(,x ,y error) | ||
| 171 | (should-error (funcall lessp x y))) | ||
| 172 | (`(,x ,y ,expected) | ||
| 173 | (should (equal (funcall lessp x y) expected))))))))) | ||
| 174 | |||
| 175 | |||
| 133 | (ert-deftest fns-tests-compare-strings () | 176 | (ert-deftest fns-tests-compare-strings () |
| 134 | (should-error (compare-strings)) | 177 | (should-error (compare-strings)) |
| 135 | (should-error (compare-strings "xyzzy" "xyzzy")) | 178 | (should-error (compare-strings "xyzzy" "xyzzy")) |
| @@ -204,6 +247,76 @@ | |||
| 204 | [-1 2 3 4 5 5 7 8 9])) | 247 | [-1 2 3 4 5 5 7 8 9])) |
| 205 | (should (equal (sort (vector 9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y))) | 248 | (should (equal (sort (vector 9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y))) |
| 206 | [9 8 7 5 5 4 3 2 -1])) | 249 | [9 8 7 5 5 4 3 2 -1])) |
| 250 | ;; Sort a reversed list and vector. | ||
| 251 | (should (equal | ||
| 252 | (sort (reverse (number-sequence 1 1000)) (lambda (x y) (< x y))) | ||
| 253 | (number-sequence 1 1000))) | ||
| 254 | (should (equal | ||
| 255 | (sort (reverse (vconcat (number-sequence 1 1000))) | ||
| 256 | (lambda (x y) (< x y))) | ||
| 257 | (vconcat (number-sequence 1 1000)))) | ||
| 258 | ;; Sort a constant list and vector. | ||
| 259 | (should (equal | ||
| 260 | (sort (make-vector 100 1) (lambda (x y) (> x y))) | ||
| 261 | (make-vector 100 1))) | ||
| 262 | (should (equal | ||
| 263 | (sort (append (make-vector 100 1) nil) (lambda (x y) (> x y))) | ||
| 264 | (append (make-vector 100 1) nil))) | ||
| 265 | ;; Sort a long list and vector with every pair reversed. | ||
| 266 | (let ((vec (make-vector 100000 nil)) | ||
| 267 | (logxor-vec (make-vector 100000 nil))) | ||
| 268 | (dotimes (i 100000) | ||
| 269 | (aset logxor-vec i (logxor i 1)) | ||
| 270 | (aset vec i i)) | ||
| 271 | (should (equal | ||
| 272 | (sort logxor-vec (lambda (x y) (< x y))) | ||
| 273 | vec)) | ||
| 274 | (should (equal | ||
| 275 | (sort (append logxor-vec nil) (lambda (x y) (< x y))) | ||
| 276 | (append vec nil)))) | ||
| 277 | ;; Sort a list and vector with seven swaps. | ||
| 278 | (let ((vec (make-vector 100 nil)) | ||
| 279 | (swap-vec (make-vector 100 nil))) | ||
| 280 | (dotimes (i 100) | ||
| 281 | (aset vec i (- i 50)) | ||
| 282 | (aset swap-vec i (- i 50))) | ||
| 283 | (mapc (lambda (p) | ||
| 284 | (let ((tmp (elt swap-vec (car p)))) | ||
| 285 | (aset swap-vec (car p) (elt swap-vec (cdr p))) | ||
| 286 | (aset swap-vec (cdr p) tmp))) | ||
| 287 | '((48 . 94) (75 . 77) (33 . 41) (92 . 52) | ||
| 288 | (10 . 96) (1 . 14) (43 . 81))) | ||
| 289 | (should (equal | ||
| 290 | (sort (copy-sequence swap-vec) (lambda (x y) (< x y))) | ||
| 291 | vec)) | ||
| 292 | (should (equal | ||
| 293 | (sort (append swap-vec nil) (lambda (x y) (< x y))) | ||
| 294 | (append vec nil)))) | ||
| 295 | ;; Check for possible corruption after GC. | ||
| 296 | (let* ((size 3000) | ||
| 297 | (complex-vec (make-vector size nil)) | ||
| 298 | (vec (make-vector size nil)) | ||
| 299 | (counter 0) | ||
| 300 | (my-counter (lambda () | ||
| 301 | (if (< counter 500) | ||
| 302 | (cl-incf counter) | ||
| 303 | (setq counter 0) | ||
| 304 | (garbage-collect)))) | ||
| 305 | (rand 1) | ||
| 306 | (generate-random | ||
| 307 | (lambda () (setq rand | ||
| 308 | (logand (+ (* rand 1103515245) 12345) 2147483647))))) | ||
| 309 | ;; Make a complex vector and its sorted version. | ||
| 310 | (dotimes (i size) | ||
| 311 | (let ((r (funcall generate-random))) | ||
| 312 | (aset complex-vec i (cons r "a")) | ||
| 313 | (aset vec i (cons r "a")))) | ||
| 314 | ;; Sort it. | ||
| 315 | (should (equal | ||
| 316 | (sort complex-vec | ||
| 317 | (lambda (x y) (funcall my-counter) (< (car x) (car y)))) | ||
| 318 | (sort vec 'car-less-than-car)))) | ||
| 319 | ;; Check for sorting stability. | ||
| 207 | (should (equal | 320 | (should (equal |
| 208 | (sort | 321 | (sort |
| 209 | (vector | 322 | (vector |
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el index 862f6a6595f..9ec54c719c8 100644 --- a/test/src/lread-tests.el +++ b/test/src/lread-tests.el | |||
| @@ -258,5 +258,27 @@ literals (Bug#20852)." | |||
| 258 | (should (equal (read "-0.e-5") -0.0)) | 258 | (should (equal (read "-0.e-5") -0.0)) |
| 259 | ) | 259 | ) |
| 260 | 260 | ||
| 261 | (defun lread-test-read-and-print (str) | ||
| 262 | (let* ((read-circle t) | ||
| 263 | (print-circle t) | ||
| 264 | (val (read-from-string str))) | ||
| 265 | (if (consp val) | ||
| 266 | (prin1-to-string (car val)) | ||
| 267 | (error "reading %S failed: %S" str val)))) | ||
| 268 | |||
| 269 | (defconst lread-test-circle-cases | ||
| 270 | '("#1=(#1# . #1#)" | ||
| 271 | "#1=[#1# a #1#]" | ||
| 272 | "#1=(#2=[#1# #2#] . #1#)" | ||
| 273 | "#1=(#2=[#1# #2#] . #2#)" | ||
| 274 | "#1=[#2=(#1# . #2#)]" | ||
| 275 | "#1=(#2=[#3=(#1# . #2#) #4=(#3# . #4#)])" | ||
| 276 | )) | ||
| 277 | |||
| 278 | (ert-deftest lread-circle () | ||
| 279 | (dolist (str lread-test-circle-cases) | ||
| 280 | (ert-info (str :prefix "input: ") | ||
| 281 | (should (equal (lread-test-read-and-print str) str)))) | ||
| 282 | (should-error (read-from-string "#1=#1#") :type 'invalid-read-syntax)) | ||
| 261 | 283 | ||
| 262 | ;;; lread-tests.el ends here | 284 | ;;; lread-tests.el ends here |
diff --git a/test/src/print-tests.el b/test/src/print-tests.el index 1ef0caf1a46..0bae1959d1b 100644 --- a/test/src/print-tests.el +++ b/test/src/print-tests.el | |||
| @@ -417,5 +417,13 @@ otherwise, use a different charset." | |||
| 417 | t))) | 417 | t))) |
| 418 | (should (equal (prin1-to-string (make-marker)) "")))) | 418 | (should (equal (prin1-to-string (make-marker)) "")))) |
| 419 | 419 | ||
| 420 | (ert-deftest test-dots () | ||
| 421 | (should (equal (prin1-to-string 'foo.bar) "foo.bar")) | ||
| 422 | (should (equal (prin1-to-string '.foo) "\\.foo")) | ||
| 423 | (should (equal (prin1-to-string '.foo.) "\\.foo.")) | ||
| 424 | (should (equal (prin1-to-string 'bar?bar) "bar?bar")) | ||
| 425 | (should (equal (prin1-to-string '\?bar) "\\?bar")) | ||
| 426 | (should (equal (prin1-to-string '\?bar?) "\\?bar?"))) | ||
| 427 | |||
| 420 | (provide 'print-tests) | 428 | (provide 'print-tests) |
| 421 | ;;; print-tests.el ends here | 429 | ;;; print-tests.el ends here |
diff --git a/test/src/regex-emacs-tests.el b/test/src/regex-emacs-tests.el index e6288d1fc9b..ff0d6be3f5d 100644 --- a/test/src/regex-emacs-tests.el +++ b/test/src/regex-emacs-tests.el | |||
| @@ -157,8 +157,8 @@ are known failures, and are skipped." | |||
| 157 | 157 | ||
| 158 | (defun regex-tests-compare (string what-failed bounds-ref &optional substring-ref) | 158 | (defun regex-tests-compare (string what-failed bounds-ref &optional substring-ref) |
| 159 | "I just ran a search, looking at STRING. WHAT-FAILED describes | 159 | "I just ran a search, looking at STRING. WHAT-FAILED describes |
| 160 | what failed, if anything; valid values are 'search-failed, | 160 | what failed, if anything; valid values are `search-failed', |
| 161 | 'compilation-failed and nil. I compare the beginning/end of each | 161 | `compilation-failed' and nil. I compare the beginning/end of each |
| 162 | group with their expected values. This is done with either | 162 | group with their expected values. This is done with either |
| 163 | BOUNDS-REF or SUBSTRING-REF; one of those should be non-nil. | 163 | BOUNDS-REF or SUBSTRING-REF; one of those should be non-nil. |
| 164 | BOUNDS-REF is a sequence [start-ref0 end-ref0 start-ref1 | 164 | BOUNDS-REF is a sequence [start-ref0 end-ref0 start-ref1 |
| @@ -166,9 +166,9 @@ end-ref1 ....] while SUBSTRING-REF is the expected substring | |||
| 166 | obtained by indexing the input string by start/end-ref. | 166 | obtained by indexing the input string by start/end-ref. |
| 167 | 167 | ||
| 168 | If the search was supposed to fail then start-ref0/substring-ref0 | 168 | If the search was supposed to fail then start-ref0/substring-ref0 |
| 169 | is 'search-failed. If the search wasn't even supposed to compile | 169 | is `search-failed'. If the search wasn't even supposed to compile |
| 170 | successfully, then start-ref0/substring-ref0 is | 170 | successfully, then start-ref0/substring-ref0 is |
| 171 | 'compilation-failed. If I only care about a match succeeding, | 171 | `compilation-failed'. If I only care about a match succeeding, |
| 172 | this can be set to t. | 172 | this can be set to t. |
| 173 | 173 | ||
| 174 | This function returns a string that describes the failure, or nil | 174 | This function returns a string that describes the failure, or nil |
| @@ -259,8 +259,8 @@ BOUNDS-REF is a sequence [start-ref0 end-ref0 start-ref1 end-ref1 | |||
| 259 | ....]. | 259 | ....]. |
| 260 | 260 | ||
| 261 | If the search was supposed to fail then start-ref0 is | 261 | If the search was supposed to fail then start-ref0 is |
| 262 | 'search-failed. If the search wasn't even supposed to compile | 262 | `search-failed'. If the search wasn't even supposed to compile |
| 263 | successfully, then start-ref0 is 'compilation-failed. | 263 | successfully, then start-ref0 is `compilation-failed'. |
| 264 | 264 | ||
| 265 | This function returns a string that describes the failure, or nil | 265 | This function returns a string that describes the failure, or nil |
| 266 | on success" | 266 | on success" |
diff --git a/test/src/sqlite-tests.el b/test/src/sqlite-tests.el index 6e44300f3ad..5af43923012 100644 --- a/test/src/sqlite-tests.el +++ b/test/src/sqlite-tests.el | |||
| @@ -216,4 +216,29 @@ | |||
| 216 | db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so") | 216 | db "/usr/lib/x86_64-linux-gnu/libsqlite3_mod_csvtable.so") |
| 217 | '(nil t))))) | 217 | '(nil t))))) |
| 218 | 218 | ||
| 219 | (ert-deftest sqlite-blob () | ||
| 220 | (skip-unless (sqlite-available-p)) | ||
| 221 | (let (db) | ||
| 222 | (progn | ||
| 223 | (setq db (sqlite-open)) | ||
| 224 | (sqlite-execute | ||
| 225 | db "create table if not exists test10 (col1 text, col2 blob, col3 numbre)") | ||
| 226 | (let ((string (with-temp-buffer | ||
| 227 | (set-buffer-multibyte nil) | ||
| 228 | (insert 0 1 2) | ||
| 229 | (buffer-string)))) | ||
| 230 | (should-not (multibyte-string-p string)) | ||
| 231 | (sqlite-execute | ||
| 232 | db "insert into test10 values (?, ?, 1)" | ||
| 233 | (list string | ||
| 234 | (propertize string | ||
| 235 | 'coding-system 'binary))) | ||
| 236 | (cl-destructuring-bind | ||
| 237 | (c1 c2 _) | ||
| 238 | (car (sqlite-select db "select * from test10 where col3 = 1")) | ||
| 239 | (should (equal c1 string)) | ||
| 240 | (should (equal c2 string)) | ||
| 241 | (should (multibyte-string-p c1)) | ||
| 242 | (should-not (multibyte-string-p c2))))))) | ||
| 243 | |||
| 219 | ;;; sqlite-tests.el ends here | 244 | ;;; sqlite-tests.el ends here |
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el index 1b49e0622f5..08d06f27d9e 100644 --- a/test/src/timefns-tests.el +++ b/test/src/timefns-tests.el | |||
| @@ -169,6 +169,10 @@ a fixed place on the right and are padded on the left." | |||
| 169 | (ert-deftest time-equal-p-nil-nil () | 169 | (ert-deftest time-equal-p-nil-nil () |
| 170 | (should (time-equal-p nil nil))) | 170 | (should (time-equal-p nil nil))) |
| 171 | 171 | ||
| 172 | (ert-deftest time-equal-p-NaN-NaN () | ||
| 173 | (let ((x 0.0e+NaN)) | ||
| 174 | (should (not (time-equal-p x x))))) | ||
| 175 | |||
| 172 | (ert-deftest time-arith-tests () | 176 | (ert-deftest time-arith-tests () |
| 173 | (let ((time-values (list 0 -1 1 0.0 -0.0 -1.0 1.0 | 177 | (let ((time-values (list 0 -1 1 0.0 -0.0 -1.0 1.0 |
| 174 | most-negative-fixnum most-positive-fixnum | 178 | most-negative-fixnum most-positive-fixnum |
| @@ -221,6 +225,15 @@ a fixed place on the right and are padded on the left." | |||
| 221 | (encode-time '(29 31 17 30 4 2019 2 t 7200)) | 225 | (encode-time '(29 31 17 30 4 2019 2 t 7200)) |
| 222 | '(23752 27217)))) | 226 | '(23752 27217)))) |
| 223 | 227 | ||
| 228 | (ert-deftest encode-time-alternate-apis () | ||
| 229 | (let* ((time '(30 30 12 15 6 1970)) | ||
| 230 | (time-1 (append time '(nil -1 nil))) | ||
| 231 | (etime (encode-time time))) | ||
| 232 | (should (time-equal-p etime (encode-time time-1))) | ||
| 233 | (should (time-equal-p etime (apply #'encode-time time))) | ||
| 234 | (should (time-equal-p etime (apply #'encode-time time-1))) | ||
| 235 | (should (time-equal-p etime (apply #'encode-time (append time '(nil))))))) | ||
| 236 | |||
| 224 | (ert-deftest float-time-precision () | 237 | (ert-deftest float-time-precision () |
| 225 | (should (= (float-time '(0 1 0 4025)) 1.000000004025)) | 238 | (should (= (float-time '(0 1 0 4025)) 1.000000004025)) |
| 226 | (should (= (float-time '(1000000004025 . 1000000000000)) 1.000000004025)) | 239 | (should (= (float-time '(1000000004025 . 1000000000000)) 1.000000004025)) |