[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/objed b54fa1a 077/216: Add more tests
From: |
Stefan Monnier |
Subject: |
[elpa] externals/objed b54fa1a 077/216: Add more tests |
Date: |
Tue, 8 Jan 2019 12:29:15 -0500 (EST) |
branch: externals/objed
commit b54fa1aa74aecc7b762daf0932cd8c3b02369cb7
Author: Clemera <address@hidden>
Commit: Clemera <address@hidden>
Add more tests
---
Makefile | 6 +--
test/tests.el | 165 ++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 122 insertions(+), 49 deletions(-)
diff --git a/Makefile b/Makefile
index 9cbb963..4ba2ad7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,11 +1,11 @@
update:
- emacs -batch -l test/make-update.el
+ emacs -Q -batch -l test/make-update.el
compile: clean
- emacs -batch -l test/elpa.el -l test/make-compile.el
+ emacs -Q -batch -l test/elpa.el -l test/make-compile.el
test:
- emacs -batch -l test/elpa.el -l test/make-test.el
+ emacs -Q -batch -l test/elpa.el -l test/make-test.el
clean:
rm -f *.elc
diff --git a/test/tests.el b/test/tests.el
index 9d55f1d..a81f047 100644
--- a/test/tests.el
+++ b/test/tests.el
@@ -1,11 +1,8 @@
(require 'ert)
-(require 'objed)
-(require 'objed-objects)
(require 'cl-lib)
+(require 'objed)
-
-;; from `lispy-with'
-
+;; adapted from lispy-test.el
(defun objed-decode-keysequence (str)
"Decode STR from e.g. \"23ab5c\" to '(23 \"a\" \"b\" 5 \"c\")"
@@ -29,32 +26,37 @@
(if (vectorp seq)
(objed--unalias-key seq)
(let ((lkeys (objed-decode-keysequence seq))
- key)
+ (map nil)
+ (key nil))
(while (setq key (pop lkeys))
(if (numberp key)
(let ((current-prefix-arg (list key)))
(when lkeys
(objed--unalias-key (pop lkeys))))
- (objed--unalias-key key))))))
+ (let ((cmd (key-binding key)))
+ (if (keymapp cmd)
+ (setq map cmd)
+ (objed--unalias-key key map)
+ (setq map nil))))))))
-(defun objed--unalias-key (key)
+(defun objed--unalias-key (key &optional map)
"Call command that corresponds to KEY.
Insert KEY if there's no command."
- (let ((cmd (key-binding key)))
+ (let ((cmd (if map (lookup-key map key)
+ (key-binding key))))
(if (not cmd)
(insert key)
(setq last-command-event (aref key 0))
- (call-interactively cmd)
- (setq last-command cmd))))
-
+ (objed--call-object-interactively nil cmd))))
-(ert-deftest objed-decode-keysequence ()
- (should (equal (objed-decode-keysequence "23ab50c")
- '(23 "a" "b" 50 "c")))
- (should (equal (objed-decode-keysequence "3\C-d")
- '(3 "")))
- (should (equal (objed-decode-keysequence "3\C-?")
- '(3 ""))))
+;;
+;; (ert-deftest objed-decode-keysequence ()
+;; (should (equal (objed-decode-keysequence "23ab50c")
+;; '(23 "a" "b" 50 "c")))
+;; (should (equal (objed-decode-keysequence "3\C-d")
+;; '(3 "")))
+;; (should (equal (objed-decode-keysequence "3\C-?")
+;; '(3 ""))))
;; adapated from `lispy-with'
(defmacro objed-with (in &rest body)
@@ -76,7 +78,7 @@ Insert KEY if there's no command."
(goto-char (point-max))
(search-backward "|")
(delete-char 1)
- (objed--init 'char)
+ ;; (objed--init 'char)
(setq current-prefix-arg nil)
;; execute command
,@(mapcar (lambda (x)
@@ -108,35 +110,106 @@ Insert KEY if there's no command."
(and (buffer-name temp-buffer)
(kill-buffer temp-buffer))))))
+(defun objed--call-object-interactively (o &optional cmd)
+ (let* ((cmd (or cmd (objed--name2func o)))
+ (real-this-command cmd)
+ (inhibit-message t))
+ (setq this-command cmd)
+ (call-interactively cmd)
+ (setq last-command cmd)))
+
+;; 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)))
+>")))
-(ert-deftest objed-next-line ()
- (should (string= (objed-with ";; this is a| test\n;; this is the next line"
"n")
- ";; this is a test\n<;; this is t|he next line>")))
-
-(ert-deftest objed-previous-line ()
- (should (string= (objed-with ";; this is the previous line\n;; this is| the
current line" "p")
- "<;; this is| the previous line\n>;; this is the current
line")))
-
-(ert-deftest objed-forward-char ()
- (should (string= (objed-with "Tes|ting line" "fff")
- "Testin|<g> line")))
-
-(ert-deftest objed-backward-char ()
- (should (string= (objed-with "Tes|ting line" "bb")
- "T|<e>sting line")))
-
-(ert-deftest objed-forward-word ()
- (should (string= (objed-with "Tes|ting line here" "ss")
- "Testing <line>| here")))
-
-
-(ert-deftest objed-backward-word ()
- (should (string= (objed-with "Testing line he|re" "rr")
- "Testing |<line> here")))
(ert-deftest objed-basic-movment ()
- (should (string= (objed-with "Testing |line here\nFollowing line here"
"npsrfb")
- "Testing |<l>ine here\nFollowing line here")))
+ (should (string= (objed-with "Testing line he|re" "rr")
+ "Testing |<line> here"))
+ (should (string= (objed-with "Testing line he|re" "2r")
+ "Testing |<line> here"))
+ (should (string= (objed-with "Tes|ting line here" "ss")
+ "Testing <line>| here"))
+ (should (string= (objed-with "Tes|ting line here" "2s")
+ "Testing <line>| here"))
+ (should (string= (objed-with "Tes|ting line" "bb")
+ "T|<e>sting line"))
+ (should (string= (objed-with "Tes|ting line" "2b")
+ "T|<e>sting line"))
+ (should (string= (objed-with "Tes|ting line" "fff")
+ "Testin|<g> line"))
+ (should (string= (objed-with "Tes|ting line" "3f")
+ "Testin|<g> line"))
+ (should (string= (objed-with ";; this is the previous line\n;; this is| the
current line" "p")
+ "<;; this is| the previous line\n>;; this is the current
line"))
+ (should (string= (objed-with ";; this is a| test\n;; this is the next line"
"n")
+ ";; this is a test\n<;; this is t|he next line>"))
+ (should (string= (objed-with "Testing |line here\nFollowing line here"
"npsrfb")
+ "Testing |<l>ine here\nFollowing line here"))
+ (should (string= (objed-with "Testing |line here\nFollowing line here" "e")
+ "Testing <line here>|\nFollowing line here"))
+ (should (string= (objed-with "Testing |line here\nFollowing line here" "a")
+ "|<Testing >line here\nFollowing line here"))
+ (should (string= (objed-with "Testing |line here\nFollowing line here" "ae")
+ "<Testing line here>|\nFollowing line here")))
+
+
+(ert-deftest objed-switch-to-object ()
+ (should (string= (objed-with "
+(defun objed--save-start-position (&rest _)
+ \"Save position of point via `objed--opoint'.\"
+ (setq objed--opoint (point)))
+
+(defun objed--|goto-start (&optional _)
+ \"Goto start of current object if there is one.\"
+ (when objed--current-obj
+ (goto-char (objed--beg))))
+
+(defun objed--object-trailing-line (pos)
+ \"Activate trailing part from POS.\"
+ (unless (eq objed--obj-state 'inner)
+ (objed--reverse))
+ (objed--change-to :beg pos :ibeg pos))"
+ "cdd")
+"
+(defun objed--save-start-position (&rest _)
+ \"Save position of point via `objed--opoint'.\"
+ (setq objed--opoint (point)))
+|<
+>(defun objed--object-trailing-line (pos)
+ \"Activate trailing part from POS.\"
+ (unless (eq objed--obj-state 'inner)
+ (objed--reverse))
+ (objed--change-to :beg pos :ibeg pos))")))
+
+(ert-deftest objed-delete-op ()
+ (should (string= (objed-with "
+(defun |objed--save-start-position (&rest _)
+ \"Save position of point via `objed--opoint'.\"
+ (setq objed--opoint (point)))"
+ "nd")
+"
+(defun objed--save-start-position (&rest _)
+|< (setq objed--opoint (point)))>")))
(provide 'tests)
- [elpa] externals/objed 8764254 081/216: Add note about tests to contribute, (continued)
- [elpa] externals/objed 8764254 081/216: Add note about tests to contribute, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 3eb73e0 060/216: Adjust indent op and tab commands, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 5fbacd4 050/216: Cleanup, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 5f23c05 070/216: Fixup advice code, Stefan Monnier, 2019/01/08
- [elpa] externals/objed bd6a50c 092/216: Change bindings for surroundings, undo in region, Stefan Monnier, 2019/01/08
- [elpa] externals/objed aa8ba7b 093/216: Change DEL to behave as normal for char object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 21ca995 069/216: Cleanup malformed object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed d21fd72 073/216: Fix makup again, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 7c41d13 076/216: Fixup which-key paging commands, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 204ea88 095/216: Change surroundings binding, Stefan Monnier, 2019/01/08
- [elpa] externals/objed b54fa1a 077/216: Add more tests,
Stefan Monnier <=
- [elpa] externals/objed deb059e 100/216: Update bindings, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 53cafee 085/216: Add new commands to move to first/last instance, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 919a72d 071/216: Adjust python block object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed b7ded6d 083/216: Improve tests, add more tests, Stefan Monnier, 2019/01/08
- [elpa] externals/objed e5f8bac 102/216: Improve undo in region, Stefan Monnier, 2019/01/08
- [elpa] externals/objed e5dfba1 096/216: Add extend commands, Stefan Monnier, 2019/01/08
- [elpa] externals/objed d770ddd 055/216: Don't exit after eval op, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 6907e69 058/216: Improve face object, Stefan Monnier, 2019/01/08
- [elpa] externals/objed cac61c3 084/216: Improve block objects, Stefan Monnier, 2019/01/08
- [elpa] externals/objed 58af659 068/216: Start adding tests, Stefan Monnier, 2019/01/08