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