blob: d12ac1676c6b9c0907f1b7a419004862b24b5589 (
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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
|
;;; test-flyspell-config-functions.el --- -*- lexical-binding: t; -*-
;;; Commentary:
;; Evaluate the buffer, then run (ert-all-tests).
;;; Code:
(add-to-list 'load-path (concat user-emacs-directory "modules"))
(require 'flyspell-and-abbrev)
;; --------------------------- Flyspell Overlay Tests --------------------------
(ert-deftest cj/flyspell-overlay-test-positive ()
"Simplest positive test for \='cj/find-previous-flyspell-overlay\='.
With one misspelling, cj/find-previous-flyspell-overlay should return the
character position at the beginning of the misspelled word."
(with-temp-buffer
(let ((misspelled "mispeled")
(overlay-pos))
;; insert some text
(insert (format "some text for testing. %s" misspelled))
;; trigger flyspell and wait for it to complete
(flyspell-buffer)
(sit-for 1)
;; call the function with position at end of the buffer
(setq overlay-pos (cj/find-previous-flyspell-overlay (point-max)))
;; test flyspell-auto-correct-previous-pos is at char position of 'mispeled'.
(should (eq (- (point-max) (length misspelled)) overlay-pos)))))
(ert-deftest cj/flyspell-overlay-test-negative ()
"Simplest negative test for \='cj/find-previous-flyspell-overlay\='.
With no misspelled words, cj/find-previous-flyspell-overlay should return nil."
(with-temp-buffer
(insert "This is a correctly spelled sentence.")
(flyspell-buffer)
;; No overlay should exist, so test the result is nil.
(should-not (cj/find-previous-flyspell-overlay (point-max)))))
(ert-deftest cj/flyspell-overlay-test-positive-multiple ()
"Positive test for \='cj/find-previous-flyspell-overlay\='.
With several misspellings above and below, cj/find-previous-flyspell-overlay
should return the character position at the beginning of the previous misspelled
word."
(with-temp-buffer
(let ((misspelled0 "incorect")
(misspelled1 "wrongg")
(misspelled2 "erroor")
(misspelled3 "mistken")
(actual-pos)
(expected-pos)
(between-pos))
;; insert some text with misspellings
(insert (format "flyspell should catch this: %s" misspelled0))
(insert (format "flyspell should catch this: %s" misspelled1))
;; calculate the overlay's expected position based on our current position
(setq expected-pos (- (point) (length misspelled1)))
;; calculate a position in between misspellings
(setq between-pos (+ expected-pos (length misspelled1) 5))
;; insert the rest of the misspellings
(insert (format "flyspell should catch this: %s" misspelled2))
(insert (format "flyspell should catch this: %s" misspelled3))
;; trigger Flyspell and wait for it to identify all misspellings.
(flyspell-buffer)
(sit-for 1)
;; call the function with position in between misspellings
(setq actual-pos (cj/find-previous-flyspell-overlay between-pos))
(should (eq expected-pos actual-pos)))))
(ert-deftest cj/flyspell-goto-previous-misspelling-positive ()
"Positive test for \='cj/flyspell-goto-previous-misspelling\='.
With a simple misspelling above, cj/flyspell-goto-previous-misspelling
should land on the next misspelled word."
(with-temp-buffer
(let ((misspelled-word "incorect")
(actual-word))
;; insert some text with misspellings
(insert (format "flyspell should catch this: %s" misspelled-word))
;; trigger Flyspell and wait for it to identify all misspellings.
(flyspell-buffer)
(sit-for 1)
;; call the function with position in between misspellings
(setq actual-word (cj/flyspell-goto-previous-misspelling (point-max)))
(should (string= misspelled-word actual-word)))))
(ert-deftest cj/flyspell-goto-previous-misspelling-negative ()
"Negative test for \='cj/flyspell-goto-previous-misspelling\='.
With no misspellings, cj/flyspell-goto-previous-misspelling return nil."
(with-temp-buffer
(let ((expected nil)
(result))
;; insert some text with misspellings
(insert (format "None of these words are misspelled."))
;; trigger Flyspell and wait for it to identify all misspellings.
(flyspell-buffer)
(sit-for 1)
;; call the function with position in between misspellings
(setq result (cj/flyspell-goto-previous-misspelling (point-max)))
(message "result is %s" result)
(should (eq result expected)))))
(ert-deftest cj/flyspell-goto-previous-misspelling-positive-multiple ()
"Positive test for \='cj/flyspell-goto-previous-misspelling\='.
With several misspellings above and below, cj/flyspell-goto-previous-misspelling
should return the misspelled word just previous to the position of the cursor."
(with-temp-buffer
(let ((misspelled0 "incorect")
(misspelled1 "wrongg")
(misspelled2 "erroor")
(misspelled3 "mistken")
(result)
(between-pos))
;; insert some text with misspellings
(insert (format "flyspell should catch this: %s\n" misspelled0))
(insert (format "flyspell should catch this: %s\n" misspelled1))
;; calculate a position in between misspellings
(setq between-pos (+ (point) (length misspelled1) 5))
;; insert the rest of the misspellings
(insert (format "flyspell should catch this: %s\n" misspelled2))
(insert (format "flyspell should catch this: %s\n" misspelled3))
;; trigger Flyspell and wait for it to identify all misspellings.
(flyspell-buffer)
(sit-for 1)
;; call the function with position in between misspellings
(setq result (cj/flyspell-goto-previous-misspelling between-pos))
(should (string= result misspelled1)))))
(provide 'test-flyspell-config-functions)
;;; test-flyspell-config-functions.el ends here.
|