diff options
| author | Matthew White <mehw.is.me@inventati.org> | 2021-08-16 17:02:43 +0000 |
|---|---|---|
| committer | Matthew White <mehw.is.me@inventati.org> | 2021-10-20 23:01:53 +0200 |
| commit | f7dd9da5302951e292b9128aa47f9c380d5d23db (patch) | |
| tree | cb309feecf47a4bf7292b61da6fe3119a43575b1 | |
| parent | e03a9876c85f9cf0466e6f867bfeaadffca63a11 (diff) | |
basic-persp-test-match-scratch-buffers: test new ert's function
Add tests for 'persp-test-match-scratch-buffers' utility function, to
verify that it can detect buffers which may be all considered scratch
buffer.
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | test/test-perspective.el | 82 |
2 files changed, 83 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d72626..bf05c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### ERT tests added +- `basic-persp-test-match-scratch-buffers`: evaluate `persp-test-match-scratch-buffers`. - `persp-test-match-scratch-buffers`: utility function to list live scratch buffers. - `basic-persp-test-with-persp`: evaluate `persp-test-with-persp` macro. diff --git a/test/test-perspective.el b/test/test-perspective.el index e91ce0a..9c5cdb4 100644 --- a/test/test-perspective.el +++ b/test/test-perspective.el @@ -249,6 +249,88 @@ that are not the main perspective." (should (kill-buffer "*scratch* (C)")) (should-not (get-buffer "*scratch* (C)")))) +(ert-deftest basic-persp-test-match-scratch-buffers () + "Test `persp-test-match-scratch-buffers'. + +Expect a list of live buffers that may be considered *scratch* +buffers, aka the buffer's name begins with \"*scratch*\", or nil +if there's none. + +When providing buffer or buffer's name arguments, them should +include exactly what the function would find. Repetition and +order do not matter. If just one argument isn't a candidate, +return nil." + (let (matched-buffers dummy-buffer scratch-buffer scratch-buffer-A) + ;; Cleanup *scratch* buffers. + (mapc (lambda (buffer) + (when (string-match-p "^\\*scratch\\*.*$" (buffer-name buffer)) + (kill-buffer buffer))) + (buffer-list)) + ;; Match live *scratch* buffers. + (persp-test-with-persp + (should (setq dummy-buffer (get-buffer-create "*dummy*"))) + (should (setq scratch-buffer (get-buffer-create "*scratch*"))) + ;; get a list of all live *scratch* buffers + (should (setq matched-buffers (list scratch-buffer))) + (should (equal matched-buffers (persp-test-match-scratch-buffers))) + ;; verify that all arguemnts meet the criteria + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*"))) + (should (equal matched-buffers (persp-test-match-scratch-buffers scratch-buffer))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*" scratch-buffer))) + (should (equal matched-buffers (persp-test-match-scratch-buffers scratch-buffer "*scratch*"))) + ;; verify that the matching criteria cannot be subverted + (should-not (persp-test-match-scratch-buffers "*dummy*")) + (should-not (persp-test-match-scratch-buffers dummy-buffer)) + (should-not (persp-test-match-scratch-buffers "*scratch* ")) + (should-not (persp-test-match-scratch-buffers "*scratch*" "*dummy*")) + (should-not (persp-test-match-scratch-buffers "*dummy*" "*scratch*")) + (should-not (persp-test-match-scratch-buffers "*scratch*" "*scratch* ")) + (should-not (persp-test-match-scratch-buffers "*scratch* " "*scratch*")) + (should-not (persp-test-match-scratch-buffers scratch-buffer dummy-buffer)) + (should-not (persp-test-match-scratch-buffers dummy-buffer scratch-buffer)) + (should-not (persp-test-match-scratch-buffers "*scratch*" "*scratch* " "*scratch*")) + (should (kill-buffer dummy-buffer)) + (should-not (get-buffer "*dummy*")) + (should-not (buffer-live-p dummy-buffer)) + (should-not (persp-test-match-scratch-buffers dummy-buffer)) + (should-not (persp-test-match-scratch-buffers scratch-buffer dummy-buffer)) + (should-not (persp-test-match-scratch-buffers dummy-buffer scratch-buffer)) + (should (get-buffer-create "*scratch* ")) + (setq matched-buffers (list scratch-buffer (get-buffer "*scratch* "))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*" "*scratch* "))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch* " "*scratch*"))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*" "*scratch* " "*scratch*")))) + ;; Cleanup *scratch* buffers. + (mapc (lambda (buffer) + (when (string-match-p "^\\*scratch\\*.*$" (buffer-name buffer)) + (kill-buffer buffer))) + (buffer-list)) + ;; Match live *scratch* buffers. + (persp-test-with-persp + (persp-new "A") + (should (setq scratch-buffer (get-buffer-create "*scratch*"))) + (should (setq scratch-buffer-A (get-buffer "*scratch* (A)"))) + ;; get a list of all live *scratch* buffers + (should (setq matched-buffers (list scratch-buffer scratch-buffer-A))) + (should (equal matched-buffers (persp-test-match-scratch-buffers))) + ;; verify that all arguemnts meet the criteria + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*" "*scratch* (A)"))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch* (A)" "*scratch*"))) + (should (equal matched-buffers (persp-test-match-scratch-buffers scratch-buffer scratch-buffer-A))) + (should (equal matched-buffers (persp-test-match-scratch-buffers scratch-buffer-A "*scratch* (A)" scratch-buffer "*scratch*"))) + ;; verify that the matching criteria cannot be subverted + (should-not (persp-test-match-scratch-buffers "*scratch*" "*scratch* " "*scratch* (A)")) + (should (get-buffer-create "*scratch* ")) + (setq matched-buffers (list scratch-buffer (get-buffer "*scratch* ") scratch-buffer-A)) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch*" "*scratch* " "*scratch* (A)"))) + (should (equal matched-buffers (persp-test-match-scratch-buffers "*scratch* (A)" "*scratch*" "*scratch* ")))) + ;; Cleanup *scratch* buffers. + (mapc (lambda (buffer) + (when (string-match-p "^\\*scratch\\*.*$" (buffer-name buffer)) + (kill-buffer buffer))) + (buffer-list)) + (should (get-buffer-create "*scratch*")))) + (ert-deftest basic-persp-header-line-format-default-value () "Disabling `persp-mode' should properly restore the default value of `header-line-format'. |
