"brother from another mother") ;; no newline should be here!\r
)))\r
\r
+;;; Loading\r
+;;;\r
+(ert-deftest basic-loading ()\r
+ "Test basic loading and expansion of snippets"\r
+ (yas/saving-variables\r
+ (with-snippet-dirs\r
+ '((".emacs.d/snippets"\r
+ ("c-mode"\r
+ (".yas-parents" . "cc-mode")\r
+ ("printf" . "printf($1);"))\r
+ ("emacs-lisp-mode" ("ert-deftest" . "(ert-deftest ${1:name} () $0)"))\r
+ ("lisp-interaction-mode" (".yas-parents" . "emacs-lisp-mode")))\r
+ ("library/snippets"\r
+ ("c-mode" (".yas-parents" . "c++-mode"))\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
+ (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
+\r
+\r
+\r
;;; Helpers\r
;;; \r
\r
((= i (length string)))\r
(insert (aref string i))))\r
\r
+(defun yas/make-file-or-dirs (ass)\r
+ (let ((file-or-dir-name (car ass))\r
+ (content (cdr ass)))\r
+ (cond ((listp content)\r
+ (make-directory file-or-dir-name 'parents)\r
+ (let ((default-directory (concat default-directory "/" file-or-dir-name)))\r
+ (mapc #'yas/make-file-or-dirs content)))\r
+ ((stringp content)\r
+ (with-current-buffer (find-file file-or-dir-name)\r
+ (insert content)\r
+ (save-buffer)\r
+ (kill-buffer)))\r
+ (t\r
+ (message "[yas] oops don't know this content")))))\r
+\r
+\r
+(defun yas/variables ()\r
+ (let ((syms))\r
+ (mapatoms #'(lambda (sym)\r
+ (if (and (string-match "^yas/[^/]" (symbol-name sym))\r
+ (boundp sym))\r
+ (push sym syms))))\r
+ syms))\r
+\r
+\r
+(defmacro yas/saving-variables (&rest body)\r
+ `(let ,(mapcar #'(lambda (sym)\r
+ `(,sym ,sym))\r
+ (yas/variables))\r
+ ,@body))\r
+\r
+(defmacro with-snippet-dirs (dirs &rest body)\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
+\r
\r
(provide 'yasnippet-tests)\r
;;; yasnippet-tests.el ends here\r