+(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
+ (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* ((major-mode 'c-mode)
+ (expected `(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 (equal major-mode (car observed)))
+ (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"))
+ ("yet-another-c-mode"
+ (".yas-parents" . "c-mode and-also-this-one lisp-interaction-mode"))))
+ (yas-reload-all)
+ (with-temp-buffer
+ (yas-activate-extra-mode 'c-mode)
+ (yas-activate-extra-mode 'yet-another-c-mode)
+ (yas-activate-extra-mode 'and-that-one)
+ (let* ((expected-first `(and-that-one
+ yet-another-c-mode
+ c-mode
+ ,major-mode))
+ (expected-rest `(cc-mode
+ ;; prog-mode doesn't exist in emacs 24.3
+ ,@(if (fboundp 'prog-mode)
+ '(prog-mode))
+ emacs-lisp-mode
+ and-also-this-one
+ lisp-interaction-mode))
+ (observed (yas--modes-to-activate)))
+ (should (equal expected-first
+ (cl-subseq observed 0 (length expected-first))))
+ (should (equal (sort expected-rest #'string<)
+ (sort (cl-subseq observed (length expected-first)) #'string<))))))))
+
+(defalias 'yas--phony-c-mode 'c-mode)
+
+(ert-deftest issue-492-and-494 ()
+ (define-derived-mode yas--test-mode yas--phony-c-mode "Just a test mode")
+ (yas-with-snippet-dirs '((".emacs.d/snippets"
+ ("yas--test-mode")))
+ (yas-reload-all)
+ (with-temp-buffer
+ (let* ((major-mode 'yas--test-mode)
+ (expected `(c-mode
+ ,@(if (fboundp 'prog-mode)
+ '(prog-mode))
+ yas--phony-c-mode
+ yas--test-mode))
+ (observed (yas--modes-to-activate)))
+ (should (null (cl-set-exclusive-or expected observed)))
+ (should (= (length expected)
+ (length observed)))))))
+
+(define-derived-mode yas--test-mode c-mode "Just a test mode")
+(define-derived-mode yas--another-test-mode c-mode "Another test mode")
+
+(ert-deftest issue-504-tricky-jit ()
+ (yas-with-snippet-dirs
+ '((".emacs.d/snippets"
+ ("yas--another-test-mode"
+ (".yas-parents" . "yas--test-mode"))
+ ("yas--test-mode")))
+ (let ((b (with-current-buffer (generate-new-buffer "*yas-test*")
+ (yas--another-test-mode)
+ (current-buffer))))
+ (unwind-protect
+ (progn
+ (yas-reload-all)
+ (should (= 0 (hash-table-count yas--scheduled-jit-loads))))
+ (kill-buffer b)))))
+
+(defun yas--basic-jit-loading-1 ()