aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorAndrea Corallo2019-08-06 21:54:51 +0200
committerAndrea Corallo2020-01-01 11:33:57 +0100
commit6465002b8a51d065a662cb589e8e1cf0a78ad160 (patch)
tree48cdd43c6d5f4e78606709da8346a04731e37f0c /test/src
parentdba7034ea10fb394b0dcf91256b7df094218119f (diff)
downloademacs-6465002b8a51d065a662cb589e8e1cf0a78ad160.tar.gz
emacs-6465002b8a51d065a662cb589e8e1cf0a78ad160.zip
add tromeys tests
Diffstat (limited to 'test/src')
-rw-r--r--test/src/comp-tests.el280
1 files changed, 280 insertions, 0 deletions
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index 96362ecf6e5..332dd3f8c0f 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -479,4 +479,284 @@
479 479
480 (should (= (comp-tests-cons-cdr-f 3) 3))) 480 (should (= (comp-tests-cons-cdr-f 3) 3)))
481 481
482;;;;;;;;;;;;;;;;;;;;
483;; Tromey's tests ;;
484;;;;;;;;;;;;;;;;;;;;
485
486(defun comp-test-apply (func &rest args)
487 (unless (subrp (symbol-function func))
488 (native-compile func))
489 (apply func args))
490
491;; Test Bconsp.
492(defun comp-test-consp (x) (consp x))
493
494(ert-deftest comp-consp ()
495 (should-not (comp-test-apply 'comp-test-consp 23))
496 (should-not (comp-test-apply 'comp-test-consp nil))
497 (should (comp-test-apply 'comp-test-consp '(1 . 2))))
498
499;; Test Blistp.
500(defun comp-test-listp (x) (listp x))
501
502(ert-deftest comp-listp ()
503 (should-not (comp-test-apply 'comp-test-listp 23))
504 (should (comp-test-apply 'comp-test-listp nil))
505 (should (comp-test-apply 'comp-test-listp '(1 . 2))))
506
507;; Test Bstringp.
508(defun comp-test-stringp (x) (stringp x))
509
510(ert-deftest comp-stringp ()
511 (should-not (comp-test-apply 'comp-test-stringp 23))
512 (should-not (comp-test-apply 'comp-test-stringp nil))
513 (should (comp-test-apply 'comp-test-stringp "hi")))
514
515;; Test Bsymbolp.
516(defun comp-test-symbolp (x) (symbolp x))
517
518(ert-deftest comp-symbolp ()
519 (should-not (comp-test-apply 'comp-test-symbolp 23))
520 (should-not (comp-test-apply 'comp-test-symbolp "hi"))
521 (should (comp-test-apply 'comp-test-symbolp 'whatever)))
522
523;; Test Bintegerp.
524(defun comp-test-integerp (x) (integerp x))
525
526(ert-deftest comp-integerp ()
527 (should (comp-test-apply 'comp-test-integerp 23))
528 (should-not (comp-test-apply 'comp-test-integerp 57.5))
529 (should-not (comp-test-apply 'comp-test-integerp "hi"))
530 (should-not (comp-test-apply 'comp-test-integerp 'whatever)))
531
532;; Test Bnumberp.
533(defun comp-test-numberp (x) (numberp x))
534
535(ert-deftest comp-numberp ()
536 (should (comp-test-apply 'comp-test-numberp 23))
537 (should (comp-test-apply 'comp-test-numberp 57.5))
538 (should-not (comp-test-apply 'comp-test-numberp "hi"))
539 (should-not (comp-test-apply 'comp-test-numberp 'whatever)))
540
541;; Test Badd1.
542(defun comp-test-add1 (x) (1+ x))
543
544(ert-deftest comp-add1 ()
545 (should (eq (comp-test-apply 'comp-test-add1 23) 24))
546 (should (eq (comp-test-apply 'comp-test-add1 -17) -16))
547 (should (eql (comp-test-apply 'comp-test-add1 1.0) 2.0))
548 (should-error (comp-test-apply 'comp-test-add1 nil)
549 :type 'wrong-type-argument))
550
551;; Test Bsub1.
552(defun comp-test-sub1 (x) (1- x))
553
554(ert-deftest comp-sub1 ()
555 (should (eq (comp-test-apply 'comp-test-sub1 23) 22))
556 (should (eq (comp-test-apply 'comp-test-sub1 -17) -18))
557 (should (eql (comp-test-apply 'comp-test-sub1 1.0) 0.0))
558 (should-error (comp-test-apply 'comp-test-sub1 nil)
559 :type 'wrong-type-argument))
560
561;; Test Bneg.
562(defun comp-test-negate (x) (- x))
563
564(ert-deftest comp-negate ()
565 (should (eq (comp-test-apply 'comp-test-negate 23) -23))
566 (should (eq (comp-test-apply 'comp-test-negate -17) 17))
567 (should (eql (comp-test-apply 'comp-test-negate 1.0) -1.0))
568 (should-error (comp-test-apply 'comp-test-negate nil)
569 :type 'wrong-type-argument))
570
571;; Test Bnot.
572(defun comp-test-not (x) (not x))
573
574(ert-deftest comp-not ()
575 (should (eq (comp-test-apply 'comp-test-not 23) nil))
576 (should (eq (comp-test-apply 'comp-test-not nil) t))
577 (should (eq (comp-test-apply 'comp-test-not t) nil)))
578
579;; Test Bbobp, Beobp, Bpoint, Bpoint_min, Bpoint_max.
580(defun comp-test-bobp () (bobp))
581(defun comp-test-eobp () (eobp))
582(defun comp-test-point () (point))
583(defun comp-test-point-min () (point-min))
584(defun comp-test-point-max () (point-max))
585
586(ert-deftest comp-bobp-and-eobp ()
587 (with-temp-buffer
588 (should (comp-test-apply 'comp-test-bobp))
589 (should (comp-test-apply 'comp-test-eobp))
590 (insert "hi")
591 (goto-char (point-min))
592 (should (eq (comp-test-apply 'comp-test-point-min) (point-min)))
593 (should (eq (comp-test-apply 'comp-test-point) (point-min)))
594 (should (comp-test-apply 'comp-test-bobp))
595 (should-not (comp-test-apply 'comp-test-eobp))
596 (goto-char (point-max))
597 (should (eq (comp-test-apply 'comp-test-point-max) (point-max)))
598 (should (eq (comp-test-apply 'comp-test-point) (point-max)))
599 (should-not (comp-test-apply 'comp-test-bobp))
600 (should (comp-test-apply 'comp-test-eobp))))
601
602;; Test Bcar and Bcdr.
603(defun comp-test-car (x) (car x))
604(defun comp-test-cdr (x) (cdr x))
605
606(ert-deftest comp-car-cdr ()
607 (let ((pair '(1 . b)))
608 (should (eq (comp-test-apply 'comp-test-car pair) 1))
609 (should (eq (comp-test-apply 'comp-test-car nil) nil))
610 (should-error (comp-test-apply 'comp-test-car 23)
611 :type 'wrong-type-argument)
612 (should (eq (comp-test-apply 'comp-test-cdr pair) 'b))
613 (should (eq (comp-test-apply 'comp-test-cdr nil) nil))
614 (should-error (comp-test-apply 'comp-test-cdr 23)
615 :type 'wrong-type-argument)))
616
617;; Test Bcar_safe and Bcdr_safe.
618(defun comp-test-car-safe (x) (car-safe x))
619(defun comp-test-cdr-safe (x) (cdr-safe x))
620
621(ert-deftest comp-car-cdr-safe ()
622 (let ((pair '(1 . b)))
623 (should (eq (comp-test-apply 'comp-test-car-safe pair) 1))
624 (should (eq (comp-test-apply 'comp-test-car-safe nil) nil))
625 (should (eq (comp-test-apply 'comp-test-car-safe 23) nil))
626 (should (eq (comp-test-apply 'comp-test-cdr-safe pair) 'b))
627 (should (eq (comp-test-apply 'comp-test-cdr-safe nil) nil))
628 (should (eq (comp-test-apply 'comp-test-cdr-safe 23) nil))))
629
630;; Test Beq.
631(defun comp-test-eq (x y) (eq x y))
632
633(ert-deftest comp-eq ()
634 (should (comp-test-apply 'comp-test-eq 'a 'a))
635 (should (comp-test-apply 'comp-test-eq 5 5))
636 (should-not (comp-test-apply 'comp-test-eq 'a 'b))
637 (should-not (comp-test-apply 'comp-test-eq "x" "x")))
638
639;; Test Bgotoifnil.
640(defun comp-test-if (x y) (if x x y))
641
642(ert-deftest comp-if ()
643 (should (eq (comp-test-apply 'comp-test-if 'a 'b) 'a))
644 (should (eq (comp-test-apply 'comp-test-if 0 23) 0))
645 (should (eq (comp-test-apply 'comp-test-if nil 'b) 'b)))
646
647;; Test Bgotoifnilelsepop.
648(defun comp-test-and (x y) (and x y))
649
650(ert-deftest comp-and ()
651 (should (eq (comp-test-apply 'comp-test-and 'a 'b) 'b))
652 (should (eq (comp-test-apply 'comp-test-and 0 23) 23))
653 (should (eq (comp-test-apply 'comp-test-and nil 'b) nil)))
654
655;; Test Bgotoifnonnilelsepop.
656(defun comp-test-or (x y) (or x y))
657
658(ert-deftest comp-or ()
659 (should (eq (comp-test-apply 'comp-test-or 'a 'b) 'a))
660 (should (eq (comp-test-apply 'comp-test-or 0 23) 0))
661 (should (eq (comp-test-apply 'comp-test-or nil 'b) 'b)))
662
663;; Test Bsave_excursion.
664(defun comp-test-save-excursion ()
665 (save-excursion
666 (insert "XYZ")))
667
668;; Test Bcurrent_buffer.
669(defun comp-test-current-buffer () (current-buffer))
670
671(ert-deftest comp-save-excursion ()
672 (with-temp-buffer
673 (comp-test-apply 'comp-test-save-excursion)
674 (should (eq (point) (point-min)))
675 (should (eq (comp-test-apply 'comp-test-current-buffer) (current-buffer)))))
676
677;; Test Bgtr.
678(defun comp-test-> (a b)
679 (> a b))
680
681(ert-deftest comp-> ()
682 (should (eq (comp-test-apply 'comp-test-> 0 23) nil))
683 (should (eq (comp-test-apply 'comp-test-> 23 0) t)))
684
685;; Test Bpushcatch.
686(defun comp-test-catch (&rest l)
687 (catch 'done
688 (dolist (v l)
689 (when (> v 23)
690 (throw 'done v)))))
691
692(ert-deftest comp-catch ()
693 (should (eq (comp-test-apply 'comp-test-catch 0 1 2 3 4) nil))
694 (should (eq (comp-test-apply 'comp-test-catch 20 21 22 23 24 25 26 27 28) 24)))
695
696;; Test Bmemq.
697(defun comp-test-memq (val list)
698 (memq val list))
699
700(ert-deftest comp-memq ()
701 (should (equal (comp-test-apply 'comp-test-memq 0 '(5 4 3 2 1 0)) '(0)))
702 (should (eq (comp-test-apply 'comp-test-memq 72 '(5 4 3 2 1 0)) nil)))
703
704;; Test BlistN.
705(defun comp-test-listN (x)
706 (list x x x x x x x x x x x x x x x x))
707
708(ert-deftest comp-listN ()
709 (should (equal (comp-test-apply 'comp-test-listN 57)
710 '(57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57))))
711
712;; Test BconcatN.
713(defun comp-test-concatN (x)
714 (concat x x x x x x))
715
716(ert-deftest comp-concatN ()
717 (should (equal (comp-test-apply 'comp-test-concatN "x") "xxxxxx")))
718
719;; Test optional and rest arguments.
720(defun comp-test-opt-rest (a &optional b &rest c)
721 (list a b c))
722
723(ert-deftest comp-opt-rest ()
724 (should (equal (comp-test-apply 'comp-test-opt-rest 1) '(1 nil nil)))
725 (should (equal (comp-test-apply 'comp-test-opt-rest 1 2) '(1 2 nil)))
726 (should (equal (comp-test-apply 'comp-test-opt-rest 1 2 3) '(1 2 (3))))
727 (should (equal (comp-test-apply 'comp-test-opt-rest 1 2 56 57 58)
728 '(1 2 (56 57 58)))))
729
730;; Test for too many arguments.
731(defun comp-test-opt (a &optional b)
732 (cons a b))
733
734(ert-deftest comp-opt ()
735 (should (equal (comp-test-apply 'comp-test-opt 23) '(23)))
736 (should (equal (comp-test-apply 'comp-test-opt 23 24) '(23 . 24)))
737 (should-error (comp-test-apply 'comp-test-opt)
738 :type 'wrong-number-of-arguments)
739 (should-error (comp-test-apply 'comp-test-opt nil 24 97)
740 :type 'wrong-number-of-arguments))
741
742;; Test for unwind-protect.
743(defvar comp-test-up-val nil)
744(defun comp-test-unwind-protect (fun)
745 (setq comp-test-up-val nil)
746 (unwind-protect
747 (progn
748 (setq comp-test-up-val 23)
749 (funcall fun)
750 (setq comp-test-up-val 24))
751 (setq comp-test-up-val 999)))
752
753(ert-deftest comp-unwind-protect ()
754 (comp-test-unwind-protect 'ignore)
755 (should (eq comp-test-up-val 999))
756 (condition-case nil
757 (comp-test-unwind-protect (lambda () (error "HI")))
758 (error
759 nil))
760 (should (eq comp-test-up-val 999)))
761
482;;; comp-tests.el ends here 762;;; comp-tests.el ends here