X-Git-Url: http://git.chise.org/gitweb/?p=chise%2Fxemacs-chise.git.1;a=blobdiff_plain;f=tests%2Fautomated%2Flisp-tests.el;h=1fba118beaaacba69192cabb11e7959cb85652d1;hp=f42f5d815a1d1c5b331c459fd5184339f7c51fa7;hb=46f51e794ddb493a8a76ec2f3be00b41e3b0be22;hpb=77dcef404dc78635f6ffa8f71a803d2bc7cc8921 diff --git a/tests/automated/lisp-tests.el b/tests/automated/lisp-tests.el index f42f5d8..1fba118 100644 --- a/tests/automated/lisp-tests.el +++ b/tests/automated/lisp-tests.el @@ -22,7 +22,7 @@ ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ;; 02111-1307, USA. -;;; Synched up with: not in FSF Emacs. +;;; Synched up with: Not in FSF. ;;; Commentary: @@ -119,7 +119,7 @@ (Check-Error wrong-type-argument (nconc 'foo nil)) -(dolist (length `(1 2 3 4 1000 2000)) +(dolist (length '(1 2 3 4 1000 2000)) (Check-Error circular-list (nconc (make-circular-list length) 'foo)) (Check-Error circular-list (nconc '(1 . 2) (make-circular-list length) 'foo)) (Check-Error circular-list (nconc '(1 . 2) '(3 . 4) (make-circular-list length) 'foo))) @@ -158,7 +158,7 @@ (Assert (eq (last x 3) (cdr x))) (Assert (eq (last x 4) x)) (Assert (eq (last x 9) x)) - (Assert (eq (last `(1 . 2) 0) 2)) + (Assert (eq (last '(1 . 2) 0) 2)) ) ;;----------------------------------------------------- @@ -213,7 +213,7 @@ (Check-Error circular-list (copy-list (make-circular-list 1))) (Check-Error circular-list (copy-list (make-circular-list 2000))) (Assert (eq '() (copy-list '()))) -(dolist (x `((1) (1 2) (1 2 3) (1 2 . 3))) +(dolist (x '((1) (1 2) (1 2 3) (1 2 . 3))) (let ((y (copy-list x))) (Assert (and (equal x y) (not (eq x y)))))) @@ -229,6 +229,8 @@ (Assert (= (+ 1.0 1) 2.0)) (Assert (= (+ 1.0 1 1) 3.0)) (Assert (= (+ 1 1 1.0) 3.0)) +(Assert (eq (1+ most-positive-fixnum) most-negative-fixnum)) +(Assert (eq (+ most-positive-fixnum 1) most-negative-fixnum)) ;; Test `-' (Check-Error wrong-number-of-arguments (-)) @@ -242,7 +244,7 @@ (Assert (= (- one one) 0)) (Assert (= (- one one one) -1)) (Assert (= (+ one 1) 2)) - (dolist (zero `(0 0.0 ?\0)) + (dolist (zero '(0 0.0 ?\0)) (Assert (= (+ 1 zero) 1)) (Assert (= (+ zero 1) 1)) (Assert (= (- zero) zero)) @@ -253,10 +255,13 @@ (Assert (= (- 1.5 1) .5)) (Assert (= (- 1 1.5) (- .5))) +(Assert (eq (1- most-negative-fixnum) most-positive-fixnum)) +(Assert (eq (- most-negative-fixnum 1) most-positive-fixnum)) + ;; Test `/' ;; Test division by zero errors -(dolist (zero `(0 0.0 ?\0)) +(dolist (zero '(0 0.0 ?\0)) (Check-Error arith-error (/ zero)) (dolist (n1 `(42 42.0 ?\042 ,(Int-to-Marker 42))) (Check-Error arith-error (/ n1 zero)) @@ -269,14 +274,14 @@ (Assert (= (/ (setq x 2)) 0)) (Assert (= (/ (setq x 2.0)) 0.5))) -(dolist (six `(6 6.0 ?\06)) - (dolist (two `(2 2.0 ?\02)) - (dolist (three `(3 3.0 ?\03)) +(dolist (six '(6 6.0 ?\06)) + (dolist (two '(2 2.0 ?\02)) + (dolist (three '(3 3.0 ?\03)) (Assert (= (/ six two) three))))) -(dolist (three `(3 3.0 ?\03)) +(dolist (three '(3 3.0 ?\03)) (Assert (= (/ three 2.0) 1.5))) -(dolist (two `(2 2.0 ?\02)) +(dolist (two '(2 2.0 ?\02)) (Assert (= (/ 3.0 two) 1.5))) ;; Test `*' @@ -285,18 +290,18 @@ (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) (Assert (= 1 (* one)))) -(dolist (two `(2 2.0 ?\02)) +(dolist (two '(2 2.0 ?\02)) (Assert (= 2 (* two)))) -(dolist (six `(6 6.0 ?\06)) - (dolist (two `(2 2.0 ?\02)) - (dolist (three `(3 3.0 ?\03)) +(dolist (six '(6 6.0 ?\06)) + (dolist (two '(2 2.0 ?\02)) + (dolist (three '(3 3.0 ?\03)) (Assert (= (* three two) six))))) -(dolist (three `(3 3.0 ?\03)) - (dolist (two `(2 2.0 ?\02)) +(dolist (three '(3 3.0 ?\03)) + (dolist (two '(2 2.0 ?\02)) (Assert (= (* 1.5 two) three)) - (dolist (five `(5 5.0 ?\05)) + (dolist (five '(5 5.0 ?\05)) (Assert (= 30 (* five two three)))))) ;; Test `+' @@ -305,12 +310,12 @@ (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) (Assert (= 1 (+ one)))) -(dolist (two `(2 2.0 ?\02)) +(dolist (two '(2 2.0 ?\02)) (Assert (= 2 (+ two)))) -(dolist (five `(5 5.0 ?\05)) - (dolist (two `(2 2.0 ?\02)) - (dolist (three `(3 3.0 ?\03)) +(dolist (five '(5 5.0 ?\05)) + (dolist (two '(2 2.0 ?\02)) + (dolist (three '(3 3.0 ?\03)) (Assert (= (+ three two) five)) (Assert (= 10 (+ five two three)))))) @@ -341,7 +346,7 @@ (Check-Error wrong-type-argument (logior 3.0)) (Check-Error wrong-type-argument (logand 3.0)) -(dolist (three `(3 ?\03)) +(dolist (three '(3 ?\03)) (Assert (eq 3 (logand three))) (Assert (eq 3 (logxor three))) (Assert (eq 3 (logior three))) @@ -350,11 +355,11 @@ (Assert (eq 3 (logior three three)))) (dolist (one `(1 ?\01 ,(Int-to-Marker 1))) - (dolist (two `(2 ?\02)) + (dolist (two '(2 ?\02)) (Assert (eq 0 (logand one two))) (Assert (eq 3 (logior one two))) (Assert (eq 3 (logxor one two)))) - (dolist (three `(3 ?\03)) + (dolist (three '(3 ?\03)) (Assert (eq 1 (logand one three))) (Assert (eq 3 (logior one three))) (Assert (eq 2 (logxor one three))))) @@ -468,7 +473,7 @@ ;; Meat (dolist (one `(1 1.0 ,(Int-to-Marker 1) ?\01)) - (dolist (two `(2 2.0 ?\02)) + (dolist (two '(2 2.0 ?\02)) (Assert (< one two)) (Assert (<= one two)) (Assert (<= two two)) @@ -489,7 +494,7 @@ )) (dolist (one `(1 1.0 ,(Int-to-Marker 1) ?\01)) - (dolist (two `(2 2.0 ?\02)) + (dolist (two '(2 2.0 ?\02)) (Assert (< one two)) (Assert (<= one two)) (Assert (<= two two)) @@ -537,7 +542,7 @@ (Check-Error wrong-number-of-arguments (,fun)) (Check-Error wrong-number-of-arguments (,fun nil)) (Check-Error malformed-list (,fun nil 1)) - ,@(loop for n in `(1 2 2000) + ,@(loop for n in '(1 2 2000) collect `(Check-Error circular-list (,fun 1 (make-circular-list ,n)))))) (test-funs (&rest funs) `(progn ,@(loop for fun in funs collect `(test-fun ,fun))))) @@ -725,3 +730,134 @@ (Assert (eq (type-of "42") 'string)) (Assert (eq (type-of 'foo) 'symbol)) (Assert (eq (type-of (selected-device)) 'device)) + +;;----------------------------------------------------- +;; Test mapping functions +;;----------------------------------------------------- +(Check-Error wrong-type-argument (mapcar #'identity (current-buffer))) +(Assert (equal (mapcar #'identity load-path) load-path)) +(Assert (equal (mapcar #'identity '(1 2 3)) '(1 2 3))) +(Assert (equal (mapcar #'identity "123") '(?1 ?2 ?3))) +(Assert (equal (mapcar #'identity [1 2 3]) '(1 2 3))) +(Assert (equal (mapcar #'identity #*010) '(0 1 0))) + +(let ((z 0) (list (make-list 1000 1))) + (mapc (lambda (x) (incf z x)) list) + (Assert (eq 1000 z))) + +(Check-Error wrong-type-argument (mapvector #'identity (current-buffer))) +(Assert (equal (mapvector #'identity '(1 2 3)) [1 2 3])) +(Assert (equal (mapvector #'identity "123") [?1 ?2 ?3])) +(Assert (equal (mapvector #'identity [1 2 3]) [1 2 3])) +(Assert (equal (mapvector #'identity #*010) [0 1 0])) + +(Check-Error wrong-type-argument (mapconcat #'identity (current-buffer) "foo")) +(Assert (equal (mapconcat #'identity '("1" "2" "3") "|") "1|2|3")) +(Assert (equal (mapconcat #'identity ["1" "2" "3"] "|") "1|2|3")) + +;; The following 2 functions used to crash XEmacs via mapcar1(). +;; We don't test the actual values of the mapcar, since they're undefined. +(Assert + (let ((x (list (cons 1 1) (cons 2 2) (cons 3 3)))) + (mapcar + (lambda (y) + "Devious evil mapping function" + (when (eq (car y) 2) ; go out onto a limb + (setcdr x nil) ; cut it off behind us + (garbage-collect)) ; are we riding a magic broomstick? + (car y)) ; sorry, hard landing + x))) + +(Assert + (let ((x (list (cons 1 1) (cons 2 2) (cons 3 3)))) + (mapcar + (lambda (y) + "Devious evil mapping function" + (when (eq (car y) 1) + (setcdr (cdr x) 42)) ; drop a brick wall onto the freeway + (car y)) + x))) + +;;----------------------------------------------------- +;; Test vector functions +;;----------------------------------------------------- +(Assert (equal [1 2 3] [1 2 3])) +(Assert (equal [] [])) +(Assert (not (equal [1 2 3] []))) +(Assert (not (equal [1 2 3] [1 2 4]))) +(Assert (not (equal [0 2 3] [1 2 3]))) +(Assert (not (equal [1 2 3] [1 2 3 4]))) +(Assert (not (equal [1 2 3 4] [1 2 3]))) +(Assert (equal (vector 1 2 3) [1 2 3])) +(Assert (equal (make-vector 3 1) [1 1 1])) + +;;----------------------------------------------------- +;; Test bit-vector functions +;;----------------------------------------------------- +(Assert (equal #*010 #*010)) +(Assert (equal #* #*)) +(Assert (not (equal #*010 #*011))) +(Assert (not (equal #*010 #*))) +(Assert (not (equal #*110 #*010))) +(Assert (not (equal #*010 #*0100))) +(Assert (not (equal #*0101 #*010))) +(Assert (equal (bit-vector 0 1 0) #*010)) +(Assert (equal (make-bit-vector 3 1) #*111)) +(Assert (equal (make-bit-vector 3 0) #*000)) + +;;----------------------------------------------------- +;; Test buffer-local variables used as (ugh!) function parameters +;;----------------------------------------------------- +(make-local-variable 'test-emacs-buffer-local-variable) +(byte-compile + (defun test-emacs-buffer-local-parameter (test-emacs-buffer-local-variable) + (setq test-emacs-buffer-local-variable nil))) +(test-emacs-buffer-local-parameter nil) + +;;----------------------------------------------------- +;; Test split-string +;;----------------------------------------------------- +;; Hrvoje didn't like these tests so I'm disabling them for now. -sb +;(Assert (equal (split-string "foo" "") '("" "f" "o" "o" ""))) +;(Assert (equal (split-string "foo" "^") '("" "foo"))) +;(Assert (equal (split-string "foo" "$") '("foo" ""))) +(Assert (equal (split-string "foo,bar" ",") '("foo" "bar"))) +(Assert (equal (split-string ",foo,bar," ",") '("" "foo" "bar" ""))) +(Assert (equal (split-string ",foo,bar," "^,") '("" "foo,bar,"))) +(Assert (equal (split-string ",foo,bar," ",$") '(",foo,bar" ""))) +(Assert (equal (split-string ",foo,,bar," ",") '("" "foo" "" "bar" ""))) +(Assert (equal (split-string "foo,,,bar" ",") '("foo" "" "" "bar"))) +(Assert (equal (split-string "foo,,bar,," ",") '("foo" "" "bar" "" ""))) +(Assert (equal (split-string "foo,,bar" ",+") '("foo" "bar"))) +(Assert (equal (split-string ",foo,,bar," ",+") '("" "foo" "bar" ""))) + +;;----------------------------------------------------- +;; Test near-text buffer functions. +;;----------------------------------------------------- +(with-temp-buffer + (erase-buffer) + (Assert (eq (char-before) nil)) + (Assert (eq (char-before (point)) nil)) + (Assert (eq (char-before (point-marker)) nil)) + (Assert (eq (char-before (point) (current-buffer)) nil)) + (Assert (eq (char-before (point-marker) (current-buffer)) nil)) + (Assert (eq (char-after) nil)) + (Assert (eq (char-after (point)) nil)) + (Assert (eq (char-after (point-marker)) nil)) + (Assert (eq (char-after (point) (current-buffer)) nil)) + (Assert (eq (char-after (point-marker) (current-buffer)) nil)) + (Assert (eq (preceding-char) 0)) + (Assert (eq (preceding-char (current-buffer)) 0)) + (Assert (eq (following-char) 0)) + (Assert (eq (following-char (current-buffer)) 0)) + (insert "foobar") + (Assert (eq (char-before) ?r)) + (Assert (eq (char-after) nil)) + (Assert (eq (preceding-char) ?r)) + (Assert (eq (following-char) 0)) + (goto-char (point-min)) + (Assert (eq (char-before) nil)) + (Assert (eq (char-after) ?f)) + (Assert (eq (preceding-char) 0)) + (Assert (eq (following-char) ?f)) + )