[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."
- [elpa] master ba4e5c1 01/51: * yasnippet-debug.el (yas-debug-snippet): Handle non-numbered fields., (continued)
- [elpa] master ba4e5c1 01/51: * yasnippet-debug.el (yas-debug-snippet): Handle non-numbered fields., Noam Postavsky, 2018/05/13
- [elpa] master 1fc3426 02/51: Add test relying on overlay hook inhibition in `yas-expand-snippet', Noam Postavsky, 2018/05/13
- [elpa] master ece7935 07/51: * yasnippet.el (yas--message): Fix invalid docstring reference., Noam Postavsky, 2018/05/13
- [elpa] master 4ab9cb5 04/51: Set test to fail with newer org version, Noam Postavsky, 2018/05/13
- [elpa] master 0b8d434 05/51: Unset autoload-compute-prefixes for utility files, Noam Postavsky, 2018/05/13
- [elpa] master acec3ba 06/51: * doc/faq.org: Fix typo., Noam Postavsky, 2018/05/13
- [elpa] master ee81da9 11/51: Allow "# --" end-of-header marker to have trailing space, Noam Postavsky, 2018/05/13
- [elpa] master b1ca219 12/51: Remove submodules (snippet and yasmate), Noam Postavsky, 2018/05/13
- [elpa] master 35a4df7 03/51: Let whitespace-global-mode work in new snippet buffers, Noam Postavsky, 2018/05/13
- [elpa] master d806b04 15/51: * yasnippet.el (snippet-mode): Derive from prog-mode., Noam Postavsky, 2018/05/13
- [elpa] master 1292cd2 10/51: Refactor undo tests,
Noam Postavsky <=
- [elpa] master 203059a 17/51: * yasnippet.el (yas-key-syntaxes): Prefer the longest key., Noam Postavsky, 2018/05/13
- [elpa] master 7ea1305 09/51: Fix undo when first line indentation moves snippet forward, Noam Postavsky, 2018/05/13
- [elpa] master 6ffd1c7 22/51: ; .travis.yml: Test with 25.3 and 26 prelease., Noam Postavsky, 2018/05/13
- [elpa] master 2e69471 24/51: ; yasnippet-debug.el: macroexp-progn is not avaiable in Emacs 23., Noam Postavsky, 2018/05/13
- [elpa] master 3d7cafc 34/51: Make yas-snippet-mode-buffer-p robust against symlinks, Noam Postavsky, 2018/05/13
- [elpa] master ba73f20 27/51: Bind field skip and clear command conditionally, Noam Postavsky, 2018/05/13
- [elpa] master ce11fd6 13/51: * yasnippet.el (yas-reload-all): Mention if no snippets were found., Noam Postavsky, 2018/05/13
- [elpa] master e200a3b 08/51: Let snippet insertion trigger active field clearing., Noam Postavsky, 2018/05/13
- [elpa] master 04062d8 14/51: Don't set yas-selected-text to non-selected text, Noam Postavsky, 2018/05/13
- [elpa] master ad3a4d1 16/51: Don't use prog-mode in older Emacs, Noam Postavsky, 2018/05/13