]> code.delx.au - gnu-emacs-elpa/commitdiff
Test visiting compiled snippets
authorNoam Postavsky <npostavs@users.sourceforge.net>
Sat, 5 Sep 2015 19:13:09 +0000 (15:13 -0400)
committerNoam Postavsky <npostavs@users.sourceforge.net>
Sat, 5 Sep 2015 19:42:32 +0000 (15:42 -0400)
* yasnippet-tests.el (visiting-compiled-snippets): New Test.
* yasnippet.el (yas--lookup-snippet-1, yas-lookup-snippet): Split new
  function yas--lookup-snippet-1 from yas-lookup-snippet.

yasnippet-tests.el
yasnippet.el

index 0b14a56640a8c07f4966957109e1303304332252..a59cdf7352abc27bd46a2281625c01a89167cb6a 100644 (file)
@@ -449,7 +449,7 @@ TODO: correct this bug!"
    (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)
@@ -459,6 +459,20 @@ TODO: correct this bug!"
      (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
index 1fd08e2b856f7eca7227637cc9ca5d15b206ef06..ff4681170e2f779f3373c0b656c8c1788469211f 100644 (file)
@@ -2296,6 +2296,14 @@ Honours `yas-choose-tables-first', `yas-choose-keys-first' and
             (remove-duplicates (mapcan #'yas--table-templates tables)
                                :test #'equal))))
 
+(defun yas--lookup-snippet-1 (name mode)
+  "Get the snippet called NAME in MODE's tables."
+  (let ((yas-choose-tables-first nil)   ; avoid prompts
+        (yas-choose-keys-first nil))
+    (cl-find name (yas--all-templates
+                   (yas--get-snippet-tables mode))
+             :key #'yas--template-name :test #'string=)))
+
 (defun yas-lookup-snippet (name &optional mode noerror)
   "Get the snippet content for the snippet NAME in MODE's tables.
 
@@ -2304,11 +2312,7 @@ is non-nil, then don't signal an error if there isn't any snippet
 called NAME.
 
 Honours `yas-buffer-local-condition'."
-  (let* ((yas-choose-tables-first nil)  ; avoid prompts
-         (yas-choose-keys-first nil)
-         (snippet (cl-find name (yas--all-templates
-                                 (yas--get-snippet-tables mode))
-                           :key #'yas--template-name :test #'string=)))
+  (let ((snippet (yas--lookup-snippet-1 name mode)))
     (cond
      (snippet (yas--template-content snippet))
      (noerror nil)