diff --git a/init.test.el b/init.test.el index 72c4feead..fad51de56 100644 --- a/init.test.el +++ b/init.test.el @@ -2,8 +2,18 @@ (require 'core (concat user-emacs-directory "core/core")) -(doom! :feature evil - :completion company - :tools password-store - :lang web - :private hlissner) +(doom! :feature + evil + workspaces + + :completion + company + + :tools + password-store + + :lang + web + + :private + hlissner) diff --git a/modules/feature/workspaces/test/autoload-workspaces.el b/modules/feature/workspaces/test/autoload-workspaces.el new file mode 100644 index 000000000..64b04760e --- /dev/null +++ b/modules/feature/workspaces/test/autoload-workspaces.el @@ -0,0 +1,89 @@ +;;; feature/workspaces/test/autoload-workspaces.el -*- lexical-binding: t; -*- + +(require! :feature workspaces) + +(defmacro -with-workspace! (buffer-args &rest body) + (declare (indent defun)) + (let ((buffers + (cl-loop for bsym in buffer-args + collect `(,bsym (get-buffer-create ,(symbol-name bsym)))))) + `(let (noninteractive) + (+workspaces|init) + (save-window-excursion + (let* (,@buffers) + (cl-loop with persp = (get-current-persp) + for buf in (list ,@(mapcar #'car buffers)) + do (persp-add-buffer buf persp) + do (with-current-buffer buf + (setq buffer-file-name (make-temp-file "workspaces-test-")))) + ,@body + (dolist (buf (list ,@(mapcar #'car buffers))) + (persp-remove-buffer buf) + (kill-buffer buf)))) + (persp-mode -1) + (setq *persp-hash* nil + persp-buffer-props-hash nil)))) + +;; +(def-test! init + (-with-workspace! () + (should (equal (+workspace-current-name) +workspaces-main)))) + +(def-test! advice + (should (advice-member-p #'+workspaces*auto-add-buffer #'switch-to-buffer))) + +(def-test! current + (-with-workspace! () + (should (equal (+workspace-current-name) +workspaces-main)) + (should (+workspace-exists-p +workspaces-main)) + (let ((workspace (+workspace-get +workspaces-main)) + (current-workspace (+workspace-current))) + (should workspace) + (should (+workspace-p workspace)) + (should (+workspace-p current-workspace)) + (should (equal workspace current-workspace))))) + +(def-test! workspace-list + (-with-workspace! () + (should (equal (+workspace-list-names) + (list (+workspace-current-name)))) + (should (equal (+workspace-list) + (list (+workspace-current)))))) + +(def-test! workspace-crud + "Creating, reading, updating and deleting workspaces." + (-with-workspace! () + (let ((new-workspace-name "*new-test*") + (renamed-workspace-name "*old-test*")) + (should (+workspace-new new-workspace-name)) + (should (seq-contains (+workspace-list-names) new-workspace-name)) + (should (equal new-workspace-name + (+workspace-rename new-workspace-name renamed-workspace-name))) + (should-not (seq-contains (+workspace-list-names) new-workspace-name)) + (should (seq-contains (+workspace-list-names) renamed-workspace-name)) + (should (= (length (+workspace-list-names)) 2)) + (+workspace-delete renamed-workspace-name) + (should (= (length (+workspace-list-names)) 1))))) + +(def-test! workspace-switch + (-with-workspace! () + (let ((new-workspace-name "*new-test*")) + (should-error (+workspace-switch new-workspace-name)) + (should (+workspace-switch new-workspace-name t)) + (should (equal (+workspace-current-name) new-workspace-name))))) + +(def-test! buffer-list + (-with-workspace! (a b) + (let ((c (get-buffer-create "c")) + (d (get-buffer-create "d"))) + (should (+workspace-contains-buffer-p a)) + (should (+workspace-contains-buffer-p b)) + (should-not (+workspace-contains-buffer-p c)) + ;; New (and real) buffers should be added to workspace buffer list. + (doom-set-buffer-real c t) + (switch-to-buffer "c") + (should (+workspace-contains-buffer-p c)) + ;; unreal buffers shouldn't + (switch-to-buffer "d") + (should-not (+workspace-contains-buffer-p d))))) +