3
3
; ; Author: Mats Lidell
4
4
; ;
5
5
; ; 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
7
7
; ;
8
8
; ; SPDX-License-Identifier: GPL-3.0-or-later
9
9
; ;
105
105
(hywiki-mode -1 )
106
106
(hy-delete-dir-and-buffer hywiki-directory))))
107
107
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
+
108
115
(ert-deftest hywiki-tests--maybe-at-wikiword-beginning ()
109
116
" Verify `hywiki-maybe-at-wikiword-beginning' identifies if maybe at beginning of WikiWord."
110
117
(with-temp-buffer
@@ -252,19 +259,61 @@ Both mod-time and checksum must be changed for a test to return true."
252
259
; ; Following three test cases for verifying proper face is some what
253
260
; ; experimental. They need to be run in interactive mode.
254
261
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
+
255
300
(ert-deftest hywiki-tests--face-property-for-wikiword-with-wikipage ()
256
301
" Verify WikiWord for a wiki page gets face property hywiki-word-face."
257
302
(skip-unless (not noninteractive))
258
303
(let* ((hsys-org-enable-smart-keys t )
259
304
(hywiki-directory (make-temp-file " hywiki" t ))
260
305
(wikipage (hywiki-add-page " WikiWord" )))
261
306
(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)
268
317
(hywiki-mode 0 )
269
318
(hy-delete-file-and-buffer wikipage)
270
319
(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."
275
324
(let* ((hsys-org-enable-smart-keys t )
276
325
(hywiki-directory (make-temp-file " hywiki" t )))
277
326
(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))
284
394
(hy-delete-dir-and-buffer hywiki-directory))))
285
395
286
396
(ert-deftest hywiki-tests--convert-words-to-org-link ()
0 commit comments