mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
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.
This commit is contained in:
parent
7ea1305e67
commit
1292cd263a
@ -297,77 +297,51 @@ attention to case differences."
|
|||||||
;; (should (string= (yas--buffer-contents)
|
;; (should (string= (yas--buffer-contents)
|
||||||
;; "brother from another mother!"))))
|
;; "brother from another mother!"))))
|
||||||
|
|
||||||
(ert-deftest undo-indentation-1 ()
|
(defun yas-test-expand-and-undo (mode snippet-entry initial-contents)
|
||||||
"Check undoing works when only line of snippet is indented."
|
(yas-with-snippet-dirs
|
||||||
(let ((yas-also-auto-indent-first-line t))
|
`((".emacs.d/snippets" (,(symbol-name mode) ,snippet-entry)))
|
||||||
(yas-with-snippet-dirs
|
(with-temp-buffer
|
||||||
'((".emacs.d/snippets" ("emacs-lisp-mode" ("s" . "(setq $0)"))))
|
(funcall mode)
|
||||||
(with-temp-buffer
|
(yas-reload-all)
|
||||||
(emacs-lisp-mode)
|
(yas-minor-mode 1)
|
||||||
(yas-reload-all)
|
(yas-expand-snippet initial-contents)
|
||||||
(yas-minor-mode 1)
|
(let ((pre-expand-string (buffer-string)))
|
||||||
(insert "(let\n(while s")
|
|
||||||
(setq buffer-undo-list ())
|
(setq buffer-undo-list ())
|
||||||
(ert-simulate-command '(yas-expand))
|
(ert-simulate-command '(yas-expand))
|
||||||
;; Need undo barrier, I think command loop puts it normally.
|
;; Need undo barrier, I think command loop puts it normally.
|
||||||
(push nil buffer-undo-list)
|
(push nil buffer-undo-list)
|
||||||
(should (string= (buffer-string) "(let\n (while (setq )"))
|
|
||||||
(ert-simulate-command '(undo))
|
(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 ()
|
(ert-deftest undo-indentation-2 ()
|
||||||
"Check undoing works when only line of snippet is indented."
|
"Check undoing works when only line of snippet is indented."
|
||||||
(let ((yas-also-auto-indent-first-line t)
|
(let ((yas-also-auto-indent-first-line t)
|
||||||
(indent-tabs-mode nil))
|
(indent-tabs-mode nil))
|
||||||
(yas-with-snippet-dirs
|
(yas-test-expand-and-undo
|
||||||
'((".emacs.d/snippets" ("emacs-lisp-mode" ("t" . "; TODO"))))
|
'emacs-lisp-mode '("t" . "; TODO") "t$0")))
|
||||||
(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"))))))
|
|
||||||
|
|
||||||
(ert-deftest undo-indentation-multiline-1 ()
|
(ert-deftest undo-indentation-multiline-1 ()
|
||||||
"Check undoing works when 1st line of multi-line snippet is indented."
|
"Check undoing works when 1st line of multi-line snippet is indented."
|
||||||
(yas-with-snippet-dirs
|
(let ((yas-also-auto-indent-first-line t)
|
||||||
'((".emacs.d/snippets" ("js-mode" ("if" . "if ($1) {\n\n}\n"))))
|
(indent-tabs-mode nil))
|
||||||
(with-temp-buffer
|
(yas-test-expand-and-undo
|
||||||
(js-mode)
|
'js-mode '("if" . "if ($1) {\n\n}\n")
|
||||||
(yas-reload-all)
|
"if$0\nabc = 123456789 + abcdef;")))
|
||||||
(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;")))))
|
|
||||||
|
|
||||||
|
|
||||||
(ert-deftest undo-indentation-multiline-2 ()
|
(ert-deftest undo-indentation-multiline-2 ()
|
||||||
"Check undoing works when 2nd line of multi-line snippet is indented."
|
"Check undoing works when 2nd line of multi-line snippet is indented."
|
||||||
(yas-with-snippet-dirs
|
(let ((yas-also-auto-indent-first-line t)
|
||||||
'((".emacs.d/snippets" ("js-mode" ("if" . "if (true) {\n${1:foo};\n}\n"))))
|
(indent-tabs-mode nil))
|
||||||
(with-temp-buffer
|
(yas-test-expand-and-undo
|
||||||
(js-mode)
|
'js-mode '("if" . "if (true) {\n${1:foo};\n}\n")
|
||||||
(yas-reload-all)
|
"if$0\nabc = 123456789 + abcdef;")))
|
||||||
(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;")))))
|
|
||||||
|
|
||||||
(ert-deftest dont-clear-on-partial-deletion-issue-515 ()
|
(ert-deftest dont-clear-on-partial-deletion-issue-515 ()
|
||||||
"Ensure fields are not cleared when user doesn't really mean to."
|
"Ensure fields are not cleared when user doesn't really mean to."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user