("lisp-interaction-mode" ("sc" . "brother from another mother"))))
,@body))))
+(ert-deftest snippet-lookup ()
+ "Test `yas-lookup-snippet'."
+ (yas-with-some-interesting-snippet-dirs
+ (yas-reload-all 'no-jit)
+ (should (equal (yas-lookup-snippet "printf" 'c-mode) "printf($1);"))
+ (should (equal (yas-lookup-snippet "def" 'c-mode) "# define"))
+ (should-not (yas-lookup-snippet "no such snippet" nil 'noerror))
+ (should-not (yas-lookup-snippet "printf" 'emacs-lisp-mode 'noerror))))
(ert-deftest basic-jit-loading ()
"Test basic loading and expansion of snippets"
(yas--basic-jit-loading-1)))
(ert-deftest basic-jit-loading-with-compiled-snippets ()
- "Test basic loading and expansion of snippets"
+ "Test basic loading and expansion of compiled snippets"
(yas-with-some-interesting-snippet-dirs
(yas-reload-all)
(yas-recompile-all)
(yas-reload-all)
(yas--basic-jit-loading-1))))
+(ert-deftest visiting-compiled-snippets ()
+ "Test snippet visiting for compiled snippets."
+ (yas-with-some-interesting-snippet-dirs
+ (yas-recompile-all)
+ (yas-reload-all 'no-jit) ; must be loaded for `yas-lookup-snippet' to work.
+ (yas--with-temporary-redefinitions ((find-file-noselect
+ (filename &rest _)
+ (throw 'yas-snippet-file filename)))
+ (should (string-suffix-p
+ "cc-mode/def"
+ (catch 'yas-snippet-file
+ (yas--visit-snippet-file-1
+ (yas--lookup-snippet-1 "def" 'cc-mode))))))))
+
(ert-deftest loading-with-cyclic-parenthood ()
"Test loading when cyclic parenthood is setup."
(yas-saving-variables
yet-another-c-mode
and-also-this-one
and-that-one
- ;; prog-mode doesn't exit in emacs 24.3
+ ;; prog-mode doesn't exist in emacs 24.3
+ ,@(if (fboundp 'prog-mode)
+ '(prog-mode))
+ emacs-lisp-mode
+ lisp-interaction-mode))
+ (observed (yas--modes-to-activate)))
+ (should (equal (sort expected #'string<) (sort observed #'string<))))))))
+
+(ert-deftest extra-modes-parenthood ()
+ "Test activation of parents of `yas--extra-modes'."
+ (yas-saving-variables
+ (yas-with-snippet-dirs '((".emacs.d/snippets"
+ ("c-mode"
+ (".yas-parents" . "cc-mode"))
+ ("cc-mode"
+ (".yas-parents" . "yet-another-c-mode and-that-one"))
+ ("yet-another-c-mode"
+ (".yas-parents" . "c-mode and-also-this-one lisp-interaction-mode"))))
+ (yas-reload-all)
+ (with-temp-buffer
+ (let* ((_ (yas-activate-extra-mode 'c-mode))
+ (expected `(,major-mode
+ c-mode
+ cc-mode
+ yet-another-c-mode
+ and-also-this-one
+ and-that-one
+ ;; prog-mode doesn't exist in emacs 24.3
,@(if (fboundp 'prog-mode)
'(prog-mode))
emacs-lisp-mode
lisp-interaction-mode))
(observed (yas--modes-to-activate)))
- (should (null (cl-set-exclusive-or expected observed)))
- (should (= (length expected)
- (length observed))))))))
+ (should (equal (sort expected #'string<) (sort observed #'string<))))))))
(ert-deftest issue-492-and-494 ()
(defalias 'yas--phony-c-mode 'c-mode)
;; FIXME: Why provide this default definition here?!?
(defalias 'special-mode 'fundamental))
+(unless (fboundp 'string-suffix-p)
+ ;; introduced in Emacs 24.4
+ (defun string-suffix-p (suffix string &optional ignore-case)
+ "Return non-nil if SUFFIX is a suffix of STRING.
+If IGNORE-CASE is non-nil, the comparison is done without paying
+attention to case differences."
+ (let ((start-pos (- (length string) (length suffix))))
+ (and (>= start-pos 0)
+ (eq t (compare-strings suffix nil nil
+ string start-pos nil ignore-case))))))
+
;;; 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