1 ;;; typescript-mode-test-utilities --- This file contains test utilities for typescript-mode.el
4 ;; See typescript-mode-tests.el and typescript-mode-jsdoc-tests.el
9 (require 'typescript-mode)
11 ;; Adapted from jdee-mode's test suite.
12 (defmacro test-with-temp-buffer (content &rest body)
13 "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
19 (goto-char (point-min))
20 ;; We need this so that tests that simulate user actions operate on the right buffer.
21 (switch-to-buffer (current-buffer))
24 (defmacro test-with-fontified-buffer (content &rest body)
25 "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
28 `(test-with-temp-buffer
30 (font-lock-fontify-buffer)
33 (defun get-face-at (loc)
34 "Get the face at `LOC'.
35 If it is not a number, then we `re-search-forward' with `LOC'
36 as the search pattern."
37 (when (not (numberp loc))
39 (re-search-forward loc)
40 (setq loc (match-beginning 0))))
41 (get-text-property loc 'face))
43 (defun font-lock-test (contents expected)
44 "Perform a test on our template.
45 `CONTENTS' is the string to put in the temporary buffer.
46 `EXPECTED' is the expected results.
47 It should be a list of (LOCATION . FACE) pairs, where
48 LOCATION can be either a single location, or list of locations,
49 that are all expected to have the same face."
50 (test-with-fontified-buffer
52 ;; Make sure our propertize function has been applied to the whole
54 (syntax-propertize (point-max))
55 (dolist (spec expected)
56 (if (listp (car spec))
57 (dolist (source (car spec))
58 (should (eq (get-face-at source) (cdr spec))))
59 (should (eq (get-face-at (car spec)) (cdr spec)))))))
61 (provide 'typescript-mode-test-utilities)
63 ;;; typescript-mode-test-utilities.el ends here