]> code.delx.au - gnu-emacs-elpa/blobdiff - yasnippet-tests.el
Merge pull request #571 from PhilHudson/master
[gnu-emacs-elpa] / yasnippet-tests.el
index f40ed25b64644955d6967a49b97192fa56fc3724..0f113522d1f9b524f608806a15833ae57c1a5529 100644 (file)
     (ert-simulate-command `(yas-mock-insert "abc"))
     (should (string= (yas--buffer-contents) "abcabcabcabc"))))
 
+(ert-deftest delete-numberless-inner-snippet-issue-562 ()
+  (with-temp-buffer
+    (yas-minor-mode 1)
+    (yas-expand-snippet "${3:${test}bla}$0${2:ble}")
+    (ert-simulate-command '(yas-next-field-or-maybe-expand))
+    (should (looking-at "testblable"))
+    (ert-simulate-command '(yas-next-field-or-maybe-expand))
+    (ert-simulate-command '(yas-skip-and-clear-or-delete-char))
+    (should (looking-at "ble"))
+    (should (null (yas--snippets-at-point)))))
+
 ;; (ert-deftest in-snippet-undo ()
 ;;   (with-temp-buffer
 ;;     (yas-minor-mode 1)
 
 (ert-deftest be-careful-when-escaping-in-yas-selected-text-2 ()
   (with-temp-buffer
+    (yas-minor-mode 1)
     (let ((yas-selected-text "He)}o world!"))
       (yas-expand-snippet "Look ma! ${1:`(yas-selected-text)`} OK?")
       (should (string= (yas--buffer-contents) "Look ma! He)}o world! OK?")))))
@@ -322,12 +334,13 @@ TODO: correct this bug!"
     (yas-saving-variables
      (yas-with-snippet-dirs
        '((".emacs.d/snippets"
-          ("text-mode"
+          ("emacs-lisp-mode"
            ("foo-barbaz" . "# condition: yas--foobarbaz\n# --\nOKfoo-barbazOK")
            ("barbaz" . "# condition: yas--barbaz\n# --\nOKbarbazOK")
-           ("baz" . "OKbazOK"))))
+           ("baz" . "OKbazOK")
+           ("'quote" . "OKquoteOK"))))
        (yas-reload-all)
-       (text-mode)
+       (emacs-lisp-mode)
        (yas-minor-mode-on)
        (let ((yas-key-syntaxes '("w" "w_")))
          (let ((yas--barbaz t))
@@ -336,13 +349,22 @@ TODO: correct this bug!"
          (let ((yas--foobarbaz t))
            (yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK"))))
          (let ((yas-key-syntaxes
-                (cons #'(lambda ()
+                (cons #'(lambda (_start-point)
                           (unless (looking-back "-")
                             (backward-char)
                             'again))
                       yas-key-syntaxes))
                (yas--foobarbaz t))
-           (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))))))))
+           (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))))
+       (let ((yas-key-syntaxes '(yas-try-key-from-whitespace)))
+         (yas-should-expand '(("xxx\n'quote" . "xxx\nOKquoteOK")
+                              ("xxx 'quote" . "xxx OKquoteOK"))))
+       (let ((yas-key-syntaxes '(yas-shortest-key-until-whitespace))
+             (yas--foobarbaz t) (yas--barbaz t))
+         (yas-should-expand '(("foo-barbaz" . "foo-barOKbazOK")))
+         (setq yas-key-syntaxes '(yas-longest-key-from-whitespace))
+         (yas-should-expand '(("foo-barbaz" . "OKfoo-barbazOK")
+                              ("foo " . "foo "))))))))
 
 \f
 ;;; Loading
@@ -475,6 +497,23 @@ TODO: correct this bug!"
                              (should (= (length expected)
                                         (length observed)))))))
 
+(ert-deftest issue-504-tricky-jit ()
+  (define-derived-mode yas--test-mode c-mode "Just a test mode")
+  (define-derived-mode yas--another-test-mode c-mode "Another test mode")
+  (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 ()
   (with-temp-buffer
     (should (= 4 (hash-table-count yas--scheduled-jit-loads)))
@@ -794,8 +833,9 @@ add the snippets associated with the given mode."
 
 
 (provide 'yasnippet-tests)
-;;; yasnippet-tests.el ends here
 ;; Local Variables:
+;; indent-tabs-mode: nil
 ;; lexical-binding: t
 ;; byte-compile-warnings: (not cl-functions)
 ;; End:
+;;; yasnippet-tests.el ends here