emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/typescript-mode 6a6c63ad5e 126/222: Extract test utilities


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 6a6c63ad5e 126/222: Extract test utilities
Date: Sun, 6 Feb 2022 16:59:25 -0500 (EST)

branch: elpa/typescript-mode
commit 6a6c63ad5ed8457e0982530ee3301263f1a70fc7
Author: Ailrun <jjc9310@gmail.com>
Commit: Ailrun <jjc9310@gmail.com>

    Extract test utilities
---
 Makefile                          |  5 +++-
 typescript-mode-test-utilities.el | 63 +++++++++++++++++++++++++++++++++++++++
 typescript-mode-tests.el          | 49 +-----------------------------
 3 files changed, 68 insertions(+), 49 deletions(-)

diff --git a/Makefile b/Makefile
index 2a3406c2db..32c70e8f19 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,8 @@
 EMACS=$(shell which emacs) -Q -batch -L .
-ELS = typescript-mode.el typescript-mode-tests.el
+ELS = \
+  typescript-mode.el \
+  typescript-mode-tests.el \
+  typescript-mode-test-utilities.el
 ELCS = $(ELS:.el=.elc)
 
 clean:
diff --git a/typescript-mode-test-utilities.el 
b/typescript-mode-test-utilities.el
new file mode 100644
index 0000000000..faa6c1166a
--- /dev/null
+++ b/typescript-mode-test-utilities.el
@@ -0,0 +1,63 @@
+;;; typescript-mode-test-utilities --- This file contains test utilities for 
typescript-mode.el
+
+;;; Commentary:
+;; See typescript-mode-tests.el and typescript-mode-jsdoc-tests.el
+
+;;; Code:
+
+(require 'ert)
+(require 'typescript-mode)
+
+;; Adapted from jdee-mode's test suite.
+(defmacro test-with-temp-buffer (content &rest body)
+  "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
+  (declare (debug t)
+           (indent 1))
+  `(with-temp-buffer
+     (insert ,content)
+     (typescript-mode)
+     (goto-char (point-min))
+     ;; We need this so that tests that simulate user actions operate on the 
right buffer.
+     (switch-to-buffer (current-buffer))
+     ,@body))
+
+(defmacro test-with-fontified-buffer (content &rest body)
+  "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
+  (declare (debug t)
+           (indent 1))
+  `(test-with-temp-buffer
+    ,content
+     (font-lock-fontify-buffer)
+     ,@body))
+
+(defun get-face-at (loc)
+  "Get the face at `LOC'.
+If it is not a number, then we `re-search-forward' with `LOC'
+as the search pattern."
+  (when (not (numberp loc))
+    (save-excursion
+      (re-search-forward loc)
+      (setq loc (match-beginning 0))))
+  (get-text-property loc 'face))
+
+(defun font-lock-test (contents expected)
+  "Perform a test on our template.
+`CONTENTS' is the string to put in the temporary buffer.
+`EXPECTED' is the expected results.
+It should be a list of (LOCATION . FACE) pairs, where
+LOCATION can be either a single location, or list of locations,
+that are all expected to have the same face."
+  (test-with-fontified-buffer
+   contents
+   ;; Make sure our propertize function has been applied to the whole
+   ;; buffer.
+   (syntax-propertize (point-max))
+   (dolist (spec expected)
+     (if (listp (car spec))
+         (dolist (source (car spec))
+           (should (eq (get-face-at source) (cdr spec))))
+       (should (eq (get-face-at (car spec)) (cdr spec)))))))
+
+(provide 'typescript-mode-test-utilities)
+
+;;; typescript-mode-test-utilities.el ends here
diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 4cf37fd01e..a976088fbd 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -9,6 +9,7 @@
 (require 'ert)
 (require 'typescript-mode)
 (require 'cl)
+(require 'typescript-mode-test-utilities)
 
 (defun typescript-test-get-doc ()
   (buffer-substring-no-properties (point-min) (point-max)))
@@ -204,58 +205,10 @@ a severity set to WARNING, no rule name."
 (ert-deftest re-search-backwards-skips-multi-line-comments ()
   (test-re-search "token" "let token; /* token in \nmulti-line token comment" 
0))
 
-;; Adapted from jdee-mode's test suite.
-(defmacro test-with-temp-buffer (content &rest body)
-  "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
-  (declare (debug t)
-           (indent 1))
-  `(with-temp-buffer
-     (insert ,content)
-     (typescript-mode)
-     (goto-char (point-min))
-     ;; We need this so that tests that simulate user actions operate on the 
right buffer.
-     (switch-to-buffer (current-buffer))
-     ,@body))
-
-(defmacro test-with-fontified-buffer (content &rest body)
-  "Fill a temporary buffer with `CONTENT' and eval `BODY' in it."
-  (declare (debug t)
-           (indent 1))
-  `(test-with-temp-buffer
-    ,content
-     (font-lock-fontify-buffer)
-     ,@body))
-
-(defun get-face-at (loc)
-  "Get the face at `LOC'. If it is not a number, then we `re-search-forward' 
with `LOC'
-as the search pattern."
-  (when (not (numberp loc))
-    (save-excursion
-      (re-search-forward loc)
-      (setq loc (match-beginning 0))))
-  (get-text-property loc 'face))
-
 (setq font-lock-contents
  " * @param {Something} bar A parameter. References [[moo]] and [[foo]].
  * @param second May hold ``x`` or ``y``.")
 
-(defun font-lock-test (contents expected)
-  "Perform a test on our template. `CONTENTS' is the string to
-put in the temporary buffer. `EXPECTED' is the expected
-results. It should be a list of (LOCATION . FACE) pairs, where
-LOCATION can be either a single location, or list of locations,
-that are all expected to have the same face."
-  (test-with-fontified-buffer
-   contents
-   ;; Make sure our propertize function has been applied to the whole
-   ;; buffer.
-   (syntax-propertize (point-max))
-   (dolist (spec expected)
-     (if (listp (car spec))
-         (dolist (source (car spec))
-           (should (eq (get-face-at source) (cdr spec))))
-       (should (eq (get-face-at (car spec)) (cdr spec)))))))
-
 (ert-deftest font-lock/documentation-in-documentation-comments ()
   "Documentation in documentation comments should be fontified as
 documentation."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]