Move unit tests from ert to buttercup
Easier to organize and write. Now I can hopefully strive for better coverage!
This commit is contained in:
parent
98d2f1de3f
commit
eaca8c58fa
41 changed files with 1371 additions and 1101 deletions
|
@ -18,6 +18,36 @@
|
|||
`(set-evil-initial-state! ,modes ,state))
|
||||
|
||||
|
||||
;;
|
||||
;; Custom arguments / interactive codes
|
||||
;;
|
||||
|
||||
;;;###autoload
|
||||
(after! evil
|
||||
;; These arg types will highlight matches in the current buffer
|
||||
(evil-ex-define-argument-type buffer-match :runner +evil-ex-buffer-match)
|
||||
(evil-ex-define-argument-type global-match :runner +evil-ex-global-match)
|
||||
;; Other commands can make use of this
|
||||
(evil-define-interactive-code "<//>"
|
||||
:ex-arg buffer-match (list (if (evil-ex-p) evil-ex-argument)))
|
||||
(macroexpand '
|
||||
(evil-define-interactive-code "<//g>"
|
||||
:ex-arg global-match (list (if (evil-ex-p) evil-ex-argument))))
|
||||
|
||||
;; By default :g[lobal] doesn't highlight matches in the current buffer. I've
|
||||
;; got to write my own argument type and interactive code to get it to do so.
|
||||
(evil-ex-define-argument-type global-delim-match :runner +evil-ex-global-delim-match)
|
||||
(dolist (sym '(evil-ex-global evil-ex-global-inverted))
|
||||
(evil-set-command-property sym :ex-arg 'global-delim-match))
|
||||
|
||||
;; Forward declare these so that ex completion works, even if the autoloaded
|
||||
;; functions aren't loaded yet.
|
||||
(evil-set-command-properties
|
||||
'+evil:align :move-point t :ex-arg 'buffer-match :ex-bang t :evil-mc t :keep-visual t :suppress-operator t)
|
||||
(evil-set-command-properties
|
||||
'+evil:mc :move-point nil :ex-arg 'global-match :ex-bang t :evil-mc t))
|
||||
|
||||
|
||||
;;
|
||||
;; Commands
|
||||
;;
|
||||
|
|
|
@ -141,28 +141,6 @@ variable for an explanation of the defaults (in comments). See
|
|||
(advice-add #'evil-window-split :override #'+evil*window-split)
|
||||
(advice-add #'evil-window-vsplit :override #'+evil*window-vsplit)
|
||||
|
||||
;; By default :g[lobal] doesn't highlight matches in the current buffer. I've
|
||||
;; got to write my own argument type and interactive code to get it to do so.
|
||||
(evil-ex-define-argument-type global-delim-match :runner +evil-ex-global-delim-match)
|
||||
(dolist (sym '(evil-ex-global evil-ex-global-inverted))
|
||||
(evil-set-command-property sym :ex-arg 'global-delim-match))
|
||||
|
||||
;; These arg types will highlight matches in the current buffer
|
||||
(evil-ex-define-argument-type buffer-match :runner +evil-ex-buffer-match)
|
||||
(evil-ex-define-argument-type global-match :runner +evil-ex-global-match)
|
||||
;; Other commands can make use of this
|
||||
(evil-define-interactive-code "<//>"
|
||||
:ex-arg buffer-match (list (if (evil-ex-p) evil-ex-argument)))
|
||||
(evil-define-interactive-code "<//g>"
|
||||
:ex-arg global-match (list (if (evil-ex-p) evil-ex-argument)))
|
||||
|
||||
;; Forward declare these so that ex completion works, even if the autoloaded
|
||||
;; functions aren't loaded yet.
|
||||
(evil-set-command-properties
|
||||
'+evil:align :move-point t :ex-arg 'buffer-match :ex-bang t :evil-mc t :keep-visual t :suppress-operator t)
|
||||
(evil-set-command-properties
|
||||
'+evil:mc :move-point nil :ex-arg 'global-match :ex-bang t :evil-mc t)
|
||||
|
||||
;; Ensure jump points are created
|
||||
(defun +evil*set-jump (&rest _)
|
||||
(evil-set-jump))
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/evil/test/autoload-files.el
|
||||
|
||||
(defmacro with-temp-files!! (src dest &rest body)
|
||||
"Run FORMS in the context of a temporary package setup (as in, it won't
|
||||
affects your Emacs packages)."
|
||||
(declare (indent 2) (doc-string 3))
|
||||
`(let ((it ,src)
|
||||
(other ,dest))
|
||||
(with-temp-file it
|
||||
(insert "Hello world"))
|
||||
(with-minor-mode! projectile-mode
|
||||
(unwind-protect
|
||||
(progn
|
||||
(should (file-exists-p it))
|
||||
(find-file-literally it)
|
||||
(should (equal (buffer-string) "Hello world"))
|
||||
(should (equal (buffer-file-name) it))
|
||||
(let ((inhibit-message (not doom-debug-mode)))
|
||||
,@body))
|
||||
(ignore-errors (delete-file it))
|
||||
,(if dest `(ignore-errors (delete-file other)))))))
|
||||
|
||||
;;
|
||||
(def-test! move-this-file
|
||||
":mv"
|
||||
(with-temp-files!! "/tmp/doom-buffer" "/tmp/doom-buffer-new"
|
||||
(should-error (+evil:move-this-file it))
|
||||
(should (+evil:move-this-file other t))
|
||||
(should (file-exists-p other))
|
||||
(should (not (file-exists-p it)))))
|
||||
|
||||
(def-test! copy-this-file
|
||||
":cp"
|
||||
(with-temp-files!! "/tmp/doom-buffer-2" "/tmp/doom-buffer-2-new"
|
||||
(should-error (+evil:copy-this-file it))
|
||||
(should (+evil:copy-this-file other t))
|
||||
(should (file-exists-p other))
|
||||
(should (file-exists-p it))))
|
||||
|
||||
(def-test! delete-this-file
|
||||
":rm"
|
||||
(with-temp-files!! "/tmp/doom-buffer-3" nil
|
||||
(should-error (+evil:delete-this-file "this-file-does-not-exist"))
|
||||
(should (+evil:delete-this-file nil t))
|
||||
(should (not (file-exists-p it)))))
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/evil/test/evil.el
|
||||
|
||||
;;
|
||||
;; `evil-ex-replace-special-filenames'
|
||||
(def-test! resolve-vim-path
|
||||
(cl-flet ((do-it #'evil-ex-replace-special-filenames))
|
||||
;; file modifiers
|
||||
(let ((buffer-file-name "~/.emacs.d/test/modules/feature/test-evil.el")
|
||||
(default-directory "~/.emacs.d/test/modules/"))
|
||||
(should (equal (do-it "%") "feature/test-evil.el"))
|
||||
(should (equal (do-it "%:r") "feature/test-evil"))
|
||||
(should (equal (do-it "%:r.elc") "feature/test-evil.elc"))
|
||||
(should (equal (do-it "%:e") "el"))
|
||||
(should (equal (do-it "%:p") (expand-file-name buffer-file-name)))
|
||||
(should (equal (do-it "%:h") "feature"))
|
||||
(should (equal (do-it "%:t") "test-evil.el"))
|
||||
(should (equal (do-it "%:.") "feature/test-evil.el"))
|
||||
(should (equal (do-it "%:~") "~/.emacs.d/test/modules/feature/test-evil.el"))
|
||||
(should (equal (file-truename (do-it "%:p"))
|
||||
(file-truename buffer-file-name))))
|
||||
;; nested file modifiers
|
||||
(let ((buffer-file-name "~/vim/src/version.c")
|
||||
(default-directory "~/vim/"))
|
||||
(should (equal (do-it "%:p") (expand-file-name "~/vim/src/version.c")))
|
||||
(should (equal (do-it "%:p:.") "src/version.c"))
|
||||
(should (equal (do-it "%:p:~") "~/vim/src/version.c"))
|
||||
(should (equal (do-it "%:h") "src"))
|
||||
(should (equal (do-it "%:p:h") (expand-file-name "~/vim/src")))
|
||||
(should (equal (do-it "%:p:h:h") (expand-file-name "~/vim")))
|
||||
(should (equal (do-it "%:t") "version.c"))
|
||||
(should (equal (do-it "%:p:t") "version.c"))
|
||||
(should (equal (do-it "%:r") "src/version"))
|
||||
(should (equal (do-it "%:p:r") (expand-file-name "~/vim/src/version")))
|
||||
(should (equal (do-it "%:t:r") "version")))
|
||||
;; empty file modifiers
|
||||
(let (buffer-file-name default-directory)
|
||||
(should (equal (do-it "%") ""))
|
||||
(should (equal (do-it "%:r") ""))
|
||||
(should (equal (do-it "%:e") ""))
|
||||
(should (equal (do-it "%:h") ""))
|
||||
(should (equal (do-it "%:t") ""))
|
||||
(should (equal (do-it "%:.") ""))
|
||||
(should (equal (do-it "%:~") ""))
|
||||
(should (equal (do-it "%:P") "")))))
|
||||
|
||||
(def-test! file-modifiers
|
||||
(cl-flet ((do-it #'evil-ex-replace-special-filenames))
|
||||
(let ((buffer-file-name "~/.emacs.d/test/modules/feature/test-evil.el")
|
||||
(default-directory "~/.emacs.d/test/modules/"))
|
||||
(should (equal (do-it "%:s?e?x?") "fxature/test-evil.el"))
|
||||
(should (equal (do-it "%:gs?e?x?") "fxaturx/txst-xvil.xl")))))
|
||||
|
||||
(def-test! empty-file-modifiers
|
||||
(cl-flet ((do-it #'evil-ex-replace-special-filenames))
|
||||
(let (buffer-file-name default-directory)
|
||||
(should (equal (do-it "%:s?e?x?") ""))
|
||||
(should (equal (do-it "%:gs?e?x?") "")))))
|
||||
|
66
modules/feature/evil/test/test-evil.el
Normal file
66
modules/feature/evil/test/test-evil.el
Normal file
|
@ -0,0 +1,66 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/evil/test/test-evil.el
|
||||
|
||||
(describe "feature/evil"
|
||||
:var (resv project-root)
|
||||
(before-all (require 'evil))
|
||||
(after-all (unload-feature 'evil t))
|
||||
(before-each
|
||||
(fset 'resv #'+evil*resolve-vim-path)
|
||||
(spy-on 'doom-project-root :and-call-fake (lambda () project-root)))
|
||||
|
||||
;; `evil-ex-replace-special-filenames' / `+evil*resolve-vim-path'
|
||||
(describe "file modifiers"
|
||||
(it "supports basic vim file modifiers"
|
||||
(let ((buffer-file-name "~/.emacs.d/test/modules/feature/test-evil.el")
|
||||
(default-directory "~/.emacs.d/test/modules/")
|
||||
(project-root "~/.emacs.d/"))
|
||||
(expect (resv "%") :to-equal "feature/test-evil.el")
|
||||
(expect (resv "%:r") :to-equal "feature/test-evil")
|
||||
(expect (resv "%:r.elc") :to-equal "feature/test-evil.elc")
|
||||
(expect (resv "%:e") :to-equal "el")
|
||||
(expect (resv "%:p") :to-equal (expand-file-name buffer-file-name))
|
||||
(expect (resv "%:h") :to-equal "feature")
|
||||
(expect (resv "%:t") :to-equal "test-evil.el")
|
||||
(expect (resv "%:.") :to-equal "feature/test-evil.el")
|
||||
(expect (resv "%:~") :to-equal "~/.emacs.d/test/modules/feature/test-evil.el")
|
||||
(expect (file-truename (resv "%:p"))
|
||||
:to-equal (file-truename buffer-file-name))))
|
||||
|
||||
(it "supports nested vim file modifiers"
|
||||
(let ((buffer-file-name "~/vim/src/version.c")
|
||||
(default-directory "~/vim/")
|
||||
(project-root "~/vim/"))
|
||||
(expect (resv "%:p") :to-equal (expand-file-name "~/vim/src/version.c"))
|
||||
(expect (resv "%:p:.") :to-equal "src/version.c")
|
||||
(expect (resv "%:p:~") :to-equal "~/vim/src/version.c")
|
||||
(expect (resv "%:h") :to-equal "src")
|
||||
(expect (resv "%:p:h") :to-equal (expand-file-name "~/vim/src"))
|
||||
(expect (resv "%:p:h:h") :to-equal (expand-file-name "~/vim"))
|
||||
(expect (resv "%:t") :to-equal "version.c")
|
||||
(expect (resv "%:p:t") :to-equal "version.c")
|
||||
(expect (resv "%:r") :to-equal "src/version")
|
||||
(expect (resv "%:p:r") :to-equal (expand-file-name "~/vim/src/version"))
|
||||
(expect (resv "%:t:r") :to-equal "version")))
|
||||
|
||||
(it "cleans up empty file modifiers"
|
||||
(let (buffer-file-name default-directory)
|
||||
(expect (resv "%") :to-equal "")
|
||||
(expect (resv "%:r") :to-equal "")
|
||||
(expect (resv "%:e") :to-equal "")
|
||||
(expect (resv "%:h") :to-equal "")
|
||||
(expect (resv "%:t") :to-equal "")
|
||||
(expect (resv "%:.") :to-equal "")
|
||||
(expect (resv "%:~") :to-equal "")
|
||||
(expect (resv "%:P") :to-equal "")))
|
||||
|
||||
(it "supports substitution modifiers"
|
||||
(let ((buffer-file-name "~/.emacs.d/test/modules/feature/test-evil.el")
|
||||
(default-directory "~/.emacs.d/test/modules/"))
|
||||
(expect (resv "%:s?e?x?") :to-equal "fxature/test-evil.el")
|
||||
(expect (resv "%:gs?e?x?") :to-equal "fxaturx/txst-xvil.xl")))
|
||||
|
||||
(it "cleans up empty substitution modifiers"
|
||||
(let (buffer-file-name default-directory)
|
||||
(expect (resv "%:s?e?x?") :to-equal "")
|
||||
(expect (resv "%:gs?e?x?") :to-equal "")))))
|
Loading…
Add table
Add a link
Reference in a new issue