emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 1292cd2 10/51: Refactor undo tests


From: Noam Postavsky
Subject: [elpa] master 1292cd2 10/51: Refactor undo tests
Date: Sun, 13 May 2018 13:11:40 -0400 (EDT)

branch: master
commit 1292cd263a63213ebcf65a3200ebcca16fe8bc36
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Refactor undo tests
    
    * yasnippet-tests.el (yas-test-expand-and-undo): New helper function.
    (undo-indentation-1, undo-indentation-2, undo-indentation-multiline-1)
    (undo-indentation-multiline-2): Use it.
---
 yasnippet-tests.el | 82 +++++++++++++++++++-----------------------------------
 1 file changed, 28 insertions(+), 54 deletions(-)

diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 13fff53..4101454 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -297,77 +297,51 @@ attention to case differences."
 ;;     (should (string= (yas--buffer-contents)
 ;;                      "brother from another mother!"))))
 
-(ert-deftest undo-indentation-1 ()
-  "Check undoing works when only line of snippet is indented."
-  (let ((yas-also-auto-indent-first-line t))
-    (yas-with-snippet-dirs
-     '((".emacs.d/snippets" ("emacs-lisp-mode" ("s" . "(setq $0)"))))
-     (with-temp-buffer
-       (emacs-lisp-mode)
-       (yas-reload-all)
-       (yas-minor-mode 1)
-       (insert "(let\n(while s")
+(defun yas-test-expand-and-undo (mode snippet-entry initial-contents)
+  (yas-with-snippet-dirs
+   `((".emacs.d/snippets" (,(symbol-name mode) ,snippet-entry)))
+   (with-temp-buffer
+     (funcall mode)
+     (yas-reload-all)
+     (yas-minor-mode 1)
+     (yas-expand-snippet initial-contents)
+     (let ((pre-expand-string (buffer-string)))
        (setq buffer-undo-list ())
        (ert-simulate-command '(yas-expand))
        ;; Need undo barrier, I think command loop puts it normally.
        (push nil buffer-undo-list)
-       (should (string= (buffer-string) "(let\n    (while (setq )"))
        (ert-simulate-command '(undo))
-       (should (string= (buffer-string) "(let\n(while s"))))))
+       (should (string= (buffer-string) pre-expand-string))))))
+
+(ert-deftest undo-indentation-1 ()
+  "Check undoing works when only line of snippet is indented."
+  (let ((yas-also-auto-indent-first-line t))
+    (yas-test-expand-and-undo
+     'emacs-lisp-mode '("s" . "(setq $0)") "(let\n(while s$0")))
 
 (ert-deftest undo-indentation-2 ()
   "Check undoing works when only line of snippet is indented."
   (let ((yas-also-auto-indent-first-line t)
         (indent-tabs-mode nil))
-    (yas-with-snippet-dirs
-     '((".emacs.d/snippets" ("emacs-lisp-mode" ("t" . "; TODO"))))
-     (with-temp-buffer
-       (emacs-lisp-mode)
-       (yas-reload-all)
-       (yas-minor-mode 1)
-       (insert "t")
-       (setq buffer-undo-list ())
-       (ert-simulate-command '(yas-expand))
-       ;; Need undo barrier, I think command loop puts it normally.
-       (push nil buffer-undo-list)
-       (should (string= (buffer-string) (concat (make-string comment-column 
?\s) "; TODO")))
-       (ert-simulate-command '(undo))
-       (should (string= (buffer-string) "t"))))))
+    (yas-test-expand-and-undo
+     'emacs-lisp-mode '("t" . "; TODO") "t$0")))
 
 (ert-deftest undo-indentation-multiline-1 ()
   "Check undoing works when 1st line of multi-line snippet is indented."
-  (yas-with-snippet-dirs
-    '((".emacs.d/snippets" ("js-mode" ("if" . "if ($1) {\n\n}\n"))))
-    (with-temp-buffer
-      (js-mode)
-      (yas-reload-all)
-      (yas-minor-mode 1)
-      (insert "if\nabc = 123456789 + abcdef;")
-      (setq buffer-undo-list ())
-      (goto-char (point-min))
-      (search-forward "if")
-      (ert-simulate-command '(yas-expand))
-      (push nil buffer-undo-list)       ; See test above.
-      (ert-simulate-command '(undo))
-      (should (string= (buffer-string) "if\nabc = 123456789 + abcdef;")))))
+  (let ((yas-also-auto-indent-first-line t)
+        (indent-tabs-mode nil))
+    (yas-test-expand-and-undo
+     'js-mode '("if" . "if ($1) {\n\n}\n")
+     "if$0\nabc = 123456789 + abcdef;")))
 
 
 (ert-deftest undo-indentation-multiline-2 ()
   "Check undoing works when 2nd line of multi-line snippet is indented."
-  (yas-with-snippet-dirs
-    '((".emacs.d/snippets" ("js-mode" ("if" . "if (true) {\n${1:foo};\n}\n"))))
-    (with-temp-buffer
-      (js-mode)
-      (yas-reload-all)
-      (yas-minor-mode 1)
-      (insert "if\nabc = 123456789 + abcdef;")
-      (setq buffer-undo-list ())
-      (goto-char (point-min))
-      (search-forward "if")
-      (ert-simulate-command '(yas-expand))
-      (push nil buffer-undo-list)       ; See test above.
-      (ert-simulate-command '(undo))
-      (should (string= (buffer-string) "if\nabc = 123456789 + abcdef;")))))
+  (let ((yas-also-auto-indent-first-line t)
+        (indent-tabs-mode nil))
+    (yas-test-expand-and-undo
+     'js-mode '("if" . "if (true) {\n${1:foo};\n}\n")
+     "if$0\nabc = 123456789 + abcdef;")))
 
 (ert-deftest dont-clear-on-partial-deletion-issue-515 ()
   "Ensure fields are not cleared when user doesn't really mean to."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]