-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathbeginend-narrowing-test.el
136 lines (107 loc) · 4.33 KB
/
beginend-narrowing-test.el
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
;;; beginend-narrowing-test.el --- Tests beginend when narrowing is in effect -*- lexical-binding: t; -*-
;; Copyright (C) 2017-2023 Damien Cassou
;; Author: Damien Cassou <[email protected]>
;; Version: 2.4.0
;; URL: https://github.com/DamienCassou/beginend
;; Package-requires: ((emacs "25.3"))
;; 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/>.
;;; Commentary:
;; Tests beginend when narrowing is in effect.
;;; Code:
(load "test/test-helper")
(require 'assess)
(require 'buttercup)
(require 'beginend)
(define-error 'dont-call-me "This code should not have been called" 'error)
(defun beginend-narrowing-test--goto-begin ()
"Go to point 2."
(beginend--double-tap-begin
(goto-char 2)))
(defun beginend-narrowing-test--goto-end ()
"Go to point 2."
(beginend--double-tap-end
(goto-char 2)))
(describe "beginend, when narrowing is active,"
(before-each
(spy-on 'message)) ;; disable "Mark activated/Mark set" messages
(it "goes to point-min if beginning is outside the narrowed region"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(beginend-narrowing-test--goto-begin)
(expect (point) :to-be (point-min))))
(it "goes to beginning if beginning is inside the narrowed region"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 1 3)
(beginend-narrowing-test--goto-begin)
(expect (point) :to-be 2)))
(it "goes to point-max if end is outside the narrowed region"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(beginend-narrowing-test--goto-end)
(expect (point) :to-be (point-max))))
(it "goes to end if end is inside the narrowed region"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 1 3)
(beginend-narrowing-test--goto-end)
(expect (point) :to-be 2)))
(describe "does not move point"
(it "when going to beginning and beginning outside the narrowed region if point is already at point-min"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(goto-char (point-min))
(beginend-narrowing-test--goto-begin)
(expect (point) :to-be (point-min))))
(it "when going to end and end outside the narrowed region if point is already at point-max"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(goto-char (point-max))
(beginend-narrowing-test--goto-end)
(expect (point) :to-be (point-max)))))
(describe "does not mark"
(it "when going to beginning and beginning outside the narrowed region if point is already at point-min"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(goto-char (point-min))
(beginend-narrowing-test--goto-begin)
(expect (mark) :to-be nil)))
(it "when going to end and end outside the narrowed region if point is already at point-max"
(with-temp-buffer
(insert "foo bar baz\n")
(narrow-to-region 3 5)
(goto-char (point-max))
(beginend-narrowing-test--goto-end)
(expect (mark) :to-be nil))))
(describe "correctly detects out of bounds"
(it "when point is before point-min"
(with-temp-buffer
(insert "123")
(expect (beginend--out-of-bounds-p 0) :to-be t)))
(it "when point is after point-max"
(with-temp-buffer
(insert "123")
(expect (beginend--out-of-bounds-p 5) :to-be t)))
(it "when point is between point-min point-max"
(with-temp-buffer
(insert "123")
(expect (beginend--out-of-bounds-p 2) :to-be nil)))))
(provide 'beginend-narrowing-test)
;;; beginend-narrowing-test.el ends here
;; Local Variables:
;; nameless-current-name: "beginend-narrowing-test"
;; End: