2017-07-14 18:19:08 +02:00
|
|
|
;; -*- no-byte-compile: t; -*-
|
|
|
|
;;; feature/workspaces/test/autoload-workspaces.el
|
2017-07-08 21:10:35 +02:00
|
|
|
|
|
|
|
(require! :feature workspaces)
|
2018-05-25 00:46:11 +02:00
|
|
|
(doom|init-custom-hooks)
|
2017-07-08 21:10:35 +02:00
|
|
|
|
2017-12-31 11:45:02 -05:00
|
|
|
(defmacro with-workspace!! (buffer-args &rest body)
|
2017-07-08 21:10:35 +02:00
|
|
|
(declare (indent defun))
|
|
|
|
(let ((buffers
|
|
|
|
(cl-loop for bsym in buffer-args
|
|
|
|
collect `(,bsym (get-buffer-create ,(symbol-name bsym))))))
|
2018-01-03 13:24:11 -05:00
|
|
|
`(let ((persp-auto-resume-time -1)
|
2018-01-03 20:13:27 -05:00
|
|
|
(persp-auto-save-opt 0))
|
2018-01-20 02:44:12 -05:00
|
|
|
(require 'persp-mode)
|
2018-01-03 20:13:27 -05:00
|
|
|
(let (noninteractive)
|
|
|
|
(persp-mode +1))
|
|
|
|
(+workspace-switch +workspaces-main t)
|
2018-01-03 13:24:11 -05:00
|
|
|
(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
|
|
|
|
(let (kill-buffer-query-functions kill-buffer-hook)
|
|
|
|
(mapc #'kill-buffer (list ,@(mapcar #'car buffers)))))
|
2018-01-03 20:13:27 -05:00
|
|
|
(let (noninteractive)
|
|
|
|
(persp-mode -1)))))
|
2017-07-08 21:10:35 +02:00
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspaces|init'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! init
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! ()
|
2017-07-08 21:10:35 +02:00
|
|
|
(should (equal (+workspace-current-name) +workspaces-main))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspaces*auto-add-buffer'
|
2017-12-31 11:45:02 -05:00
|
|
|
(def-test! auto-add-buffer-to-persp
|
|
|
|
(let ((a (generate-new-buffer "a")))
|
|
|
|
(doom-set-buffer-real a t)
|
|
|
|
(with-workspace!! ()
|
|
|
|
(should-not (+workspace-contains-buffer-p a))
|
|
|
|
(switch-to-buffer a)
|
|
|
|
(should (+workspace-contains-buffer-p a)))))
|
2017-07-08 21:10:35 +02:00
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace-current'
|
|
|
|
;; `+workspace-current-name'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! current
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! ()
|
2017-07-08 21:10:35 +02:00
|
|
|
(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)))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace-list'
|
|
|
|
;; `+workspace-list-names'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! workspace-list
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! ()
|
2017-07-08 21:10:35 +02:00
|
|
|
(should (equal (+workspace-list-names)
|
|
|
|
(list (+workspace-current-name))))
|
|
|
|
(should (equal (+workspace-list)
|
|
|
|
(list (+workspace-current))))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace-new'
|
|
|
|
;; `+workspace-rename'
|
|
|
|
;; `+workspace-delete'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! workspace-crud
|
|
|
|
"Creating, reading, updating and deleting workspaces."
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! ()
|
2017-07-08 21:10:35 +02:00
|
|
|
(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)))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace-switch'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! workspace-switch
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! ()
|
2017-07-08 21:10:35 +02:00
|
|
|
(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)))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace-buffer-list'
|
|
|
|
;; `+workspace-contains-buffer-p'
|
2017-07-08 21:10:35 +02:00
|
|
|
(def-test! buffer-list
|
2017-12-31 11:45:02 -05:00
|
|
|
(with-workspace!! (a b)
|
2017-07-08 21:10:35 +02:00
|
|
|
(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)))))
|
|
|
|
|
2018-01-03 13:24:11 -05:00
|
|
|
;; `+workspace/close-window-or-workspace'
|
|
|
|
(def-test! close-window-or-workspace
|
|
|
|
(with-workspace!! (a b)
|
|
|
|
(let ((ws (+workspace-current-name))
|
|
|
|
(inhibit-message t))
|
|
|
|
(+workspace-switch "test" t)
|
|
|
|
(split-window)
|
|
|
|
(should (equal (+workspace-current-name) "test"))
|
|
|
|
(should (= (length (doom-visible-windows)) 2))
|
|
|
|
;; kill window if more than one
|
|
|
|
(+workspace/close-window-or-workspace)
|
|
|
|
(should (= (length (doom-visible-windows)) 1))
|
|
|
|
;; kill workspace on last window
|
|
|
|
(+workspace/close-window-or-workspace)
|
|
|
|
(should (equal (+workspace-current-name) "main")))))
|