aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-rw-r--r--test/src/data-tests.el109
-rw-r--r--test/src/editfns-tests.el31
-rw-r--r--test/src/emacs-module-tests.el8
-rw-r--r--test/src/floatfns-tests.el12
-rw-r--r--test/src/fns-tests.el20
-rw-r--r--test/src/lread-tests.el4
-rw-r--r--test/src/print-tests.el6
7 files changed, 173 insertions, 17 deletions
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 3cd537859fd..ee6a3eb9222 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -105,7 +105,9 @@
105 (should (isnan (min 0.0e+NaN))) 105 (should (isnan (min 0.0e+NaN)))
106 (should (isnan (min 0.0e+NaN 1 2))) 106 (should (isnan (min 0.0e+NaN 1 2)))
107 (should (isnan (min 1.0 0.0e+NaN))) 107 (should (isnan (min 1.0 0.0e+NaN)))
108 (should (isnan (min 1.0 0.0e+NaN 1.1)))) 108 (should (isnan (min 1.0 0.0e+NaN 1.1)))
109 (should (isnan (min 1.0 0.0e+NaN 1.1 (1+ most-positive-fixnum))))
110 (should (isnan (max 1.0 0.0e+NaN 1.1 (1+ most-positive-fixnum)))))
109 111
110(defun data-tests-popcnt (byte) 112(defun data-tests-popcnt (byte)
111 "Calculate the Hamming weight of BYTE." 113 "Calculate the Hamming weight of BYTE."
@@ -515,4 +517,109 @@ comparing the subr with a much slower lisp implementation."
515 (bound-and-true-p data-tests-foo2) 517 (bound-and-true-p data-tests-foo2)
516 (bound-and-true-p data-tests-foo3))))))) 518 (bound-and-true-p data-tests-foo3)))))))
517 519
520(ert-deftest data-tests-bignum ()
521 (should (bignump (+ most-positive-fixnum 1)))
522 (let ((f0 (+ (float most-positive-fixnum) 1))
523 (f-1 (- (float most-negative-fixnum) 1))
524 (b0 (+ most-positive-fixnum 1))
525 (b-1 (- most-negative-fixnum 1)))
526 (should (> b0 -1))
527 (should (> b0 f-1))
528 (should (> b0 b-1))
529 (should (>= b0 -1))
530 (should (>= b0 f-1))
531 (should (>= b0 b-1))
532 (should (>= b-1 b-1))
533
534 (should (< -1 b0))
535 (should (< f-1 b0))
536 (should (< b-1 b0))
537 (should (<= -1 b0))
538 (should (<= f-1 b0))
539 (should (<= b-1 b0))
540 (should (<= b-1 b-1))
541
542 (should (= b0 f0))
543 (should (= b0 b0))
544
545 (should (/= b0 f-1))
546 (should (/= b0 b-1))))
547
548(ert-deftest data-tests-+ ()
549 (should-not (fixnump (+ most-positive-fixnum most-positive-fixnum)))
550 (should (> (+ most-positive-fixnum most-positive-fixnum) most-positive-fixnum))
551 (should (eq (- (+ most-positive-fixnum most-positive-fixnum)
552 (+ most-positive-fixnum most-positive-fixnum))
553 0)))
554
555(ert-deftest data-tests-/ ()
556 (let* ((x (* most-positive-fixnum 8))
557 (y (* most-negative-fixnum 8))
558 (z (- y)))
559 (should (= most-positive-fixnum (/ x 8)))
560 (should (= most-negative-fixnum (/ y 8)))
561 (should (= -1 (/ y z)))
562 (should (= -1 (/ z y)))
563 (should (= 0 (/ x (* 2 x))))
564 (should (= 0 (/ y (* 2 y))))
565 (should (= 0 (/ z (* 2 z))))))
566
567(ert-deftest data-tests-number-predicates ()
568 (should (fixnump 0))
569 (should (fixnump most-negative-fixnum))
570 (should (fixnump most-positive-fixnum))
571 (should (integerp (+ most-positive-fixnum 1)))
572 (should (integer-or-marker-p (+ most-positive-fixnum 1)))
573 (should (numberp (+ most-positive-fixnum 1)))
574 (should (number-or-marker-p (+ most-positive-fixnum 1)))
575 (should (natnump (+ most-positive-fixnum 1)))
576 (should-not (fixnump (+ most-positive-fixnum 1)))
577 (should (bignump (+ most-positive-fixnum 1))))
578
579(ert-deftest data-tests-number-to-string ()
580 (let* ((s "99999999999999999999999999999")
581 (v (read s)))
582 (should (equal (number-to-string v) s))))
583
584(ert-deftest data-tests-1+ ()
585 (should (> (1+ most-positive-fixnum) most-positive-fixnum))
586 (should (fixnump (1+ (1- most-negative-fixnum)))))
587
588(ert-deftest data-tests-1- ()
589 (should (< (1- most-negative-fixnum) most-negative-fixnum))
590 (should (fixnump (1- (1+ most-positive-fixnum)))))
591
592(ert-deftest data-tests-logcount ()
593 (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128)))
594
595(ert-deftest data-tests-minmax ()
596 (let ((a (- most-negative-fixnum 1))
597 (b (+ most-positive-fixnum 1))
598 (c 0))
599 (should (= (min a b c) a))
600 (should (= (max a b c) b))))
601
602(defun data-tests-check-sign (x y)
603 (should (eq (cl-signum x) (cl-signum y))))
604
605(ert-deftest data-tests-%-mod ()
606 (let* ((b1 (+ most-positive-fixnum 1))
607 (nb1 (- b1))
608 (b3 (+ most-positive-fixnum 3))
609 (nb3 (- b3)))
610 (data-tests-check-sign (% 1 3) (% b1 b3))
611 (data-tests-check-sign (mod 1 3) (mod b1 b3))
612 (data-tests-check-sign (% 1 -3) (% b1 nb3))
613 (data-tests-check-sign (mod 1 -3) (mod b1 nb3))
614 (data-tests-check-sign (% -1 3) (% nb1 b3))
615 (data-tests-check-sign (mod -1 3) (mod nb1 b3))
616 (data-tests-check-sign (% -1 -3) (% nb1 nb3))
617 (data-tests-check-sign (mod -1 -3) (mod nb1 nb3))))
618
619(ert-deftest data-tests-ash-lsh ()
620 (should (= (ash most-negative-fixnum 1)
621 (* most-negative-fixnum 2)))
622 (should (= (lsh most-negative-fixnum 1)
623 (* most-negative-fixnum 2))))
624
518;;; data-tests.el ends here 625;;; data-tests.el ends here
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index aa896b06499..964ff088360 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -173,20 +173,23 @@
173 (should-error (format "%x" 18446744073709551616.0) 173 (should-error (format "%x" 18446744073709551616.0)
174 :type 'overflow-error)) 174 :type 'overflow-error))
175(ert-deftest read-large-integer () 175(ert-deftest read-large-integer ()
176 (should-error (read (format "%d0" most-negative-fixnum)) 176 (should (eq (type-of (read (format "%d0" most-negative-fixnum))) 'integer))
177 :type 'overflow-error) 177 (should (eq (type-of (read (format "%+d" (* -8.0 most-negative-fixnum))))
178 (should-error (read (format "%+d" (* -8.0 most-negative-fixnum))) 178 'integer))
179 :type 'overflow-error) 179 (should (eq (type-of (read (substring (format "%d" most-negative-fixnum) 1)))
180 (should-error (read (substring (format "%d" most-negative-fixnum) 1)) 180 'integer))
181 :type 'overflow-error) 181 (should (eq (type-of (read (format "#x%x" most-negative-fixnum)))
182 'integer))
183 (should (eq (type-of (read (format "#o%o" most-negative-fixnum)))
184 'integer))
185 (should (eq (type-of (read (format "#32rG%x" most-positive-fixnum)))
186 'integer))
182 (let ((binary-as-unsigned nil)) 187 (let ((binary-as-unsigned nil))
183 (dolist (fmt '("%d" "%s" "#o%o" "#x%x")) 188 (dolist (fmt '("%d" "%s" "#o%o" "#x%x"))
184 (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum) 189 (dolist (val (list most-negative-fixnum (1+ most-negative-fixnum)
185 -1 0 1 190 -1 0 1
186 (1- most-positive-fixnum) most-positive-fixnum)) 191 (1- most-positive-fixnum) most-positive-fixnum))
187 (should (eq val (read (format fmt val))))))) 192 (should (eq val (read (format fmt val))))))))
188 (should-error (read (format "#32rG%x" most-positive-fixnum))
189 :type 'overflow-error))
190 193
191(ert-deftest format-%o-invalid-float () 194(ert-deftest format-%o-invalid-float ()
192 (should-error (format "%o" -1e-37) 195 (should-error (format "%o" -1e-37)
@@ -374,4 +377,14 @@
374 (should (eq (type-of (car (nth 4 buffer-undo-list))) 'marker)) 377 (should (eq (type-of (car (nth 4 buffer-undo-list))) 'marker))
375 (garbage-collect))) 378 (garbage-collect)))
376 379
380(ert-deftest format-bignum ()
381 (let* ((s1 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")
382 (v1 (read (concat "#x" s1)))
383 (s2 "99999999999999999999999999999999")
384 (v2 (read s2)))
385 (should (> v1 most-positive-fixnum))
386 (should (equal (format "%X" v1) s1))
387 (should (> v2 most-positive-fixnum))
388 (should (equal (format "%d" v2) s2))))
389
377;;; editfns-tests.el ends here 390;;; editfns-tests.el ends here
diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests.el
index 9ef5a47b159..90cd37a98a5 100644
--- a/test/src/emacs-module-tests.el
+++ b/test/src/emacs-module-tests.el
@@ -68,10 +68,10 @@
68 (1+ #x1fffffff))) 68 (1+ #x1fffffff)))
69 (should (= (mod-test-sum -1 (1+ #x1fffffff)) 69 (should (= (mod-test-sum -1 (1+ #x1fffffff))
70 #x1fffffff))) 70 #x1fffffff)))
71 (should-error (mod-test-sum 1 most-positive-fixnum) 71 (should (= (mod-test-sum 1 most-positive-fixnum)
72 :type 'overflow-error) 72 (1+ most-positive-fixnum)))
73 (should-error (mod-test-sum -1 most-negative-fixnum) 73 (should (= (mod-test-sum -1 most-negative-fixnum)
74 :type 'overflow-error)) 74 (1- most-negative-fixnum))))
75 75
76(ert-deftest mod-test-sum-docstring () 76(ert-deftest mod-test-sum-docstring ()
77 (should (string= (documentation 'mod-test-sum) "Return A + B\n\n(fn a b)"))) 77 (should (string= (documentation 'mod-test-sum) "Return A + B\n\n(fn a b)")))
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index cb173eea76d..7714c05d60a 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -34,4 +34,16 @@
34 (should-error (ftruncate 0) :type 'wrong-type-argument) 34 (should-error (ftruncate 0) :type 'wrong-type-argument)
35 (should-error (fround 0) :type 'wrong-type-argument)) 35 (should-error (fround 0) :type 'wrong-type-argument))
36 36
37(ert-deftest bignum-to-float ()
38 (should (eql (float (+ most-positive-fixnum 1))
39 (+ (float most-positive-fixnum) 1))))
40
41(ert-deftest bignum-abs ()
42 (should (= most-positive-fixnum
43 (- (abs most-negative-fixnum) 1))))
44
45(ert-deftest bignum-logb ()
46 (should (= (+ (logb most-positive-fixnum) 1)
47 (logb (+ most-positive-fixnum 1)))))
48
37(provide 'floatfns-tests) 49(provide 'floatfns-tests)
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index e4b9cbe25a4..f722ed6333e 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -604,4 +604,24 @@
604 (should (equal 1 (string-distance "ab" "a我b"))) 604 (should (equal 1 (string-distance "ab" "a我b")))
605 (should (equal 1 (string-distance "我" "她")))) 605 (should (equal 1 (string-distance "我" "她"))))
606 606
607(ert-deftest test-bignum-eql ()
608 "Test that `eql' works for bignums."
609 (let ((x (+ most-positive-fixnum 1))
610 (y (+ most-positive-fixnum 1)))
611 (should (eq x x))
612 (should (eql x y))
613 (should (equal x y))
614 (should-not (eql x 0.0e+NaN))))
615
616(ert-deftest test-bignum-hash ()
617 "Test that hash tables work for bignums."
618 ;; Make two bignums that are eql but not eq.
619 (let ((b1 (1+ most-positive-fixnum))
620 (b2 (1+ most-positive-fixnum)))
621 (dolist (test '(eq eql equal))
622 (let ((hash (make-hash-table :test test)))
623 (puthash b1 t hash)
624 (should (eq (gethash b2 hash)
625 (funcall test b1 b2)))))))
626
607(provide 'fns-tests) 627(provide 'fns-tests)
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index 639a6da93ae..17381340c7b 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -195,9 +195,7 @@ literals (Bug#20852)."
195 (should (eq x (cdr x))))) 195 (should (eq x (cdr x)))))
196 196
197(ert-deftest lread-long-hex-integer () 197(ert-deftest lread-long-hex-integer ()
198 (should-error 198 (should (bignump (read "#xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))))
199 (read "#xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
200 :type 'overflow-error))
201 199
202(ert-deftest lread-test-bug-31186 () 200(ert-deftest lread-test-bug-31186 ()
203 (with-temp-buffer 201 (with-temp-buffer
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index c96cb5d2b69..091f1aa1afb 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -98,5 +98,11 @@ otherwise, use a different charset."
98 (let ((sym '\’bar)) 98 (let ((sym '\’bar))
99 (should (eq (read (prin1-to-string sym)) sym)))) 99 (should (eq (read (prin1-to-string sym)) sym))))
100 100
101(ert-deftest print-bignum ()
102 (let* ((str "999999999999999999999999999999999")
103 (val (read str)))
104 (should (> val most-positive-fixnum))
105 (should (equal (prin1-to-string val) str))))
106
101(provide 'print-tests) 107(provide 'print-tests)
102;;; print-tests.el ends here 108;;; print-tests.el ends here