Skip to content

Commit 9f2eff6

Browse files
authored
Merge pull request #600 from rswgnu/add-more-hywiki-tests
add more hywiki tests
2 parents 3555e54 + aecb4ec commit 9f2eff6

File tree

2 files changed

+145
-13
lines changed

2 files changed

+145
-13
lines changed

ChangeLog

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2024-11-10 Mats Lidell <[email protected]>
2+
3+
* test/hywiki-tests.el (hywiki-tests--add-hywiki-hooks)
4+
(hywiki-tests--remove-hywiki-hooks, with-hywiki-buttonize-hooks)
5+
(with-hywiki-buttonize-and-insert-hooks): Add functions and macros for
6+
mimicking redisplay hook behavior and use these in the highlighting tests.
7+
(hywiki-tests--face-property-for-wikiword-with-wikipage)
8+
(hywiki-tests--no-face-property-for-no-wikipage)
9+
(hywiki-tests--verify-face-property-when-editing-wikiword)
10+
(hywiki-tests--verify-face-property-when-editing-wikiword-first-char):
11+
Tests using the hook mimicking functions.
12+
13+
2024-11-02 Mats Lidell <[email protected]>
14+
15+
* test/hywiki-tests.el (hywiki-tests--word-is-p)
16+
(hywiki-tests--directory-edit)
17+
(hywiki-tests--verify-face-property-when-editing-wikiword)
18+
(hywiki-tests--verify-face-property-when-editing-wikiword-first-char): Add hywiki
19+
tests.
20+
21+
* test/hywiki-tests.el (hywiki-tests--word-is-p): Add hywiki test.
22+
123
2024-10-28 Bob Weiner <[email protected]>
224

325
* hibtypes.el (hywiki-existing-word): Call action with the singular version

test/hywiki-tests.el

+123-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Mats Lidell
44
;;
55
;; Orig-Date: 18-May-24 at 23:59:48
6-
;; Last-Mod: 18-Oct-24 at 22:44:05 by Mats Lidell
6+
;; Last-Mod: 10-Nov-24 at 23:05:28 by Mats Lidell
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -105,6 +105,13 @@
105105
(hywiki-mode -1)
106106
(hy-delete-dir-and-buffer hywiki-directory))))
107107

108+
(ert-deftest hywiki-tests--word-is-p ()
109+
"Verify `hywiki-word-is-p' identifies WikiWords."
110+
(should (hywiki-word-is-p "WikiWord"))
111+
(should (hywiki-word-is-p "WikiWord#section"))
112+
(should-not (hywiki-word-is-p "hy:WikiWord"))
113+
(should-not (hywiki-word-is-p "wikiWord")))
114+
108115
(ert-deftest hywiki-tests--maybe-at-wikiword-beginning ()
109116
"Verify `hywiki-maybe-at-wikiword-beginning' identifies if maybe at beginning of WikiWord."
110117
(with-temp-buffer
@@ -252,19 +259,61 @@ Both mod-time and checksum must be changed for a test to return true."
252259
;; Following three test cases for verifying proper face is some what
253260
;; experimental. They need to be run in interactive mode.
254261

262+
(defun hywiki-tests--add-hywiki-hooks ()
263+
"Enable all hywiki hook functions."
264+
(add-hook 'pre-command-hook 'hywiki-debuttonize-non-character-commands 95)
265+
(add-hook 'post-command-hook 'hywiki-buttonize-non-character-commands 95)
266+
(add-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands)
267+
(add-hook 'window-buffer-change-functions
268+
'hywiki-maybe-highlight-page-names-in-frame)
269+
(add-to-list 'yank-handled-properties
270+
'(hywiki-word-face . hywiki-highlight-on-yank)))
271+
272+
(defun hywiki-tests--remove-hywiki-hooks ()
273+
"Disable all hywiki hook functions."
274+
(remove-hook 'pre-command-hook 'hywiki-debuttonize-non-character-commands)
275+
(remove-hook 'post-command-hook 'hywiki-buttonize-non-character-commands)
276+
(remove-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands)
277+
(remove-hook 'window-buffer-change-functions
278+
'hywiki-maybe-highlight-page-names-in-frame)
279+
(setq yank-handled-properties
280+
(delete '(hywiki-word-face . hywiki-highlight-on-yank)
281+
yank-handled-properties)))
282+
283+
(defmacro with-hywiki-buttonize-hooks (&rest body)
284+
"Call BODY wrapped in hywiki hooks to simulate Emacs redisplay."
285+
(declare (indent 0) (debug t))
286+
`(progn
287+
(funcall 'hywiki-debuttonize-non-character-commands)
288+
(progn ,@body)
289+
(funcall 'hywiki-buttonize-non-character-commands)))
290+
291+
(defmacro with-hywiki-buttonize-and-insert-hooks (&rest body)
292+
"Call BODY wrapped in hywiki hooks to simulate Emacs redisplay."
293+
(declare (indent 0) (debug t))
294+
`(progn
295+
(funcall 'hywiki-debuttonize-non-character-commands)
296+
(progn ,@body)
297+
(funcall 'hywiki-buttonize-character-commands)
298+
(funcall 'hywiki-buttonize-non-character-commands)))
299+
255300
(ert-deftest hywiki-tests--face-property-for-wikiword-with-wikipage ()
256301
"Verify WikiWord for a wiki page gets face property hywiki-word-face."
257302
(skip-unless (not noninteractive))
258303
(let* ((hsys-org-enable-smart-keys t)
259304
(hywiki-directory (make-temp-file "hywiki" t))
260305
(wikipage (hywiki-add-page "WikiWord")))
261306
(unwind-protect
262-
(with-temp-buffer
263-
(hywiki-mode 1)
264-
(insert "WikiWord")
265-
(newline nil t)
266-
(goto-char 4)
267-
(should (hproperty:but-get (point) 'face hywiki-word-face)))
307+
(progn
308+
(hywiki-tests--remove-hywiki-hooks)
309+
(with-temp-buffer
310+
(hywiki-mode 1)
311+
(with-hywiki-buttonize-and-insert-hooks
312+
(insert "WikiWord")
313+
(newline nil t))
314+
(goto-char 4)
315+
(should (hproperty:but-get (point) 'face hywiki-word-face))))
316+
(hywiki-tests--add-hywiki-hooks)
268317
(hywiki-mode 0)
269318
(hy-delete-file-and-buffer wikipage)
270319
(hy-delete-dir-and-buffer hywiki-directory))))
@@ -275,12 +324,73 @@ Both mod-time and checksum must be changed for a test to return true."
275324
(let* ((hsys-org-enable-smart-keys t)
276325
(hywiki-directory (make-temp-file "hywiki" t)))
277326
(unwind-protect
278-
(with-temp-buffer
279-
(hywiki-mode 0)
280-
(insert "WikiWord")
281-
(newline nil t)
282-
(goto-char 4)
283-
(should-not (hproperty:but-get (point) 'face hywiki-word-face)))
327+
(progn
328+
(hywiki-tests--remove-hywiki-hooks)
329+
(with-temp-buffer
330+
(hywiki-mode 0)
331+
(with-hywiki-buttonize-and-insert-hooks
332+
(insert "WikiWord")
333+
(newline nil t))
334+
(goto-char 4)
335+
(should-not (hproperty:but-get (point) 'face hywiki-word-face))))
336+
(hywiki-tests--add-hywiki-hooks)
337+
(hy-delete-dir-and-buffer hywiki-directory))))
338+
339+
(ert-deftest hywiki-tests--verify-face-property-when-editing-wikiword ()
340+
"Verify face property changes when WikiWord is edited."
341+
(skip-unless (not noninteractive))
342+
(let* ((hywiki-directory (make-temp-file "hywiki" t))
343+
(wikipage (hywiki-add-page "WikiWord")))
344+
(unwind-protect
345+
(progn
346+
(hywiki-tests--remove-hywiki-hooks)
347+
(with-temp-buffer
348+
(hywiki-mode 1)
349+
(with-hywiki-buttonize-and-insert-hooks (insert "Wikiord "))
350+
(goto-char 5)
351+
(should (looking-at-p "ord"))
352+
(should-not (hproperty:but-get (point) 'face hywiki-word-face))
353+
354+
(with-hywiki-buttonize-and-insert-hooks (insert "W"))
355+
(goto-char 5)
356+
(should (looking-at-p "Word"))
357+
(should (hproperty:but-get (point) 'face hywiki-word-face))
358+
359+
(with-hywiki-buttonize-and-insert-hooks (delete-char 1))
360+
(should (looking-at-p "ord"))
361+
(should-not (hproperty:but-get (point) 'face hywiki-word-face))))
362+
(hywiki-tests--add-hywiki-hooks)
363+
(hywiki-mode 0)
364+
(hy-delete-files-and-buffers (list wikipage))
365+
(hy-delete-dir-and-buffer hywiki-directory))))
366+
367+
(ert-deftest hywiki-tests--verify-face-property-when-editing-wikiword-first-char ()
368+
"Verify face property changes when WikiWord is edited in the first char position."
369+
:expected-result :failed
370+
(let* ((hywiki-directory (make-temp-file "hywiki" t))
371+
(wikipage (hywiki-add-page "WikiWord")))
372+
(skip-unless (not noninteractive))
373+
(unwind-protect
374+
(progn
375+
(hywiki-tests--remove-hywiki-hooks)
376+
(with-temp-buffer
377+
(hywiki-mode 1)
378+
(with-hywiki-buttonize-and-insert-hooks (insert "WikiWord "))
379+
(goto-char 1)
380+
(should (looking-at-p "Wiki"))
381+
(should (hproperty:but-get (point) 'face hywiki-word-face))
382+
383+
(with-hywiki-buttonize-and-insert-hooks (delete-char 1))
384+
(should (looking-at-p "iki"))
385+
(should-not (hproperty:but-get (point) 'face hywiki-word-face))
386+
387+
(with-hywiki-buttonize-and-insert-hooks (insert "W"))
388+
(goto-char 1)
389+
(should (looking-at-p "Wiki"))
390+
(should (hproperty:but-get (point) 'face hywiki-word-face))))
391+
(hywiki-tests--add-hywiki-hooks)
392+
(hywiki-mode 0)
393+
(hy-delete-files-and-buffers (list wikipage))
284394
(hy-delete-dir-and-buffer hywiki-directory))))
285395

286396
(ert-deftest hywiki-tests--convert-words-to-org-link ()

0 commit comments

Comments
 (0)