summaryrefslogtreecommitdiff
path: root/test/cider-overlay-tests.el
blob: 16c2d08f5297634101c3c8ea63a408361f05b5df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; cider-overlay-tests.el                       -*- lexical-binding: t; -*-

;; Copyright © 2015-2019 Bozhidar Batsov, Artur Malabarba and CIDER contributors

;; Author: Artur Malabarba <bruce.connor.am@gmail.com>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Code:

(require 'buttercup)
(require 'cider-overlays)

(defmacro cider--with-overlay (overlay-args &rest body)
  "Run BODY in a temp buffer, with overlays created."
  (declare (indent 1)
           (debug (sexp sexp &rest form)))
  `(with-temp-buffer
     (insert "garbage")
     (save-excursion (insert "\nmore trash"))
     (cider--make-result-overlay ,@overlay-args)
     ,@body))


(describe "cider--make-result-overlay"
  :var (overlay-position this-command)

  (before-all
    (fset 'overlay-position (lambda ()
                              (mapcar #'overlay-start
                                      (overlays-at (point-min))))))

  (it "can create overlays"
    (cider--with-overlay ("ok")
      (expect (overlays-at (point-min)) :to-be-truthy)))

  (describe "when overlay duration is `command`"
    (it "erases overlays after the next command is executed"
      (cider--with-overlay ("ok" :duration 'command)
        (run-hooks 'post-command-hook)
        (run-hooks 'post-command-hook)
        (expect (overlay-position) :to-equal nil))

      (cider--with-overlay ("ok" :duration 'command)
        (setq this-command nil)
        (run-hooks 'post-command-hook)
        (expect (overlay-position) :to-equal nil))))

  (describe "when overlay duration is given in secs"
    (it "erases overlays after that duration"
      (cider--with-overlay ("ok" :duration 1.5)
        (sleep-for 1)
        (expect (overlay-position) :not :to-equal nil)
        (sleep-for 1)
        (expect (overlay-position) :to-equal nil)))))

(describe "cider--delete-overlay"
  :var (overlay-position)
  (it "deletes overlays"
    (cider--with-overlay ("ok")
      (mapc #'cider--delete-overlay (overlays-at (point-min)))
      (setq overlay-position (mapcar #'overlay-start (overlays-at (point-min))))
      (expect overlay-position :to-equal nil))))

(provide 'cider-overlay-tests)
;;; cider-overlay-tests.el ends here