[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."
- [nongnu] elpa/typescript-mode f6907e8ae3 031/222: Fix error in compilation-mode alist registration., (continued)
- [nongnu] elpa/typescript-mode f6907e8ae3 031/222: Fix error in compilation-mode alist registration., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 316b018d27 040/222: Add CI-config and test-runner., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode ab6d105807 076/222: Add regression tests for function name highlighting., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 2c43dd034c 068/222: Merge pull request #46 from ananthakumaran/fix/union-type-in-return-annotation, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 3361adad67 093/222: Prevent messing up comment fontification when filling paragraphs., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5350c45aec 104/222: Add function to convert plain strings to template strings., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 7a5c74d88e 109/222: Merge pull request #72 from Wilfred/remove_cpp, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode c2d72b7d81 116/222: Fix unwanted indentation after non-keyword "each", ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 0d32c85bfb 110/222: Drop typescript-parent-mode., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 5b6d60a2b2 118/222: Fix indentation after keyword-lookalike methods., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 6a6c63ad5e 126/222: Extract test utilities,
ELPA Syncer <=
- [nongnu] elpa/typescript-mode 72ec0f93aa 125/222: Merge pull request #90 from jack-williams/add-never, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 69607202bc 139/222: Make GPL license discoverable by Github., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f20103a448 154/222: Add `delete-selection` hints, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode fe63c579b5 158/222: Merge pull request #120 from emacs-typescript/tsx-tests, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode bd15f212a7 165/222: Implement support type-highlighting in some basic declarations, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 444aa36ec2 169/222: Fix the indentation of member expressions and continued expressions., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a8b7e76e85 171/222: Fix infinite loop in indentation., ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode 62e0366b46 181/222: Remove debugging code, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode a504b6f571 182/222: Merge pull request #1 from jkdufair/jkdufair-remove-debugging-code, ELPA Syncer, 2022/02/06
- [nongnu] elpa/typescript-mode f36fddeb54 186/222: Merge pull request #136 from phst/dup, ELPA Syncer, 2022/02/06