]> code.delx.au - gnu-emacs-elpa/blob - test/context-coloring-test.el
Use old advice for Emacs 24.3.
[gnu-emacs-elpa] / test / context-coloring-test.el
1 ;;; context-coloring-test.el --- Tests for context coloring -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2014-2015 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21
22 ;; Tests for context coloring.
23
24 ;; Use with `make test'.
25
26 ;;; Code:
27
28 (require 'cl-lib)
29 (require 'context-coloring)
30 (require 'ert)
31 (require 'js2-mode)
32
33
34 ;;; Test running utilities
35
36 (defconst context-coloring-test-path
37 (file-name-directory (or load-file-name buffer-file-name))
38 "This file's directory.")
39
40 (defun context-coloring-test-read-file (path)
41 "Return the file's contents from PATH as a string."
42 (with-temp-buffer
43 (insert-file-contents (expand-file-name path context-coloring-test-path))
44 (buffer-string)))
45
46 (defmacro context-coloring-test-with-fixture (fixture &rest body)
47 "With the relative FIXTURE, evaluate BODY in a temporary
48 buffer."
49 `(with-temp-buffer
50 (progn
51 (insert (context-coloring-test-read-file ,fixture))
52 ,@body)))
53
54
55 ;;; Test defining utilities
56
57 (cl-defmacro context-coloring-test-define-deftest (name
58 &key mode
59 &key extension
60 &key no-fixture
61 &key enable-context-coloring-mode
62 &key before-each
63 &key after-each)
64 "Define a deftest defmacro for tests prefixed with NAME. MODE
65 is called to set up tests' environments. EXTENSION denotes the
66 suffix for tests' fixture files. If NO-FIXTURE is non-nil, don't
67 use a fixture. If ENABLE-CONTEXT-COLORING-MODE is non-nil,
68 `context-coloring-mode' is activated before tests. Functions
69 BEFORE-EACH and AFTER-EACH run before the major mode is activated
70 before each test, and after each test, even if an error is
71 signaled."
72 (declare (indent defun))
73 (let ((macro-name (intern (format "context-coloring-test-deftest%s"
74 (cond
75 ;; No name means no dash.
76 ((eq name nil) "")
77 (t (format "-%s" name)))))))
78 `(cl-defmacro ,macro-name (name
79 body
80 &key fixture
81 &key before
82 &key after)
83 (declare (indent defun))
84 ;; Commas in nested backquotes are not evaluated. Binding the variables
85 ;; here is probably the cleanest workaround.
86 (let ((mode ,mode)
87 (before-each ',before-each)
88 (after-each ',after-each)
89 (test-name (intern (format ,(format "%s-%%s"
90 (cond
91 (name)
92 (t "generic"))) name)))
93 (fixture (cond
94 (fixture (format "./fixtures/%s" fixture))
95 (,no-fixture "./fixtures/empty")
96 (t (format ,(format "./fixtures/%%s.%s" extension) name)))))
97 ,@`((let ((enable-context-coloring-mode ,enable-context-coloring-mode))
98 `(ert-deftest ,test-name ()
99 (context-coloring-test-with-fixture
100 ,fixture
101 (when ,before-each (funcall ,before-each))
102 (,mode)
103 (when ,before (funcall ,before))
104 (when ,enable-context-coloring-mode (context-coloring-mode))
105 (unwind-protect
106 (progn
107 (funcall ,body))
108 (when ,after (funcall ,after))
109 (when ,after-each (funcall ,after-each)))))))))))
110
111 (context-coloring-test-define-deftest nil
112 :mode #'fundamental-mode
113 :no-fixture t)
114
115 (context-coloring-test-define-deftest javascript
116 :mode #'js2-mode
117 :extension "js"
118 :enable-context-coloring-mode t
119 :before-each (lambda ()
120 (setq js2-mode-show-parse-errors nil)
121 (setq js2-mode-show-strict-warnings nil)))
122
123 (context-coloring-test-define-deftest emacs-lisp
124 :mode #'emacs-lisp-mode
125 :extension "el"
126 :enable-context-coloring-mode t)
127
128 (context-coloring-test-define-deftest eval-expression
129 :mode #'fundamental-mode
130 :no-fixture t)
131
132
133 ;;; Assertion functions
134
135 (defun context-coloring-test-get-last-message ()
136 "Get the last message in the current messages bufffer."
137 (let ((messages (split-string
138 (buffer-substring-no-properties
139 (point-min)
140 (point-max))
141 "\n")))
142 (car (nthcdr (- (length messages) 2) messages))))
143
144 (defun context-coloring-test-assert-message (expected buffer)
145 "Assert that message EXPECTED is at the end of BUFFER."
146 (when (null (get-buffer buffer))
147 (ert-fail
148 (format
149 (concat
150 "Expected buffer `%s' to have message \"%s\", "
151 "but the buffer did not have any messages.")
152 buffer expected)))
153 (with-current-buffer buffer
154 (let ((message (context-coloring-test-get-last-message)))
155 (when (not (equal message expected))
156 (ert-fail
157 (format
158 (concat
159 "Expected buffer `%s' to have message \"%s\", "
160 "but instead it was \"%s\"")
161 buffer expected
162 message))))))
163
164 (defun context-coloring-test-assert-not-message (expected buffer)
165 "Assert that message EXPECTED is not at the end of BUFFER."
166 (when (get-buffer buffer)
167 (with-current-buffer buffer
168 (let ((message (context-coloring-test-get-last-message)))
169 (when (equal message expected)
170 (ert-fail
171 (format
172 (concat
173 "Expected buffer `%s' not to have message \"%s\", "
174 "but it did")
175 buffer expected)))))))
176
177 (defun context-coloring-test-assert-error (body error-message)
178 "Assert that BODY signals ERROR-MESSAGE."
179 (let ((error-signaled-p nil))
180 (condition-case err
181 (progn
182 (funcall body))
183 (error
184 (setq error-signaled-p t)
185 (when (not (string-equal (cadr err) error-message))
186 (ert-fail (format (concat "Expected the error \"%s\" to be thrown, "
187 "but instead it was \"%s\".")
188 error-message
189 (cadr err))))))
190 (when (not error-signaled-p)
191 (ert-fail "Expected an error to be thrown, but there wasn't."))))
192
193
194 ;;; Miscellaneous tests
195
196 (defmacro context-coloring-test-define-derived-mode (name)
197 "Define a derived mode exclusively for any test with NAME."
198 (let ((name (intern (format "context-coloring-test-%s-mode" name))))
199 `(define-derived-mode ,name fundamental-mode "Testing")))
200
201 (defvar context-coloring-test-caused-p nil
202 "Dumb flag tracking for lambdas inside old advice definitions
203 which don't seem to have lexical binding.")
204
205 (defmacro context-coloring-test-assert-causes-coloring (&rest body)
206 "Assert that BODY causes coloring."
207 `(progn
208 ;; Gross, but I want this to pass on 24.3.
209 (ad-add-advice #'context-coloring-colorize
210 '(assert-causes-coloring
211 nil t
212 (advice . (lambda ()
213 (setq context-coloring-test-caused-p t))))
214 'after
215 0)
216 (ad-activate #'context-coloring-colorize)
217 ,@body
218 (when (not context-coloring-test-caused-p)
219 (ert-fail "Expected to have colorized, but it didn't."))))
220
221 (defun context-coloring-test-cleanup-assert-causes-coloring ()
222 (ad-unadvise #'context-coloring-colorize)
223 (setq context-coloring-test-caused-p nil))
224
225 (context-coloring-test-define-derived-mode mode-startup)
226
227 (context-coloring-test-deftest mode-startup
228 (lambda ()
229 (context-coloring-define-dispatch
230 'mode-startup
231 :modes '(context-coloring-test-mode-startup-mode)
232 :colorizer #'ignore)
233 (context-coloring-test-mode-startup-mode)
234 (context-coloring-test-assert-causes-coloring
235 (context-coloring-mode)))
236 :after (lambda ()
237 (context-coloring-test-cleanup-assert-causes-coloring)))
238
239 (context-coloring-test-define-derived-mode change-detection)
240
241 (context-coloring-test-deftest change-detection
242 (lambda ()
243 (context-coloring-define-dispatch
244 'idle-change
245 :modes '(context-coloring-test-change-detection-mode)
246 :colorizer #'ignore
247 :setup #'context-coloring-setup-idle-change-detection
248 :teardown #'context-coloring-teardown-idle-change-detection)
249 (context-coloring-test-change-detection-mode)
250 (context-coloring-mode)
251 (context-coloring-test-assert-causes-coloring
252 (insert " ")
253 ;; Simply cannot figure out how to trigger an idle timer; would much rather
254 ;; test that. But (current-idle-time) always returns nil in these tests.
255 (context-coloring-maybe-colorize-with-buffer (current-buffer))))
256 :after (lambda ()
257 (context-coloring-test-cleanup-assert-causes-coloring)))
258
259 (context-coloring-test-deftest unsupported-mode
260 (lambda ()
261 (context-coloring-mode)
262 (context-coloring-test-assert-message
263 "Context coloring is not available for this major mode"
264 "*Messages*")))
265
266 (context-coloring-test-deftest derived-mode
267 (lambda ()
268 (lisp-interaction-mode)
269 (context-coloring-mode)
270 (context-coloring-test-assert-not-message
271 "Context coloring is not available for this major mode"
272 "*Messages*")))
273
274 (context-coloring-test-define-derived-mode define-dispatch-error)
275
276 (context-coloring-test-deftest define-dispatch-error
277 (lambda ()
278 (context-coloring-test-assert-error
279 (lambda ()
280 (context-coloring-define-dispatch
281 'define-dispatch-no-modes))
282 "No mode or predicate defined for dispatch")
283 (context-coloring-test-assert-error
284 (lambda ()
285 (context-coloring-define-dispatch
286 'define-dispatch-no-strategy
287 :modes '(context-coloring-test-define-dispatch-error-mode)))
288 "No colorizer defined for dispatch")))
289
290 (context-coloring-test-define-derived-mode disable-mode)
291
292 (context-coloring-test-deftest disable-mode
293 (lambda ()
294 (let (torn-down)
295 (context-coloring-define-dispatch
296 'disable-mode
297 :modes '(context-coloring-test-disable-mode-mode)
298 :colorizer #'ignore
299 :teardown (lambda ()
300 (setq torn-down t)))
301 (context-coloring-test-disable-mode-mode)
302 (context-coloring-mode)
303 (context-coloring-mode -1)
304 (when (not torn-down)
305 (ert-fail "Expected teardown function to have been called, but it wasn't.")))))
306
307
308 ;;; Coloring tests
309
310 (defun context-coloring-test-assert-position-level (position level)
311 "Assert that POSITION has LEVEL."
312 (let ((face (get-text-property position 'face))
313 actual-level)
314 (when (not (and face
315 (let* ((face-string (symbol-name face))
316 (matches (string-match
317 "context-coloring-level-\\([[:digit:]]+\\)-face"
318 face-string)))
319 (when matches
320 (setq actual-level (string-to-number
321 (substring face-string
322 (match-beginning 1)
323 (match-end 1))))
324 (= level actual-level)))))
325 (ert-fail (format (concat "Expected level at position %s, "
326 "which is \"%s\", to be %s; "
327 "but it was %s")
328 position
329 (buffer-substring-no-properties position (1+ position)) level
330 actual-level)))))
331
332 (defun context-coloring-test-assert-position-face (position face-regexp)
333 "Assert that the face at POSITION satisfies FACE-REGEXP."
334 (let ((face (get-text-property position 'face)))
335 (when (or
336 ;; Pass a non-string to do an `equal' check (against a symbol or nil).
337 (unless (stringp face-regexp)
338 (not (equal face-regexp face)))
339 ;; Otherwise do the matching.
340 (when (stringp face-regexp)
341 (not (string-match-p face-regexp (symbol-name face)))))
342 (ert-fail (format (concat "Expected face at position %s, "
343 "which is \"%s\", to be %s; "
344 "but it was %s")
345 position
346 (buffer-substring-no-properties position (1+ position)) face-regexp
347 face)))))
348
349 (defun context-coloring-test-assert-position-comment (position)
350 "Assert that the face at POSITION is a comment."
351 (context-coloring-test-assert-position-face
352 position "\\`font-lock-comment\\(-delimiter\\)?-face\\'"))
353
354 (defun context-coloring-test-assert-position-constant-comment (position)
355 "Assert that the face at POSITION is a constant comment."
356 (context-coloring-test-assert-position-face position '(font-lock-constant-face
357 font-lock-comment-face)))
358
359 (defun context-coloring-test-assert-position-string (position)
360 "Assert that the face at POSITION is a string."
361 (context-coloring-test-assert-position-face position 'font-lock-string-face))
362
363 (defun context-coloring-test-assert-position-nil (position)
364 "Assert that the face at POSITION is nil."
365 (context-coloring-test-assert-position-face position nil))
366
367 (defun context-coloring-test-assert-coloring (map)
368 "Assert that the current buffer's coloring will match MAP.
369
370 MAP's newlines should correspond to the current fixture.
371
372 The following characters appearing in MAP assert coloring for
373 corresponding points in the fixture:
374
375 0-9: Level equals number.
376 C: Face is constant comment.
377 c: Face is comment.
378 n: Face is nil.
379 s: Face is string.
380
381 Any other characters are discarded. Characters \"x\" and any
382 other non-letters are guaranteed to always be discarded."
383 ;; Omit the superfluous, formatting-related leading newline. Can't use
384 ;; `save-excursion' here because if an assertion fails it will cause future
385 ;; tests to get messed up.
386 (goto-char (point-min))
387 (let* ((map (substring map 1))
388 (index 0)
389 char-string
390 char)
391 (while (< index (length map))
392 (setq char-string (substring map index (1+ index)))
393 (setq char (string-to-char char-string))
394 (cond
395 ;; Newline
396 ((= char 10)
397 (forward-line)
398 (beginning-of-line))
399 ;; Number
400 ((and (>= char 48)
401 (<= char 57))
402 (context-coloring-test-assert-position-level
403 (point) (string-to-number char-string))
404 (forward-char))
405 ;; 'C' = Constant comment
406 ((= char 67)
407 (context-coloring-test-assert-position-constant-comment (point))
408 (forward-char))
409 ;; 'c' = Comment
410 ((= char 99)
411 (context-coloring-test-assert-position-comment (point))
412 (forward-char))
413 ;; 'n' = nil
414 ((= char 110)
415 (context-coloring-test-assert-position-nil (point))
416 (forward-char))
417 ;; 's' = String
418 ((= char 115)
419 (context-coloring-test-assert-position-string (point))
420 (forward-char))
421 (t
422 (forward-char)))
423 (setq index (1+ index)))))
424
425 (context-coloring-test-deftest-javascript function-scopes
426 (lambda ()
427 (context-coloring-test-assert-coloring "
428 000 0 0 11111111 11 110
429 11111111 011 1
430 111 1 1 22222222 22 221
431 22222222 122 22
432 1")))
433
434 (context-coloring-test-deftest-javascript global
435 (lambda ()
436 (context-coloring-test-assert-coloring "
437 (xxxxxxxx () {
438 111 1 1 00000001xxx11
439 }());")))
440
441 (context-coloring-test-deftest-javascript block-scopes
442 (lambda ()
443 (context-coloring-test-assert-coloring "
444 (xxxxxxxx () {
445 11 111 2
446 222 12
447 222 22
448 2
449 }());"))
450 :before (lambda ()
451 (setq context-coloring-javascript-block-scopes t))
452 :after (lambda ()
453 (setq context-coloring-javascript-block-scopes nil)))
454
455 (context-coloring-test-deftest-javascript catch
456 (lambda ()
457 (context-coloring-test-assert-coloring "
458 (xxxxxxxx () {
459 111 11 22222 222 2
460 222 1 2 22
461 222 22 33333 333 3
462 333 1 3 33
463 3
464 2
465 }());")))
466
467 (context-coloring-test-deftest-javascript key-names
468 (lambda ()
469 (context-coloring-test-assert-coloring "
470 (xxxxxxxx () {
471 111111 1
472 11 11
473 1 1 1
474 11
475 }());")))
476
477 (context-coloring-test-deftest-javascript property-lookup
478 (lambda ()
479 (context-coloring-test-assert-coloring "
480 (xxxxxxxx () {
481 0000001111111
482 0000001 111111
483 00000011111111111
484 }());")))
485
486 (context-coloring-test-deftest-javascript key-values
487 (lambda ()
488 (context-coloring-test-assert-coloring "
489 (xxxxxxxx () {
490 xxx x;
491 (xxxxxxxx () {
492 xxxxxx {
493 x: 1
494 };
495 }());
496 }());")))
497
498 (context-coloring-test-deftest-javascript syntactic-comments-and-strings
499 (lambda ()
500 (context-coloring-test-assert-coloring "
501 0000 00
502 ccccccc
503 cccccccccc
504 ssssssssssss0"))
505 :fixture "comments-and-strings.js")
506
507 (context-coloring-test-deftest-javascript syntactic-comments
508 (lambda ()
509 (context-coloring-test-assert-coloring "
510 0000 00
511 ccccccc
512 cccccccccc
513 0000000000000"))
514 :fixture "comments-and-strings.js"
515 :before (lambda ()
516 (setq context-coloring-syntactic-strings nil))
517 :after (lambda ()
518 (setq context-coloring-syntactic-strings t)))
519
520 (context-coloring-test-deftest-javascript syntactic-strings
521 (lambda ()
522 (context-coloring-test-assert-coloring "
523 0000 00
524 0000000
525 0000000000
526 ssssssssssss0"))
527 :fixture "comments-and-strings.js"
528 :before (lambda ()
529 (setq context-coloring-syntactic-comments nil))
530 :after (lambda ()
531 (setq context-coloring-syntactic-comments t)))
532
533 (context-coloring-test-deftest-javascript unterminated-comment
534 ;; As long as `add-text-properties' doesn't signal an error, this test passes.
535 (lambda ()))
536
537 (context-coloring-test-deftest-emacs-lisp defun
538 (lambda ()
539 (context-coloring-test-assert-coloring "
540 111111 000 1111 111 111111111 1111
541 11 111 111 111 000011
542
543 0000 0 0 00
544
545 111111 01
546 111111 111
547 111111 0 1sss11")))
548
549 (context-coloring-test-deftest-emacs-lisp defadvice
550 (lambda ()
551 (context-coloring-test-assert-coloring "
552 1111111111 0 1111111 111111 11111 111 111111111
553 2222 222 122
554 22 1 2221")))
555
556 (context-coloring-test-deftest-emacs-lisp lambda
557 (lambda ()
558 (context-coloring-test-assert-coloring "
559 00000000 1111111 1111
560 11111111 11 2222222 2222
561 222 22 12 2221 111 0 00")))
562
563 (context-coloring-test-deftest-emacs-lisp quote
564 (lambda ()
565 (context-coloring-test-assert-coloring "
566 (xxxxx 0000000 00 00000)
567 (xxx () (xxxxxxxxx (,0000)))
568
569 (xxxxx x (x)
570 (xx (xx x 111
571 111111 1 111 111
572 111111 1 1111111111 11 111 1 111 1 00001 10000 11 00001 1 10000
573 sss ccc
574 1111
575
576 (xxxxxx '(sss cc
577 sss cc
578 ))
579
580 (xxxxxx () 111111 11111)")))
581
582 (context-coloring-test-deftest-emacs-lisp splice
583 (lambda ()
584 (context-coloring-test-assert-coloring "
585 (xxxxxx ()
586 111111 00001 100001)")))
587
588 (context-coloring-test-deftest-emacs-lisp comment
589 (lambda ()
590 ;; Just check that the comment isn't parsed syntactically.
591 (context-coloring-test-assert-coloring "
592 (xxxxx x ()
593 (xx (x xxxxx-xxxx xx) cccccccccc
594 11 00000-0000 11))) cccccccccc")))
595
596 (context-coloring-test-deftest-emacs-lisp string
597 (lambda ()
598 (context-coloring-test-assert-coloring "
599 (xxxxx x (x)
600 (xxxxxx x x sss 1 0 sssss 0 1 sssssss11")))
601
602 (context-coloring-test-deftest-emacs-lisp ignored
603 (lambda ()
604 (context-coloring-test-assert-coloring "
605 (xxxxx x ()
606 (x x 1 11 11 111 111 11 11 11 1 111 (1 1 1)))")))
607
608 (context-coloring-test-deftest-emacs-lisp sexp
609 (lambda ()
610 (context-coloring-test-assert-coloring "
611 (xxx ()
612 `,@sss
613 `,@11
614 `,@11)")))
615
616 (context-coloring-test-deftest-emacs-lisp let
617 (lambda ()
618 (context-coloring-test-assert-coloring "
619 1111 11
620 11 01
621 11 00001
622 11 2222 22
623 22 02
624 22 000022
625 2222 2 2 2 00002211
626 1111 1 1 1 000011
627
628 1111 cc ccccccc
629 1sss11")))
630
631 (context-coloring-test-deftest-emacs-lisp let*
632 (lambda ()
633 (context-coloring-test-assert-coloring "
634 11111 11
635 11 11
636 11 000011
637 1111 1 1 1 0 0 00001
638 22222 22
639 22 12
640 22 00002
641 22 02
642 22 222
643 2222 1 1 2 2 2 000022
644 1111 1 1 1 0 0 000011")))
645
646 (context-coloring-test-deftest-emacs-lisp cond
647 (lambda ()
648 (context-coloring-test-assert-coloring "
649 (xxx (x)
650 11111
651 11 11
652 10000 11
653 1111 1 00001 11
654 11 11111 1 000011
655 cc c
656 sss1)")))
657
658 (context-coloring-test-deftest-emacs-lisp condition-case
659 (lambda ()
660 (context-coloring-test-assert-coloring "
661 1111111111-1111 111
662 111111 000 00001
663 111111 111 00001
664 1111111 111111 111 000011
665
666 (111111111-1111-111111-11111 111
667 cc c
668 (xxx () 222)
669 (11111 (xxx () 222))
670 sss)")))
671
672 (context-coloring-test-deftest-emacs-lisp dolist
673 (lambda ()
674 (context-coloring-test-assert-coloring "
675 1111111 111111
676 2222222 2222 1111 2222222
677 3333333 33 33 222 1111 2222223321")))
678
679 (defun context-coloring-test-insert-unread-space ()
680 "Simulate the insertion of a space as if by a user."
681 (setq unread-command-events (cons '(t . 32)
682 unread-command-events)))
683
684 (defun context-coloring-test-remove-faces ()
685 "Remove all faces in the current buffer."
686 (remove-text-properties (point-min) (point-max) '(face nil)))
687
688 (context-coloring-test-deftest-emacs-lisp iteration
689 (lambda ()
690 (let ((context-coloring-elisp-sexps-per-pause 2))
691 (context-coloring-colorize)
692 (context-coloring-test-assert-coloring "
693 cc `CC' `CC'
694 (xxxxx x ())")
695 (context-coloring-test-remove-faces)
696 (context-coloring-test-insert-unread-space)
697 (context-coloring-colorize)
698 ;; Coloring is interrupted after the first "sexp" (the comment in this
699 ;; case).
700 (context-coloring-test-assert-coloring "
701 cc `CC' `CC'
702 nnnnnn n nnn"))))
703
704 (context-coloring-test-deftest-emacs-lisp changed
705 (lambda ()
706 (context-coloring-test-remove-faces)
707 ;; Goto line 3.
708 (goto-char (point-min))
709 (forward-line (1- 3))
710 (insert " ")
711 ;; Mock `pos-visible-in-window-p' because in batch mode `get-buffer-window'
712 ;; returns nil. Emacs must not have a window in that environment.
713 (cl-letf (((symbol-function 'pos-visible-in-window-p)
714 (let ((calls 0))
715 (lambda ()
716 (prog1
717 ;; First and third calls start from center. Second and
718 ;; fourth calls are made immediately after moving past
719 ;; the first defun in either direction "off screen".
720 (cond
721 ((= calls 0) t)
722 ((= calls 1) nil)
723 ((= calls 2) t)
724 ((= calls 4) nil))
725 (setq calls (1+ calls)))))))
726 (context-coloring-colorize))
727 (context-coloring-test-assert-coloring "
728 nnnn n nnn nnnnnnnn
729 0000
730
731 0000
732 nnnnn n nnn nnnnnnnn")))
733
734 (context-coloring-test-deftest-emacs-lisp unbalanced-parenthesis
735 (lambda ()
736 (context-coloring-test-assert-coloring "
737 1111 111
738 nnnn nn")))
739
740 (context-coloring-test-deftest-eval-expression let
741 (lambda ()
742 (minibuffer-with-setup-hook
743 (lambda ()
744 ;; Perform the test in a hook as it's the only way I know of examining
745 ;; the minibuffer's contents. The contents are implicitly submitted,
746 ;; so we have to ignore the errors in the arbitrary test subject code.
747 (insert "(ignore-errors (let (a) (message a free)))")
748 (context-coloring-colorize)
749 (context-coloring-test-assert-coloring "
750 xxxx: 0000000-000000 1111 111 11111111 1 0000110"))
751 ;; Simulate user input because `call-interactively' is blocking and
752 ;; doesn't seem to run the hook.
753 (execute-kbd-macro
754 (vconcat
755 [?\C-u] ;; Don't output the result of the arbitrary test subject code.
756 [?\M-:])))))
757
758 (provide 'context-coloring-test)
759
760 ;;; context-coloring-test.el ends here