add: ert-based test-suite

This commit is contained in:
Joao Tavora 2013-10-17 12:17:11 +01:00
parent b4bf8bbd33
commit 0adcad2190

View File

@ -1,4 +1,4 @@
;;; snippet-tests.el --- some basic tests for snippet.el -*- lexical-binding: t; -*- ;;; snippet-tests.el --- some basic tests for snippet.el
;; Copyright (C) 2013 ;; Copyright (C) 2013
@ -26,44 +26,36 @@
(require 'snippet) (require 'snippet)
(define-snippet printf () (setq snippet--printf-snippet-forms
"printf (\"" '("printf (\""
(field 1 "%s") (field 1 "%s")
(mirror 1 (if (string-match "%" field-text) "\"," "\);")) (mirror 1 (if (string-match "%" field-text) "\"," "\")"))
(field 2) (field 2)
(mirror 1 (if (string-match "%" field-text) "\);" ""))) (mirror 1 (if (string-match "%" field-text) "\)" ""))))
(define-snippet foo () (ert-deftest printf-expansion ()
(field 1 "bla") ""
"ble" (with-temp-buffer
(mirror 1) (funcall (eval `(make-snippet ,@snippet--printf-snippet-forms)))
(field 2 (should (equal (buffer-string) "printf (\"%s\",)"))))
((field 3 "fonix")
"fotrix"
(mirror 1 (concat field-text "qqcoisa"))))
"end")
(define-snippet easy () (ert-deftest printf-mirrors ()
"A " ""
(field 1 "field") (with-temp-buffer
" and its mirror: " (funcall (eval `(make-snippet ,@snippet--printf-snippet-forms)))
(mirror 1 (format "(mirror of %s)" field-text))) (ert-simulate-command '(delete-forward-char 1))
(should (equal (buffer-string) "printf (\"s\")"))
(ert-simulate-command '((lambda () (interactive) (insert "%"))))
(should (equal (buffer-string) "printf (\"%s\",)"))))
(defun test () (ert-deftest printf-mirrors-and-navigation ()
(interactive) ""
(with-current-buffer (switch-to-buffer (get-buffer-create "*test easy snippet*")) (with-temp-buffer
(erase-buffer) (funcall (eval `(make-snippet ,@snippet--printf-snippet-forms)))
(easy))) (ert-simulate-command '(delete-forward-char 1))
(should (equal (buffer-string) "printf (\"s\")"))
(defun test2 () (ert-simulate-command '((lambda () (interactive) (insert "%"))))
(interactive) (should (equal (buffer-string) "printf (\"%s\",)"))
(with-current-buffer (switch-to-buffer (get-buffer-create "*test printf snippent*")) (ert-simulate-command '(snippet-next-field))
(erase-buffer) (ert-simulate-command '((lambda () (interactive) (insert "somevar"))))
(printf))) (should (equal (buffer-string) "printf (\"%s\",somevar)"))))
(provide 'snippet-tests)
;;; Local Variables:
;;; lexical-binding: t
;;; End:
;;; snippet-tests.el ends here