branch: externals/objed commit 2f2d8bf0ce53178b25d69e3cb06b7e3f5eb79c73 Author: Clemens Radermacher <clem...@posteo.net> Commit: Clemens Radermacher <clem...@posteo.net>
Starting to change testing Testing should be as easy as possible. Created testfiles should be picked up automatically. For now the folder still needs to be specified in the test. --- test/tests.el | 171 +++++++++++++++++++-------------- test/tests/activate/backward-word | 5 + test/tests/activate/beginning-of-defun | 13 +++ test/tests/activate/beginning-of-line | 6 ++ test/tests/activate/forward-word | 5 + test/tests/activate/next-line | 8 ++ 6 files changed, 137 insertions(+), 71 deletions(-) diff --git a/test/tests.el b/test/tests.el index e21cbb0..47c58bf 100644 --- a/test/tests.el +++ b/test/tests.el @@ -1,8 +1,10 @@ (require 'ert) (require 'cl-lib) (require 'objed) + ;; activate on load (objed-mode 1) +(setq-default require-final-newline nil) ;; defuns adapted from lispy-test.el @@ -75,81 +77,108 @@ Insert KEY if there's no command." ;; (should (equal (objed-decode-keysequence "3\C-?") ;; '(3 "")))) -(defmacro objed-with (in body &optional object) +(defmacro objed-with (in body &optional object file) (let ((init (if object `(objed--init ',object) - '(objed--init 'char)))) - `(let ((temp-buffer (generate-new-buffer " *temp*"))) - (save-window-excursion - (unwind-protect - (progn - (switch-to-buffer temp-buffer) - (emacs-lisp-mode) - (transient-mark-mode 1) - (insert ,in) - (goto-char (point-min)) - (when (search-forward "~" nil t) - (backward-delete-char 1) - (set-mark (point))) - (goto-char (point-max)) - (search-backward "|") - (delete-char 1) - ,init - (setq current-prefix-arg nil) - ;; execute command - ,@(mapcar (lambda (x) - (cond ((equal x '(kbd "C-u")) - `(setq current-prefix-arg (list 4))) - ((or (stringp x) - (and (listp x) - (eq (car x) 'kbd))) - `(objed-unalias ,x)) - (t x))) - (list body)) - (let ((npos (point-marker))) - (when objed--current-obj - (goto-char (objed--end)) - (insert ">") - (goto-char (objed--beg)) - (insert "<")) - (goto-char npos) - (skip-chars-backward "<" (1- (point))) - (skip-chars-forward ">" (1+ (point))) - (insert "|") - (when (region-active-p) - (exchange-point-and-mark) - (insert "~"))) - (buffer-substring-no-properties - (point-min) - (point-max))) - (objed--exit-objed) - ;; reset for next test - (setq last-command nil) - (setq objed--last-states nil) - (and (buffer-name temp-buffer) - (kill-buffer temp-buffer))))))) + '(objed--init 'char))) + (body (if (stringp body) `(kbd ,body) body))) + `(let ((temp-buffer (generate-new-buffer " *temp*"))) + (save-window-excursion + (unwind-protect + (progn + (switch-to-buffer temp-buffer) + (emacs-lisp-mode) + (transient-mark-mode 1) + (insert ,in) + (goto-char (point-min)) + (when (search-forward "~" nil t) + (backward-delete-char 1) + (set-mark (point))) + (goto-char (point-max)) + (search-backward "|") + (delete-char 1) + ,init + (setq current-prefix-arg nil) + ;; execute command + ,@(mapcar (lambda (x) + (cond ((equal x '(kbd "C-u")) + `(setq current-prefix-arg (list 4))) + ((or (stringp x) + (and (listp x) + (eq (car x) 'kbd))) + `(objed-unalias ,x)) + (t x))) + (list body)) + (let ((npos (point-marker))) + (when objed--current-obj + (goto-char (objed--end)) + (insert ">") + (goto-char (objed--beg)) + (insert "<")) + (goto-char npos) + (skip-chars-backward "<" (1- (point))) + (skip-chars-forward ">" (1+ (point))) + (insert "|") + (when (region-active-p) + (exchange-point-and-mark) + (insert "~"))) + (buffer-substring-no-properties + (point-min) + (point-max))) + (objed--exit-objed) + ;; reset for next test + (setq last-command nil) + (setq objed--last-states nil) + (and (buffer-name temp-buffer) + (kill-buffer temp-buffer))))))) + +(defvar objed--count 1) + +(defun objed-get-test (file) + (let ((parsed nil)) + (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (push (buffer-substring (line-beginning-position) (line-end-position)) + parsed) + (search-forward ";;;;" nil t) + (forward-line 1) + (push (buffer-substring (point) (progn (search-forward ";;;;") + (forward-char -4) + (point))) + parsed) + (forward-line 1) + (push (buffer-substring (point) + (point-max)) + parsed)) + (nreverse parsed))) + + +(defmacro objed-test (file) + (let* ((parsed (objed-get-test file)) + (key (nth 0 parsed)) + (str1 (nth 1 parsed)) + (str2 (nth 2 parsed))) + ;; show data in ouput... + `(should (string= (objed-with ,str1 ,key nil ,file) + ,str2)))) + +(defmacro objed-create-tests-for (dir) + (let ((files (directory-files (format "test/tests/%s" dir) t "^[^.]")) + (body nil)) + (push 'progn body) + (dolist (file files) + (push `(objed-test ,file) body)) + (nreverse body))) + + ;; needs to come first initializes, for tests, too (ert-deftest objed-activate () - (should (string= (objed-with "Testing line he|re" "\C-a") - "|<Testing line here>")) - (should (string= (objed-with "Testing line he|re" (kbd "M-b")) - "Testing line |<here>")) - (should (string= (objed-with "Testing line he|re" (kbd "M-f")) - "Testing line <here>|")) - (should (string= (objed-with "Testing line he|re\nFollowing line here" "\C-n") - "Testing line here\n<Following line |here>")) - (should (string= (objed-with "Testing line he|re" (objed--call-object-interactively 'line)) - "|<Testing line here>")) - (should (string= (objed-with " -(defun objed--save-start-position (&rest _) - \"Save position of| point via `objed--opoint'.\" - (setq objed--opoint (point))) -" (kbd "C-M-a")) - "< -|(defun objed--save-start-position (&rest _) - \"Save position of point via `objed--opoint'.\" - (setq objed--opoint (point))) ->"))) + (objed-create-tests-for "activate") + ;; (should (string= (objed-with "Testing line he|re" + ;; (objed--call-object-interactively 'line)) + ;; "|<Testing line here>")) + ) (ert-deftest objed-basic-movement () diff --git a/test/tests/activate/backward-word b/test/tests/activate/backward-word new file mode 100644 index 0000000..2887599 --- /dev/null +++ b/test/tests/activate/backward-word @@ -0,0 +1,5 @@ +M-b +;;;; +Testing line he|re +;;;; +Testing line |<here> diff --git a/test/tests/activate/beginning-of-defun b/test/tests/activate/beginning-of-defun new file mode 100644 index 0000000..d11186b --- /dev/null +++ b/test/tests/activate/beginning-of-defun @@ -0,0 +1,13 @@ +C-M-a +;;;; + +(defun objed--save-start-position (&rest _) + "Save position of| point via `objed--opoint'." + (setq objed--opoint (point))) + +;;;; +< +|(defun objed--save-start-position (&rest _) + "Save position of point via `objed--opoint'." + (setq objed--opoint (point))) +> diff --git a/test/tests/activate/beginning-of-line b/test/tests/activate/beginning-of-line new file mode 100644 index 0000000..e0962b0 --- /dev/null +++ b/test/tests/activate/beginning-of-line @@ -0,0 +1,6 @@ +C-a +;;;; +Testing line he|re +;;;; +|<Testing line here +> \ No newline at end of file diff --git a/test/tests/activate/forward-word b/test/tests/activate/forward-word new file mode 100644 index 0000000..37f9586 --- /dev/null +++ b/test/tests/activate/forward-word @@ -0,0 +1,5 @@ +M-f +;;;; +Testing line he|re +;;;; +Testing line <here>| diff --git a/test/tests/activate/next-line b/test/tests/activate/next-line new file mode 100644 index 0000000..fa17c33 --- /dev/null +++ b/test/tests/activate/next-line @@ -0,0 +1,8 @@ +C-n +;;;; +Testing line he|re +Following line here +;;;; +Testing line here +<Following line |here +> \ No newline at end of file