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