]> code.delx.au - gnu-emacs-elpa/blob - packages/context-coloring/test/context-coloring-test.el
Merge commit 'f062d5a55496e22cf89f2ef9778a24a840a5a68e' from context-coloring
[gnu-emacs-elpa] / packages / context-coloring / test / context-coloring-test.el
1 ;;; test/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 ;; Tests for both synchronous (elisp) and asynchronous (shell command) coloring
25 ;; are available. Basic plugin functionality is also tested.
26
27 ;; To run, execute `make test' from the project root.
28
29 ;;; Code:
30
31 (require 'context-coloring)
32 (require 'ert-async)
33 (require 'js2-mode)
34
35
36 ;;; Test running utilities
37
38 (defconst context-coloring-test-path
39 (file-name-directory (or load-file-name buffer-file-name))
40 "This file's directory.")
41
42 (defun context-coloring-test-read-file (path)
43 "Read a file's contents from PATH into a string."
44 (with-temp-buffer
45 (insert-file-contents (expand-file-name path context-coloring-test-path))
46 (buffer-string)))
47
48 (defun context-coloring-test-setup ()
49 "Prepare before all tests."
50 (setq context-coloring-comments-and-strings nil))
51
52 (defun context-coloring-test-cleanup ()
53 "Cleanup after all tests."
54 (setq context-coloring-comments-and-strings t)
55 (setq context-coloring-syntactic-comments nil)
56 (setq context-coloring-syntactic-strings nil)
57 (setq context-coloring-js-block-scopes nil))
58
59 (defmacro context-coloring-test-with-fixture (fixture &rest body)
60 "With the relative FIXTURE, evaluate BODY in a temporary
61 buffer."
62 `(with-temp-buffer
63 (unwind-protect
64 (progn
65 (context-coloring-test-setup)
66 (insert (context-coloring-test-read-file ,fixture))
67 ,@body)
68 (context-coloring-test-cleanup))))
69
70 (defun context-coloring-test-with-temp-buffer-async (callback)
71 "Create a temporary buffer, and evaluate CALLBACK there. A
72 teardown callback is passed to CALLBACK for it to invoke when it
73 is done."
74 (let ((previous-buffer (current-buffer))
75 (temp-buffer (generate-new-buffer " *temp*")))
76 (set-buffer temp-buffer)
77 (funcall
78 callback
79 (lambda ()
80 (and (buffer-name temp-buffer)
81 (kill-buffer temp-buffer))
82 (set-buffer previous-buffer)))))
83
84 (defun context-coloring-test-with-fixture-async
85 (fixture callback &optional setup)
86 "With the relative FIXTURE, evaluate CALLBACK in a temporary
87 buffer. A teardown callback is passed to CALLBACK for it to
88 invoke when it is done. An optional SETUP callback can run
89 arbitrary code before the mode is invoked."
90 (context-coloring-test-with-temp-buffer-async
91 (lambda (done-with-temp-buffer)
92 (context-coloring-test-setup)
93 (when setup (funcall setup))
94 (insert (context-coloring-test-read-file fixture))
95 (funcall
96 callback
97 (lambda ()
98 (context-coloring-test-cleanup)
99 (funcall done-with-temp-buffer))))))
100
101
102 ;;; Test defining utilities
103
104 (defun context-coloring-test-js-mode (fixture callback &optional setup)
105 "Use FIXTURE as the subject matter for test logic in CALLBACK.
106 Optionally, provide setup code to run before the mode is
107 instantiated in SETUP."
108 (context-coloring-test-with-fixture-async
109 fixture
110 (lambda (done-with-test)
111 (js-mode)
112 (context-coloring-mode)
113 (context-coloring-colorize
114 (lambda ()
115 (funcall callback done-with-test))))
116 setup))
117
118 (defmacro context-coloring-test-js2-mode (fixture setup &rest body)
119 "Use FIXTURE as the subject matter for test logic in BODY."
120 `(context-coloring-test-with-fixture
121 ,fixture
122 (require 'js2-mode)
123 (setq js2-mode-show-parse-errors nil)
124 (setq js2-mode-show-strict-warnings nil)
125 (js2-mode)
126 (when ,setup (funcall ,setup))
127 (context-coloring-mode)
128 ,@body))
129
130 (cl-defmacro context-coloring-test-deftest-js-mode (name &key fixture-name)
131 "Define an asynchronous test for `js-mode' with the name NAME
132 in the typical format."
133 (declare (indent defun))
134 (let ((test-name (intern (format "context-coloring-test-js-mode-%s" name)))
135 (fixture (format "./fixtures/%s.js" (or fixture-name name)))
136 (function-name (intern-soft
137 (format "context-coloring-test-js-%s" name)))
138 (setup-function-name (intern-soft
139 (format "context-coloring-test-js-%s-setup" name))))
140 `(ert-deftest-async ,test-name (done)
141 (context-coloring-test-js-mode
142 ,fixture
143 (lambda (teardown)
144 (unwind-protect
145 (,function-name)
146 (funcall teardown))
147 (funcall done))
148 ',setup-function-name))))
149
150 (cl-defmacro context-coloring-test-deftest-js2-mode (name &key fixture-name)
151 "Define a test for `js2-mode' with the name NAME in the typical
152 format."
153 (declare (indent defun))
154 (let ((test-name (intern (format "context-coloring-test-js2-mode-%s" name)))
155 (fixture (format "./fixtures/%s.js" (or fixture-name name)))
156 (function-name (intern-soft
157 (format "context-coloring-test-js-%s" name)))
158 (setup-function-name (intern-soft
159 (format "context-coloring-test-js-%s-setup" name))))
160 `(ert-deftest ,test-name ()
161 (context-coloring-test-js2-mode
162 ,fixture
163 ',setup-function-name
164 (,function-name)))))
165
166
167 ;;; Assertion functions
168
169 (defmacro context-coloring-test-assert-region (&rest body)
170 "Assert something about the face of points in a region.
171 Provides the free variables `i', `length', `point', `face' and
172 `actual-level' to the code in BODY."
173 `(let ((i 0)
174 (length (- end start)))
175 (while (< i length)
176 (let* ((point (+ i start))
177 (face (get-text-property point 'face)))
178 ,@body)
179 (setq i (+ i 1)))))
180
181 (defun context-coloring-test-assert-region-level (start end level)
182 "Assert that all points in the range [START, END) are of level
183 LEVEL."
184 (context-coloring-test-assert-region
185 (let (actual-level)
186 (when (not (when face
187 (let* ((face-string (symbol-name face))
188 (matches (string-match
189 context-coloring-level-face-regexp
190 face-string)))
191 (when matches
192 (setq actual-level (string-to-number
193 (substring face-string
194 (match-beginning 1)
195 (match-end 1))))
196 (= level actual-level)))))
197 (ert-fail (format (concat "Expected level in region [%s, %s), "
198 "which is \"%s\", to be %s; "
199 "but at point %s, it was %s")
200 start end
201 (buffer-substring-no-properties start end) level
202 point actual-level))))))
203
204 (defun context-coloring-test-assert-region-face (start end expected-face)
205 "Assert that all points in the range [START, END) have the face
206 EXPECTED-FACE."
207 (context-coloring-test-assert-region
208 (when (not (eq face expected-face))
209 (ert-fail (format (concat "Expected face in region [%s, %s), "
210 "which is \"%s\", to be %s; "
211 "but at point %s, it was %s")
212 start end
213 (buffer-substring-no-properties start end) expected-face
214 point face)))))
215
216 (defun context-coloring-test-assert-region-comment-delimiter (start end)
217 "Assert that all points in the range [START, END) have
218 `font-lock-comment-delimiter-face'."
219 (context-coloring-test-assert-region-face
220 start end 'font-lock-comment-delimiter-face))
221
222 (defun context-coloring-test-assert-region-comment (start end)
223 "Assert that all points in the range [START, END) have
224 `font-lock-comment-face'."
225 (context-coloring-test-assert-region-face
226 start end 'font-lock-comment-face))
227
228 (defun context-coloring-test-assert-region-string (start end)
229 "Assert that all points in the range [START, END) have
230 `font-lock-string-face'."
231 (context-coloring-test-assert-region-face
232 start end 'font-lock-string-face))
233
234 (defun context-coloring-test-assert-message (expected buffer)
235 "Assert that message EXPECTED exists in BUFFER."
236 (when (null (get-buffer buffer))
237 (ert-fail
238 (format
239 (concat
240 "Expected buffer `%s' to have message \"%s\", "
241 "but the buffer did not have any messages.")
242 buffer expected)))
243 (with-current-buffer buffer
244 (let ((messages (split-string
245 (buffer-substring-no-properties
246 (point-min)
247 (point-max))
248 "\n")))
249 (let ((message (car (nthcdr (- (length messages) 2) messages))))
250 (when (not (equal message expected))
251 (ert-fail
252 (format
253 (concat
254 "Expected buffer `%s' to have message \"%s\", "
255 "but instead it was \"%s\"")
256 buffer expected
257 message)))))))
258
259 (defun context-coloring-test-assert-no-message (buffer)
260 "Assert that BUFFER has no message."
261 (when (get-buffer buffer)
262 (ert-fail (format (concat "Expected buffer `%s' to have no messages, "
263 "but it did: `%s'")
264 buffer
265 (with-current-buffer buffer
266 (buffer-string))))))
267
268 (defun context-coloring-test-kill-buffer (buffer)
269 "Kill BUFFER if it exists."
270 (when (get-buffer buffer) (kill-buffer buffer)))
271
272 (defun context-coloring-test-assert-face (level foreground &optional negate)
273 "Assert that a face for LEVEL exists and that its `:foreground'
274 is FOREGROUND, or the inverse if NEGATE is non-nil."
275 (let* ((face (context-coloring-level-face level))
276 actual-foreground)
277 (when (not (or negate
278 face))
279 (ert-fail (format (concat "Expected face for level `%s' to exist; "
280 "but it didn't")
281 level)))
282 (setq actual-foreground (face-attribute face :foreground))
283 (when (funcall (if negate 'identity 'not)
284 (string-equal foreground actual-foreground))
285 (ert-fail (format (concat "Expected face for level `%s' "
286 "%sto have foreground `%s'; "
287 "but it %s.")
288 level
289 (if negate "not " "") foreground
290 (if negate "did" (format "was `%s'" actual-foreground)))))))
291
292 (defun context-coloring-test-assert-not-face (&rest arguments)
293 "Assert that LEVEL does not have a face with `:foreground'
294 FOREGROUND. Apply ARGUMENTS to
295 `context-coloring-test-assert-face', see that function."
296 (apply 'context-coloring-test-assert-face
297 (append arguments '(t))))
298
299
300 ;;; The tests
301
302 (ert-deftest context-coloring-test-unsupported-mode ()
303 (context-coloring-test-with-fixture
304 "./fixtures/function-scopes.js"
305 (context-coloring-mode)
306 (context-coloring-test-assert-message
307 "Context coloring is not available for this major mode"
308 "*Messages*")))
309
310 (defvar context-coloring-test-theme-index 0
311 "Unique index for unique theme names.")
312
313 (defun context-coloring-test-get-next-theme ()
314 "Return a unique symbol for a throwaway theme."
315 (prog1
316 (intern (format "context-coloring-test-theme-%s"
317 context-coloring-test-theme-index))
318 (setq context-coloring-test-theme-index
319 (+ context-coloring-test-theme-index 1))))
320
321 (defun context-coloring-test-assert-theme-originally-set-p
322 (settings &optional negate)
323 "Assert that `context-coloring-theme-originally-set-p' returns
324 t for a theme with SETTINGS, or the inverse if NEGATE is
325 non-nil."
326 (let ((theme (context-coloring-test-get-next-theme)))
327 (put theme 'theme-settings settings)
328 (when (funcall (if negate 'identity 'not)
329 (context-coloring-theme-originally-set-p theme))
330 (ert-fail (format (concat "Expected theme `%s' with settings `%s' "
331 "%sto be considered to have defined a level, "
332 "but it %s.")
333 theme settings
334 (if negate "not " "")
335 (if negate "was" "wasn't"))))))
336
337 (defun context-coloring-test-assert-not-theme-originally-set-p (&rest arguments)
338 "Assert that `context-coloring-theme-originally-set-p' does not
339 return t for a theme with SETTINGS. Apply ARGUMENTS to
340 `context-coloring-test-assert-theme-originally-set-p', see that
341 function."
342 (apply 'context-coloring-test-assert-theme-originally-set-p
343 (append arguments '(t))))
344
345 (ert-deftest context-coloring-test-theme-originally-set-p ()
346 (context-coloring-test-assert-theme-originally-set-p
347 '((theme-face context-coloring-level-0-face)))
348 (context-coloring-test-assert-theme-originally-set-p
349 '((theme-face face)
350 (theme-face context-coloring-level-0-face)))
351 (context-coloring-test-assert-theme-originally-set-p
352 '((theme-face context-coloring-level-0-face)
353 (theme-face face)))
354 (context-coloring-test-assert-not-theme-originally-set-p
355 '((theme-face face)))
356 )
357
358 (defun context-coloring-test-assert-theme-settings-highest-level
359 (settings expected-level)
360 "Assert that a theme with SETTINGS has the highest level
361 EXPECTED-LEVEL."
362 (let ((theme (context-coloring-test-get-next-theme)))
363 (put theme 'theme-settings settings)
364 (context-coloring-test-assert-theme-highest-level theme expected-level)))
365
366 (defun context-coloring-test-assert-theme-highest-level
367 (theme expected-level &optional negate)
368 "Assert that THEME has the highest level EXPECTED-LEVEL, or the
369 inverse if NEGATE is non-nil."
370 (let ((highest-level (context-coloring-theme-highest-level theme)))
371 (when (funcall (if negate 'identity 'not) (eq highest-level expected-level))
372 (ert-fail (format (concat "Expected theme with settings `%s' "
373 "%sto have a highest level of `%s', "
374 "but it %s.")
375 (get theme 'theme-settings)
376 (if negate "not " "") expected-level
377 (if negate "did" (format "was %s" highest-level)))))))
378
379 (defun context-coloring-test-assert-theme-not-highest-level (&rest arguments)
380 "Assert that THEME's highest level is not EXPECTED-LEVEL.
381 Apply ARGUMENTS to
382 `context-coloring-test-assert-theme-highest-level', see that
383 function."
384 (apply 'context-coloring-test-assert-theme-highest-level
385 (append arguments '(t))))
386
387 (ert-deftest context-coloring-test-theme-highest-level ()
388 (context-coloring-test-assert-theme-settings-highest-level
389 '((theme-face foo))
390 -1)
391 (context-coloring-test-assert-theme-settings-highest-level
392 '((theme-face context-coloring-level-0-face))
393 0)
394 (context-coloring-test-assert-theme-settings-highest-level
395 '((theme-face context-coloring-level-1-face))
396 1)
397 (context-coloring-test-assert-theme-settings-highest-level
398 '((theme-face context-coloring-level-1-face)
399 (theme-face context-coloring-level-0-face))
400 1)
401 (context-coloring-test-assert-theme-settings-highest-level
402 '((theme-face context-coloring-level-0-face)
403 (theme-face context-coloring-level-1-face))
404 1)
405 )
406
407 (defmacro context-coloring-test-deftest-define-theme (name &rest body)
408 "Define a test with name NAME and an automatically-generated
409 theme symbol available as a free variable `theme'. Side-effects
410 from enabling themes are reversed after BODY is executed and the
411 test completes."
412 (declare (indent defun))
413 (let ((deftest-name (intern
414 (format "context-coloring-test-define-theme-%s" name))))
415 `(ert-deftest ,deftest-name ()
416 (context-coloring-test-kill-buffer "*Warnings*")
417 (let ((theme (context-coloring-test-get-next-theme)))
418 (unwind-protect
419 (progn
420 ,@body)
421 ;; Always cleanup.
422 (disable-theme theme))))))
423
424 (defun context-coloring-test-deftheme (theme)
425 "Dynamically define theme THEME."
426 (eval (macroexpand `(deftheme ,theme))))
427
428 (context-coloring-test-deftest-define-theme additive
429 (context-coloring-test-deftheme theme)
430 (context-coloring-define-theme
431 theme
432 :colors '("#aaaaaa"
433 "#bbbbbb"))
434 (context-coloring-test-assert-no-message "*Warnings*")
435 (enable-theme theme)
436 (context-coloring-test-assert-no-message "*Warnings*")
437 (context-coloring-test-assert-face 0 "#aaaaaa")
438 (context-coloring-test-assert-face 1 "#bbbbbb"))
439
440 (defun context-coloring-test-assert-defined-warning (theme)
441 "Assert that a warning about colors already being defined for
442 theme THEME is signaled."
443 (context-coloring-test-assert-message
444 (format (concat "Warning (emacs): Context coloring colors for theme "
445 "`%s' are already defined")
446 theme)
447 "*Warnings*"))
448
449 (context-coloring-test-deftest-define-theme unintentional-override
450 (context-coloring-test-deftheme theme)
451 (custom-theme-set-faces
452 theme
453 '(context-coloring-level-0-face ((t (:foreground "#aaaaaa"))))
454 '(context-coloring-level-1-face ((t (:foreground "#bbbbbb")))))
455 (context-coloring-define-theme
456 theme
457 :colors '("#cccccc"
458 "#dddddd"))
459 (context-coloring-test-assert-defined-warning theme)
460 (context-coloring-test-kill-buffer "*Warnings*")
461 (enable-theme theme)
462 (context-coloring-test-assert-defined-warning theme)
463 (context-coloring-test-assert-face 0 "#cccccc")
464 (context-coloring-test-assert-face 1 "#dddddd"))
465
466 (context-coloring-test-deftest-define-theme intentional-override
467 (context-coloring-test-deftheme theme)
468 (custom-theme-set-faces
469 theme
470 '(context-coloring-level-0-face ((t (:foreground "#aaaaaa"))))
471 '(context-coloring-level-1-face ((t (:foreground "#bbbbbb")))))
472 (context-coloring-define-theme
473 theme
474 :override t
475 :colors '("#cccccc"
476 "#dddddd"))
477 (context-coloring-test-assert-no-message "*Warnings*")
478 (enable-theme theme)
479 (context-coloring-test-assert-no-message "*Warnings*")
480 (context-coloring-test-assert-face 0 "#cccccc")
481 (context-coloring-test-assert-face 1 "#dddddd"))
482
483 (context-coloring-test-deftest-define-theme pre-recede
484 (context-coloring-define-theme
485 theme
486 :recede t
487 :colors '("#aaaaaa"
488 "#bbbbbb"))
489 (context-coloring-test-deftheme theme)
490 (custom-theme-set-faces
491 theme
492 '(context-coloring-level-0-face ((t (:foreground "#cccccc"))))
493 '(context-coloring-level-1-face ((t (:foreground "#dddddd")))))
494 (enable-theme theme)
495 (context-coloring-test-assert-no-message "*Warnings*")
496 (context-coloring-test-assert-face 0 "#cccccc")
497 (context-coloring-test-assert-face 1 "#dddddd"))
498
499 (context-coloring-test-deftest-define-theme post-recede
500 (context-coloring-test-deftheme theme)
501 (custom-theme-set-faces
502 theme
503 '(context-coloring-level-0-face ((t (:foreground "#aaaaaa"))))
504 '(context-coloring-level-1-face ((t (:foreground "#bbbbbb")))))
505 (context-coloring-define-theme
506 theme
507 :recede t
508 :colors '("#cccccc"
509 "#dddddd"))
510 (context-coloring-test-assert-no-message "*Warnings*")
511 (context-coloring-test-assert-face 0 "#aaaaaa")
512 (context-coloring-test-assert-face 1 "#bbbbbb")
513 (enable-theme theme)
514 (context-coloring-test-assert-no-message "*Warnings*")
515 (context-coloring-test-assert-face 0 "#aaaaaa")
516 (context-coloring-test-assert-face 1 "#bbbbbb"))
517
518 (context-coloring-test-deftest-define-theme recede-not-defined
519 (context-coloring-test-deftheme theme)
520 (custom-theme-set-faces
521 theme
522 '(foo-face ((t (:foreground "#ffffff")))))
523 (context-coloring-define-theme
524 theme
525 :recede t
526 :colors '("#aaaaaa"
527 "#bbbbbb"))
528 (context-coloring-test-assert-no-message "*Warnings*")
529 (context-coloring-test-assert-face 0 "#aaaaaa")
530 (context-coloring-test-assert-face 1 "#bbbbbb")
531 (enable-theme theme)
532 (context-coloring-test-assert-no-message "*Warnings*")
533 (context-coloring-test-assert-face 0 "#aaaaaa")
534 (context-coloring-test-assert-face 1 "#bbbbbb"))
535
536 (context-coloring-test-deftest-define-theme unintentional-obstinance
537 (context-coloring-define-theme
538 theme
539 :colors '("#aaaaaa"
540 "#bbbbbb"))
541 (context-coloring-test-deftheme theme)
542 (custom-theme-set-faces
543 theme
544 '(context-coloring-level-0-face ((t (:foreground "#cccccc"))))
545 '(context-coloring-level-1-face ((t (:foreground "#dddddd")))))
546 (enable-theme theme)
547 (context-coloring-test-assert-defined-warning theme)
548 (context-coloring-test-assert-face 0 "#aaaaaa")
549 (context-coloring-test-assert-face 1 "#bbbbbb"))
550
551 (context-coloring-test-deftest-define-theme intentional-obstinance
552 (context-coloring-define-theme
553 theme
554 :override t
555 :colors '("#aaaaaa"
556 "#bbbbbb"))
557 (context-coloring-test-deftheme theme)
558 (custom-theme-set-faces
559 theme
560 '(context-coloring-level-0-face ((t (:foreground "#cccccc"))))
561 '(context-coloring-level-1-face ((t (:foreground "#dddddd")))))
562 (enable-theme theme)
563 (context-coloring-test-assert-no-message "*Warnings*")
564 (context-coloring-test-assert-face 0 "#aaaaaa")
565 (context-coloring-test-assert-face 1 "#bbbbbb"))
566
567 (defun context-coloring-test-assert-maximum-face (maximum &optional negate)
568 "Assert that `context-coloring-maximum-face' is MAXIMUM, or the
569 inverse if NEGATE is non-nil."
570 (when (funcall (if negate 'identity 'not)
571 (eq context-coloring-maximum-face maximum))
572 (ert-fail (format (concat "Expected `context-coloring-maximum-face' "
573 "%sto be `%s', "
574 "but it %s.")
575 (if negate "not " "") maximum
576 (if negate
577 "was"
578 (format "was `%s'" context-coloring-maximum-face))))))
579
580 (defun context-coloring-test-assert-not-maximum-face (&rest arguments)
581 "Assert that `context-coloring-maximum-face' is not MAXIMUM.
582 Apply ARGUMENTS to `context-coloring-test-assert-maximum-face',
583 see that function."
584 (apply 'context-coloring-test-assert-maximum-face
585 (append arguments '(t))))
586
587 (context-coloring-test-deftest-define-theme disable-cascade
588 (context-coloring-test-deftheme theme)
589 (context-coloring-define-theme
590 theme
591 :colors '("#aaaaaa"
592 "#bbbbbb"))
593 (let ((second-theme (context-coloring-test-get-next-theme)))
594 (context-coloring-test-deftheme second-theme)
595 (context-coloring-define-theme
596 second-theme
597 :colors '("#cccccc"
598 "#dddddd"
599 "#eeeeee"))
600 (let ((third-theme (context-coloring-test-get-next-theme)))
601 (context-coloring-test-deftheme third-theme)
602 (context-coloring-define-theme
603 third-theme
604 :colors '("#111111"
605 "#222222"
606 "#333333"
607 "#444444"))
608 (enable-theme theme)
609 (enable-theme second-theme)
610 (enable-theme third-theme)
611 (disable-theme third-theme)
612 (context-coloring-test-assert-face 0 "#cccccc")
613 (context-coloring-test-assert-face 1 "#dddddd")
614 (context-coloring-test-assert-face 2 "#eeeeee")
615 (context-coloring-test-assert-maximum-face 2))
616 (disable-theme second-theme)
617 (context-coloring-test-assert-face 0 "#aaaaaa")
618 (context-coloring-test-assert-face 1 "#bbbbbb")
619 (context-coloring-test-assert-maximum-face 1))
620 (disable-theme theme)
621 (context-coloring-test-assert-not-face 0 "#aaaaaa")
622 (context-coloring-test-assert-not-face 1 "#bbbbbb")
623 (context-coloring-test-assert-not-maximum-face 1))
624
625 (defun context-coloring-test-js-function-scopes ()
626 "Test fixtures/functions-scopes.js."
627 (context-coloring-test-assert-region-level 1 9 0)
628 (context-coloring-test-assert-region-level 9 23 1)
629 (context-coloring-test-assert-region-level 23 25 0)
630 (context-coloring-test-assert-region-level 25 34 1)
631 (context-coloring-test-assert-region-level 34 35 0)
632 (context-coloring-test-assert-region-level 35 52 1)
633 (context-coloring-test-assert-region-level 52 66 2)
634 (context-coloring-test-assert-region-level 66 72 1)
635 (context-coloring-test-assert-region-level 72 81 2)
636 (context-coloring-test-assert-region-level 81 82 1)
637 (context-coloring-test-assert-region-level 82 87 2)
638 (context-coloring-test-assert-region-level 87 89 1))
639
640 (context-coloring-test-deftest-js-mode function-scopes)
641 (context-coloring-test-deftest-js2-mode function-scopes)
642
643 (defun context-coloring-test-js-global ()
644 "Test fixtures/global.js."
645 (context-coloring-test-assert-region-level 20 28 1)
646 (context-coloring-test-assert-region-level 28 35 0)
647 (context-coloring-test-assert-region-level 35 41 1))
648
649 (context-coloring-test-deftest-js-mode global)
650 (context-coloring-test-deftest-js2-mode global)
651
652 (defun context-coloring-test-js-block-scopes ()
653 "Test fixtures/block-scopes.js."
654 (context-coloring-test-assert-region-level 20 64 1)
655 (setq context-coloring-js-block-scopes t)
656 (context-coloring-colorize)
657 (context-coloring-test-assert-region-level 20 27 1)
658 (context-coloring-test-assert-region-level 27 41 2)
659 (context-coloring-test-assert-region-level 41 42 1)
660 (context-coloring-test-assert-region-level 42 64 2))
661
662 (context-coloring-test-deftest-js2-mode block-scopes)
663
664 (defun context-coloring-test-js-catch ()
665 "Test fixtures/js-catch.js."
666 (context-coloring-test-assert-region-level 20 27 1)
667 (context-coloring-test-assert-region-level 27 51 2)
668 (context-coloring-test-assert-region-level 51 52 1)
669 (context-coloring-test-assert-region-level 52 73 2)
670 (context-coloring-test-assert-region-level 73 101 3)
671 (context-coloring-test-assert-region-level 101 102 1)
672 (context-coloring-test-assert-region-level 102 117 3)
673 (context-coloring-test-assert-region-level 117 123 2))
674
675 (context-coloring-test-deftest-js-mode catch)
676 (context-coloring-test-deftest-js2-mode catch)
677
678 (defun context-coloring-test-js-key-names ()
679 "Test fixtures/key-names.js."
680 (context-coloring-test-assert-region-level 20 63 1))
681
682 (context-coloring-test-deftest-js-mode key-names)
683 (context-coloring-test-deftest-js2-mode key-names)
684
685 (defun context-coloring-test-js-property-lookup ()
686 "Test fixtures/property-lookup.js."
687 (context-coloring-test-assert-region-level 20 26 0)
688 (context-coloring-test-assert-region-level 26 38 1)
689 (context-coloring-test-assert-region-level 38 44 0)
690 (context-coloring-test-assert-region-level 44 52 1)
691 (context-coloring-test-assert-region-level 57 63 0)
692 (context-coloring-test-assert-region-level 63 74 1))
693
694 (context-coloring-test-deftest-js-mode property-lookup)
695 (context-coloring-test-deftest-js2-mode property-lookup)
696
697 (defun context-coloring-test-js-key-values ()
698 "Test fixtures/key-values.js."
699 (context-coloring-test-assert-region-level 78 79 1))
700
701 (context-coloring-test-deftest-js-mode key-values)
702 (context-coloring-test-deftest-js2-mode key-values)
703
704 (defun context-coloring-test-js-syntactic-comments-and-strings ()
705 "Test comments and strings."
706 (context-coloring-test-assert-region-level 1 8 0)
707 (context-coloring-test-assert-region-comment-delimiter 9 12)
708 (context-coloring-test-assert-region-comment 12 16)
709 (context-coloring-test-assert-region-comment-delimiter 17 20)
710 (context-coloring-test-assert-region-comment 20 27)
711 (context-coloring-test-assert-region-string 28 40)
712 (context-coloring-test-assert-region-level 40 41 0))
713
714 (defun context-coloring-test-js-syntactic-comments-and-strings-setup ()
715 (setq context-coloring-syntactic-comments t)
716 (setq context-coloring-syntactic-strings t))
717
718 (context-coloring-test-deftest-js-mode syntactic-comments-and-strings
719 :fixture-name comments-and-strings)
720 (context-coloring-test-deftest-js2-mode syntactic-comments-and-strings
721 :fixture-name comments-and-strings)
722
723 (defalias 'context-coloring-test-js-comments-and-strings
724 'context-coloring-test-js-syntactic-comments-and-strings
725 "Test comments and strings. Deprecated.")
726
727 (defun context-coloring-test-js-comments-and-strings-setup ()
728 "Setup comments and strings. Deprecated."
729 (setq context-coloring-comments-and-strings t))
730
731 (context-coloring-test-deftest-js-mode comments-and-strings)
732 (context-coloring-test-deftest-js2-mode comments-and-strings)
733
734 (defun context-coloring-test-js-syntactic-comments ()
735 "Test syntactic comments."
736 (context-coloring-test-assert-region-level 1 8 0)
737 (context-coloring-test-assert-region-comment-delimiter 9 12)
738 (context-coloring-test-assert-region-comment 12 16)
739 (context-coloring-test-assert-region-comment-delimiter 17 20)
740 (context-coloring-test-assert-region-comment 20 27)
741 (context-coloring-test-assert-region-level 28 41 0))
742
743 (defun context-coloring-test-js-syntactic-comments-setup ()
744 "Setup syntactic comments."
745 (setq context-coloring-syntactic-comments t))
746
747 (context-coloring-test-deftest-js-mode syntactic-comments
748 :fixture-name comments-and-strings)
749 (context-coloring-test-deftest-js2-mode syntactic-comments
750 :fixture-name comments-and-strings)
751
752 (defun context-coloring-test-js-syntactic-strings ()
753 "Test syntactic strings."
754 (context-coloring-test-assert-region-level 1 28 0)
755 (context-coloring-test-assert-region-string 28 40)
756 (context-coloring-test-assert-region-level 40 41 0))
757
758 (defun context-coloring-test-js-syntactic-strings-setup ()
759 "Setup syntactic strings."
760 (setq context-coloring-syntactic-strings t))
761
762 (context-coloring-test-deftest-js-mode syntactic-strings
763 :fixture-name comments-and-strings)
764 (context-coloring-test-deftest-js2-mode syntactic-strings
765 :fixture-name comments-and-strings)
766
767 (provide 'context-coloring-test)
768
769 ;;; context-coloring-test.el ends here