mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
Richer tests
This commit is contained in:
parent
ce85cffcfc
commit
59e18a999e
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; Attempt to test basic snippet mechanics and the loading system
|
;; Test basic snippet mechanics and the loading system
|
||||||
|
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
@ -29,6 +29,7 @@
|
|||||||
(require 'ert-x)
|
(require 'ert-x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Snippet mechanics
|
;;; Snippet mechanics
|
||||||
|
|
||||||
(ert-deftest field-navigation ()
|
(ert-deftest field-navigation ()
|
||||||
@ -126,20 +127,45 @@ TODO: correct this bug!"
|
|||||||
("cc-mode" ("def" . "# define"))
|
("cc-mode" ("def" . "# define"))
|
||||||
("emacs-lisp-mode" ("dolist" . "(dolist)"))
|
("emacs-lisp-mode" ("dolist" . "(dolist)"))
|
||||||
("lisp-interaction-mode" ("sc" . "brother from another mother"))))
|
("lisp-interaction-mode" ("sc" . "brother from another mother"))))
|
||||||
(yas/reload-all)
|
(yas/reload-all 'with-jit)
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(lisp-interaction-mode)
|
(should (= 4 (hash-table-count yas/scheduled-jit-loads)))
|
||||||
(yas/minor-mode 1)
|
(should (= 0 (hash-table-count yas/tables)))
|
||||||
(insert "sc")
|
(lisp-interaction-mode) (yas/minor-mode 1) ;; either one will load two tables depending on yas/global-mode (FIXME)
|
||||||
(ert-simulate-command '(yas/expand))
|
(should (= 2 (hash-table-count yas/scheduled-jit-loads)))
|
||||||
(should (string= (buffer-substring-no-properties (point-min) (point-max))
|
(should (= 2 (hash-table-count yas/tables)))
|
||||||
"brother from another mother"))))))
|
(should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))
|
||||||
|
(should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))
|
||||||
|
(yas/should-expand '(("sc" . "brother from another mother")
|
||||||
|
("dolist" . "(dolist)")
|
||||||
|
("ert-deftest" . "(ert-deftest name () )")))
|
||||||
|
(c-mode)
|
||||||
|
(yas/should-expand '(("printf" . "printf();")
|
||||||
|
("def" . "# define")))
|
||||||
|
(yas/should-not-expand '("sc" "dolist" "ert-deftest"))))))
|
||||||
|
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
|
(defun yas/should-expand (keys-and-expansions)
|
||||||
|
(dolist (key-and-expansion keys-and-expansions)
|
||||||
|
(yas/exit-all-snippets)
|
||||||
|
(erase-buffer)
|
||||||
|
(insert (car key-and-expansion))
|
||||||
|
(let ((yas/fallback-behavior nil))
|
||||||
|
(ert-simulate-command '(yas/expand)))
|
||||||
|
(should (string= (buffer-substring-no-properties (point-min) (point-max))
|
||||||
|
(cdr key-and-expansion)))))
|
||||||
|
|
||||||
|
(defun yas/should-not-expand (keys)
|
||||||
|
(dolist (key keys)
|
||||||
|
(yas/exit-all-snippets)
|
||||||
|
(erase-buffer)
|
||||||
|
(insert key)
|
||||||
|
(let ((yas/fallback-behavior nil))
|
||||||
|
(ert-simulate-command '(yas/expand)))
|
||||||
|
(should (string= (buffer-substring-no-properties (point-min) (point-max)) key))))
|
||||||
|
|
||||||
(defun yas/mock-insert (string)
|
(defun yas/mock-insert (string)
|
||||||
(interactive)
|
(interactive)
|
||||||
(do ((i 0 (1+ i)))
|
(do ((i 0 (1+ i)))
|
||||||
@ -157,7 +183,7 @@ TODO: correct this bug!"
|
|||||||
(with-current-buffer (find-file file-or-dir-name)
|
(with-current-buffer (find-file file-or-dir-name)
|
||||||
(insert content)
|
(insert content)
|
||||||
(save-buffer)
|
(save-buffer)
|
||||||
(kill-buffer)))
|
(kill-buffer (current-buffer))))
|
||||||
(t
|
(t
|
||||||
(message "[yas] oops don't know this content")))))
|
(message "[yas] oops don't know this content")))))
|
||||||
|
|
||||||
@ -181,8 +207,19 @@ TODO: correct this bug!"
|
|||||||
`(let ((default-directory (make-temp-file "yasnippet-fixture" t)))
|
`(let ((default-directory (make-temp-file "yasnippet-fixture" t)))
|
||||||
(setq yas/snippet-dirs ',(mapcar #'car (cadr dirs)))
|
(setq yas/snippet-dirs ',(mapcar #'car (cadr dirs)))
|
||||||
(mapc #'yas/make-file-or-dirs ,dirs)
|
(mapc #'yas/make-file-or-dirs ,dirs)
|
||||||
,@body))
|
,@body
|
||||||
|
(when (>= emacs-major-version 23)
|
||||||
|
(delete-directory default-directory 'recursive))))
|
||||||
|
|
||||||
|
;;; Older emacsen
|
||||||
|
;;;
|
||||||
|
(unless (fboundp 'special-mode)
|
||||||
|
(define-minor-mode special-mode "Just a placeholder for something isn't in emacs 22"))
|
||||||
|
|
||||||
|
;;; btw to test this in emacs22 mac osx:
|
||||||
|
;;; curl -L -O https://github.com/mirrors/emacs/raw/master/lisp/emacs-lisp/ert.el
|
||||||
|
;;; curl -L -O https://github.com/mirrors/emacs/raw/master/lisp/emacs-lisp/ert-x.el
|
||||||
|
;;; /usr/bin/emacs -nw -Q -L . -l yasnippet-tests.el --batch -e ert
|
||||||
|
|
||||||
(provide 'yasnippet-tests)
|
(provide 'yasnippet-tests)
|
||||||
;;; yasnippet-tests.el ends here
|
;;; yasnippet-tests.el ends here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user