]> code.delx.au - gnu-emacs-elpa/commitdiff
Added a few ert unit tests, mostly for very basic snippet mechanics
authorJoao Tavora <joaotavora@gmail.com>
Tue, 13 Mar 2012 11:23:38 +0000 (11:23 +0000)
committerJoao Tavora <joaotavora@gmail.com>
Tue, 13 Mar 2012 11:23:38 +0000 (11:23 +0000)
yasnippet-tests.el [new file with mode: 0755]

diff --git a/yasnippet-tests.el b/yasnippet-tests.el
new file mode 100755 (executable)
index 0000000..0cbff75
--- /dev/null
@@ -0,0 +1,123 @@
+;;; yasnippet-tests.el --- some yasnippet tests\r
+\r
+;; Copyright (C) 2012  João Távora\r
+\r
+;; Author: João Távora <joaot@siscog.pt>\r
+;; Keywords: emulations, convenience\r
+\r
+;; This program is free software; you can redistribute it and/or modify\r
+;; it under the terms of the GNU General Public License as published by\r
+;; the Free Software Foundation, either version 3 of the License, or\r
+;; (at your option) any later version.\r
+\r
+;; This program is distributed in the hope that it will be useful,\r
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+;; GNU General Public License for more details.\r
+\r
+;; You should have received a copy of the GNU General Public License\r
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+\r
+;;; Commentary:\r
+\r
+;; Attempt to test basic snippet mechanics and the loading system \r
+\r
+;;; Code:\r
+\r
+(require 'yasnippet)\r
+(require 'ert)\r
+(require 'ert-x)\r
+\r
+\r
+;;; Snippet mechanics\r
+\r
+(ert-deftest field-navigation ()\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "${1:brother} from another ${2:mother}")\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another mother"))\r
+    \r
+    (should (looking-at "brother"))\r
+    (ert-simulate-command '(yas/next-field-or-maybe-expand))\r
+    (should (looking-at "mother"))\r
+    (ert-simulate-command '(yas/prev-field))\r
+    (should (looking-at "brother"))))\r
+\r
+(ert-deftest simple-mirror ()\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "${1:brother} from another $1")\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another brother"))\r
+    (ert-simulate-command `(yas/mock-insert "bla"))\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "bla from another bla"))))\r
+\r
+(ert-deftest mirror-with-transformation ()\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "${1:brother} from another ${1:$(upcase yas/text)}")\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another BROTHER"))\r
+    (ert-simulate-command `(yas/mock-insert "bla"))\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "bla from another BLA"))))\r
+\r
+(ert-deftest nested-placeholders-kill-superfield ()\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "brother from ${2:another ${3:mother}}!")\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another mother!"))\r
+    (ert-simulate-command `(yas/mock-insert "bla"))\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from bla!"))))\r
+\r
+(ert-deftest nested-placeholders-use-subfield ()\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "brother from ${2:another ${3:mother}}!")\r
+    (ert-simulate-command '(yas/next-field-or-maybe-expand))\r
+    (ert-simulate-command `(yas/mock-insert "bla"))\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another bla!"))))\r
+\r
+;; (ert-deftest in-snippet-undo ()\r
+;;   (with-temp-buffer\r
+;;     (yas/minor-mode 1)\r
+;;     (yas/expand-snippet "brother from ${2:another ${3:mother}}!")\r
+;;     (ert-simulate-command '(yas/next-field-or-maybe-expand))\r
+;;     (ert-simulate-command `(yas/mock-insert "bla"))\r
+;;     (ert-simulate-command '(undo))\r
+;;     (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+;;                      "brother from another mother!"))))\r
+\r
+\r
+;;; Misc tests\r
+;;; \r
+\r
+(ert-deftest protection-overlay-no-cheating ()\r
+  "Protection overlays at the very end of the buffer, are dealt by cheatingly inserting a newline!\r
+\r
+TODO: correct this bug!"\r
+  :expected-result :failed\r
+  (with-temp-buffer\r
+    (yas/minor-mode 1)\r
+    (yas/expand-snippet "${2:brother} from another ${1:mother}")\r
+    (should (string= (buffer-substring-no-properties (point-min) (point-max))\r
+                     "brother from another mother") ;; no newline should be here!\r
+            )))\r
+\r
+;;; Helpers\r
+;;; \r
+\r
+(defun yas/mock-insert (string)\r
+  (interactive)\r
+  (do ((i 0 (1+ i)))\r
+      ((= i (length string)))\r
+    (insert (aref string i))))\r
+\r
+\r
+(provide 'yasnippet-tests)\r
+;;; yasnippet-tests.el ends here\r