;; Test the test support for buffers (add-to-list 'load-path ".") (load "ert-buffer" nil t) (add-to-list 'load-path "..") (load "rst.el" nil t) ;; **************************************************************************** ;; `ert-Buf' (defun roundtrip-ert-Buf (in) (with-temp-buffer (ert-Buf-to-buffer (string-to-ert-Buf in)) (ert-Buf-string (buffer-to-ert-Buf)))) (ert-deftest ert-Buf () "Tests for functions working with `ert-Buf's" (should (equal (concat ert-Buf-point-char "abc\n") (roundtrip-ert-Buf (concat ert-Buf-point-char "abc\n")))) (should (equal (concat "a" ert-Buf-point-char "bc\n") (roundtrip-ert-Buf (concat "a" ert-Buf-point-char "bc\n")))) (should (equal (concat "ab" ert-Buf-point-char "c\n") (roundtrip-ert-Buf (concat "ab" ert-Buf-point-char "c\n")))) (should (equal (concat "abc" ert-Buf-point-char "\n") (roundtrip-ert-Buf (concat "abc" ert-Buf-point-char "\n")))) (should (equal (concat "abc\n" ert-Buf-point-char) (roundtrip-ert-Buf (concat "abc\n" ert-Buf-point-char)))) (should (equal (concat ert-Buf-point-char "abc\n" ert-Buf-mark-char "") (roundtrip-ert-Buf (concat ert-Buf-point-char "abc\n" ert-Buf-mark-char "")))) (should (equal (concat ert-Buf-mark-char "abc\n" ert-Buf-point-char) (roundtrip-ert-Buf (concat ert-Buf-mark-char "abc\n" ert-Buf-point-char)))) (should (equal (concat "a" ert-Buf-mark-char ert-Buf-point-char "bc\n") (roundtrip-ert-Buf (concat "a" ert-Buf-point-char "" ert-Buf-mark-char "bc\n")))) (should (equal (concat "ab" ert-Buf-mark-char "" ert-Buf-point-char "c\n") (roundtrip-ert-Buf (concat "ab" ert-Buf-mark-char ert-Buf-point-char "c\n")))) (should-error (string-to-ert-Buf (concat "ab" ert-Buf-point-char ert-Buf-point-char "c\n"))) (should-error (string-to-ert-Buf (concat "ab" ert-Buf-mark-char ert-Buf-mark-char "c\n"))) ) ;; **************************************************************************** ;; Advice `ert-completing-read' (defvar read-fun-args nil "A list of functions and their argument lists for functions reading the minibuffer to be run successively. Prompt is omitted.") (defun insert-reads () (interactive) (while read-fun-args (let* ((fun-arg (pop read-fun-args)) (result (apply (car fun-arg) "" (cdr fun-arg)))) (insert (if (integerp result) (int-to-string result) result) "\n")))) (defun test-reads (inputs fun-args result) (setq read-fun-args fun-args) (ert-equal-buffer '(insert-reads) "" result inputs)) (ert-deftest reads () "Tests for functions using `completing-read's" (should (test-reads '(5) '((read-number)) "5\n")) (should (test-reads nil nil "")) (should-error (test-reads '("") nil "")) ;; Too much input (should-error (test-reads '(5) '((read-number) (read-number)) "")) ;; Too less input (should (test-reads '("") '((completing-read nil)) "\n")) (should (test-reads '("" "") '((completing-read nil) (completing-read nil)) "\n\n")) (should (test-reads '("a" "b") '((completing-read nil) (completing-read nil)) "a\nb\n")) (should (test-reads '("a" "b") '((completing-read ("a" "b")) (completing-read ("a" "b"))) "a\nb\n")) (should (test-reads '("a" "b") '((completing-read ("a" "b")) (completing-read ("a"))) "a\nb\n")) (should-error (test-reads '("a" "b") '((completing-read ("a" "b")) (completing-read ("a") nil t)) "a\nb\n")) ;; Invalid input (should (test-reads '("a" "") '((completing-read ("a" "b")) (completing-read ("a") nil t)) "a\n\n")) (should-error (test-reads '("a" "") '((completing-read ("a" "b")) (completing-read ("a") nil 'non-empty)) "a\n\n")) (should (test-reads '("x") '((read-string)) "x\n")) (should (test-reads '("") '((read-string nil nil "x")) "x\n")) (should (test-reads '("y") '((read-string nil nil "x")) "y\n")) (should (test-reads '("") '((read-number 5)) "5\n")) (should (test-reads '(0) '((read-number 5)) "0\n")) )