\r
;;; Commentary:\r
\r
-;; Attempt to test basic snippet mechanics and the loading system \r
+;; Test basic snippet mechanics and the loading system \r
\r
;;; Code:\r
\r
(require 'ert-x)\r
\r
\r
+\r
;;; Snippet mechanics\r
\r
(ert-deftest field-navigation ()\r
("cc-mode" ("def" . "# define"))\r
("emacs-lisp-mode" ("dolist" . "(dolist)"))\r
("lisp-interaction-mode" ("sc" . "brother from another mother"))))\r
- (yas/reload-all)\r
+ (yas/reload-all 'with-jit)\r
(with-temp-buffer\r
- (lisp-interaction-mode)\r
- (yas/minor-mode 1)\r
- (insert "sc")\r
- (ert-simulate-command '(yas/expand))\r
- (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
- "brother from another mother"))))))\r
+ (should (= 4 (hash-table-count yas/scheduled-jit-loads)))\r
+ (should (= 0 (hash-table-count yas/tables)))\r
+ (lisp-interaction-mode) (yas/minor-mode 1) ;; either one will load two tables depending on yas/global-mode (FIXME)\r
+ (should (= 2 (hash-table-count yas/scheduled-jit-loads)))\r
+ (should (= 2 (hash-table-count yas/tables)))\r
+ (should (= 1 (hash-table-count (yas/table-uuidhash (gethash 'lisp-interaction-mode yas/tables)))))\r
+ (should (= 2 (hash-table-count (yas/table-uuidhash (gethash 'emacs-lisp-mode yas/tables)))))\r
+ (yas/should-expand '(("sc" . "brother from another mother")\r
+ ("dolist" . "(dolist)")\r
+ ("ert-deftest" . "(ert-deftest name () )")))\r
+ (c-mode)\r
+ (yas/should-expand '(("printf" . "printf();")\r
+ ("def" . "# define")))\r
+ (yas/should-not-expand '("sc" "dolist" "ert-deftest"))))))\r
\r
+;;; Helpers\r
+;;;\r
\r
+(defun yas/should-expand (keys-and-expansions)\r
+ (dolist (key-and-expansion keys-and-expansions)\r
+ (yas/exit-all-snippets)\r
+ (erase-buffer)\r
+ (insert (car key-and-expansion))\r
+ (let ((yas/fallback-behavior nil))\r
+ (ert-simulate-command '(yas/expand)))\r
+ (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+ (cdr key-and-expansion)))))\r
\r
-;;; Helpers\r
-;;; \r
+(defun yas/should-not-expand (keys)\r
+ (dolist (key keys)\r
+ (yas/exit-all-snippets)\r
+ (erase-buffer)\r
+ (insert key)\r
+ (let ((yas/fallback-behavior nil))\r
+ (ert-simulate-command '(yas/expand)))\r
+ (should (string= (buffer-substring-no-properties (point-min) (point-max)) key))))\r
\r
(defun yas/mock-insert (string)\r
(interactive)\r
(with-current-buffer (find-file file-or-dir-name)\r
(insert content)\r
(save-buffer)\r
- (kill-buffer)))\r
+ (kill-buffer (current-buffer))))\r
(t\r
(message "[yas] oops don't know this content")))))\r
\r
`(let ((default-directory (make-temp-file "yasnippet-fixture" t)))\r
(setq yas/snippet-dirs ',(mapcar #'car (cadr dirs)))\r
(mapc #'yas/make-file-or-dirs ,dirs)\r
- ,@body))\r
+ ,@body\r
+ (when (>= emacs-major-version 23)\r
+ (delete-directory default-directory 'recursive))))\r
+\r
+;;; Older emacsen\r
+;;;\r
+(unless (fboundp 'special-mode)\r
+ (define-minor-mode special-mode "Just a placeholder for something isn't in emacs 22"))\r
\r
+;;; btw to test this in emacs22 mac osx:\r
+;;; curl -L -O https://github.com/mirrors/emacs/raw/master/lisp/emacs-lisp/ert.el\r
+;;; curl -L -O https://github.com/mirrors/emacs/raw/master/lisp/emacs-lisp/ert-x.el\r
+;;; /usr/bin/emacs -nw -Q -L . -l yasnippet-tests.el --batch -e ert\r
\r
(provide 'yasnippet-tests)\r
;;; yasnippet-tests.el ends here\r