[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1f474d9 11/79: Reorganize functions.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master 1f474d9 11/79: Reorganize functions. |
Date: |
Sun, 14 Jun 2015 00:05:16 +0000 |
branch: master
commit 1f474d9e189b64d996baedd3f24e6930982d1939
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Reorganize functions.
---
test/context-coloring-test.el | 270 +++++++++++++++++++++--------------------
1 files changed, 138 insertions(+), 132 deletions(-)
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index d43a716..0c7cc20 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -185,103 +185,6 @@ initial colorization if colorization should occur."
;;; Assertion functions
-(defun context-coloring-test-assert-position-level (position level)
- "Assert that POSITION has LEVEL."
- (let ((face (get-text-property position 'face))
- actual-level)
- (when (not (and face
- (let* ((face-string (symbol-name face))
- (matches (string-match
- context-coloring-level-face-regexp
- face-string)))
- (when matches
- (setq actual-level (string-to-number
- (substring face-string
- (match-beginning 1)
- (match-end 1))))
- (= level actual-level)))))
- (ert-fail (format (concat "Expected level at position %s, "
- "which is \"%s\", to be %s; "
- "but it was %s")
- position
- (buffer-substring-no-properties position (1+
position)) level
- actual-level)))))
-
-(defun context-coloring-test-assert-position-face (position face-regexp)
- "Assert that the face at POSITION satisfies FACE-REGEXP."
- (let ((face (get-text-property position 'face)))
- (when (or
- ;; Pass a non-string to do an `equal' check (against a symbol or
nil).
- (unless (stringp face-regexp)
- (not (equal face-regexp face)))
- ;; Otherwise do the matching.
- (when (stringp face-regexp)
- (not (string-match-p face-regexp (symbol-name face)))))
- (ert-fail (format (concat "Expected face at position %s, "
- "which is \"%s\", to be %s; "
- "but it was %s")
- position
- (buffer-substring-no-properties position (1+
position)) face-regexp
- face)))))
-
-(defun context-coloring-test-assert-position-comment (position)
- (context-coloring-test-assert-position-face
- position "\\`font-lock-comment\\(-delimiter\\)?-face\\'"))
-
-(defun context-coloring-test-assert-position-constant-comment (position)
- (context-coloring-test-assert-position-face position
'(font-lock-constant-face
-
font-lock-comment-face)))
-
-(defun context-coloring-test-assert-position-string (position)
- (context-coloring-test-assert-position-face position 'font-lock-string-face))
-
-(defun context-coloring-test-assert-position-nil (position)
- (context-coloring-test-assert-position-face position nil))
-
-(defun context-coloring-test-assert-coloring (map)
- "Assert that the current buffer's coloring matches MAP."
- ;; Omit the superfluous, formatting-related leading newline. Can't use
- ;; `save-excursion' here because if an assertion fails it will cause future
- ;; tests to get messed up.
- (goto-char (point-min))
- (let* ((map (substring map 1))
- (index 0)
- char-string
- char)
- (while (< index (length map))
- (setq char-string (substring map index (1+ index)))
- (setq char (string-to-char char-string))
- (cond
- ;; Newline
- ((= char 10)
- (forward-line)
- (beginning-of-line))
- ;; Number
- ((and (>= char 48)
- (<= char 57))
- (context-coloring-test-assert-position-level
- (point) (string-to-number char-string))
- (forward-char))
- ;; 'C' = Constant comment
- ((= char 67)
- (context-coloring-test-assert-position-constant-comment (point))
- (forward-char))
- ;; 'c' = Comment
- ((= char 99)
- (context-coloring-test-assert-position-comment (point))
- (forward-char))
- ;; 'n' = nil
- ((= char 110)
- (context-coloring-test-assert-position-nil (point))
- (forward-char))
- ;; 's' = String
- ((= char 115)
- (context-coloring-test-assert-position-string (point))
- (forward-char))
- (t
- (forward-char)))
- (setq index (1+ index)))))
-
(defun context-coloring-test-get-last-message ()
(let ((messages (split-string
(buffer-substring-no-properties
@@ -332,38 +235,6 @@ initial colorization if colorization should occur."
(with-current-buffer buffer
(buffer-string))))))
-(defun context-coloring-test-kill-buffer (buffer)
- "Kill BUFFER if it exists."
- (when (get-buffer buffer) (kill-buffer buffer)))
-
-(defun context-coloring-test-assert-face (level foreground &optional negate)
- "Assert that a face for LEVEL exists and that its `:foreground'
-is FOREGROUND, or the inverse if NEGATE is non-nil."
- (let* ((face (context-coloring-level-face level))
- actual-foreground)
- (when (not (or negate
- face))
- (ert-fail (format (concat "Expected face for level `%s' to exist; "
- "but it didn't")
- level)))
- (setq actual-foreground (face-attribute face :foreground))
- (when (funcall (if negate 'identity 'not)
- (string-equal foreground actual-foreground))
- (ert-fail (format (concat "Expected face for level `%s' "
- "%sto have foreground `%s'; "
- "but it %s.")
- level
- (if negate "not " "") foreground
- (if negate
- "did" (format "was `%s'" actual-foreground)))))))
-
-(defun context-coloring-test-assert-not-face (&rest arguments)
- "Assert that LEVEL does not have a face with `:foreground'
-FOREGROUND. Apply ARGUMENTS to
-`context-coloring-test-assert-face', see that function."
- (apply 'context-coloring-test-assert-face
- (append arguments '(t))))
-
(defun context-coloring-test-assert-error (body error-message)
"Assert that BODY signals ERROR-MESSAGE."
(let ((error-signaled-p nil))
@@ -380,13 +251,13 @@ FOREGROUND. Apply ARGUMENTS to
(when (not error-signaled-p)
(ert-fail "Expected an error to be thrown, but there wasn't."))))
+
+;;; Miscellaneous tests
+
(defun context-coloring-test-assert-trimmed (result expected)
(when (not (string-equal result expected))
(ert-fail "Expected string to be trimmed, but it wasn't.")))
-
-;;; The tests
-
(ert-deftest context-coloring-test-trim ()
(context-coloring-test-assert-trimmed (context-coloring-trim "") "")
(context-coloring-test-assert-trimmed (context-coloring-trim " ") "")
@@ -554,6 +425,9 @@ FOREGROUND. Apply ARGUMENTS to
(funcall teardown))
(funcall done)))))
+
+;;; Theme tests
+
(defvar context-coloring-test-theme-index 0
"Unique index for unique theme names.")
@@ -565,6 +439,34 @@ FOREGROUND. Apply ARGUMENTS to
(setq context-coloring-test-theme-index
(+ context-coloring-test-theme-index 1))))
+(defun context-coloring-test-assert-face (level foreground &optional negate)
+ "Assert that a face for LEVEL exists and that its `:foreground'
+is FOREGROUND, or the inverse if NEGATE is non-nil."
+ (let* ((face (context-coloring-level-face level))
+ actual-foreground)
+ (when (not (or negate
+ face))
+ (ert-fail (format (concat "Expected face for level `%s' to exist; "
+ "but it didn't")
+ level)))
+ (setq actual-foreground (face-attribute face :foreground))
+ (when (funcall (if negate 'identity 'not)
+ (string-equal foreground actual-foreground))
+ (ert-fail (format (concat "Expected face for level `%s' "
+ "%sto have foreground `%s'; "
+ "but it %s.")
+ level
+ (if negate "not " "") foreground
+ (if negate
+ "did" (format "was `%s'" actual-foreground)))))))
+
+(defun context-coloring-test-assert-not-face (&rest arguments)
+ "Assert that LEVEL does not have a face with `:foreground'
+FOREGROUND. Apply ARGUMENTS to
+`context-coloring-test-assert-face', see that function."
+ (apply 'context-coloring-test-assert-face
+ (append arguments '(t))))
+
(defun context-coloring-test-assert-theme-originally-set-p
(settings &optional negate)
"Assert that `context-coloring-theme-originally-set-p' returns
@@ -649,6 +551,10 @@ function."
(theme-face context-coloring-level-1-face))
1))
+(defun context-coloring-test-kill-buffer (buffer)
+ "Kill BUFFER if it exists."
+ (when (get-buffer buffer) (kill-buffer buffer)))
+
(defmacro context-coloring-test-deftest-define-theme (name &rest body)
"Define a test with name NAME and an automatically-generated
theme symbol available as a free variable `theme'. Side-effects
@@ -884,6 +790,106 @@ see that function."
(context-coloring-test-assert-maximum-face
maximum-face-value)))
+
+;;; Coloring tests
+
+(defun context-coloring-test-assert-position-level (position level)
+ "Assert that POSITION has LEVEL."
+ (let ((face (get-text-property position 'face))
+ actual-level)
+ (when (not (and face
+ (let* ((face-string (symbol-name face))
+ (matches (string-match
+ context-coloring-level-face-regexp
+ face-string)))
+ (when matches
+ (setq actual-level (string-to-number
+ (substring face-string
+ (match-beginning 1)
+ (match-end 1))))
+ (= level actual-level)))))
+ (ert-fail (format (concat "Expected level at position %s, "
+ "which is \"%s\", to be %s; "
+ "but it was %s")
+ position
+ (buffer-substring-no-properties position (1+
position)) level
+ actual-level)))))
+
+(defun context-coloring-test-assert-position-face (position face-regexp)
+ "Assert that the face at POSITION satisfies FACE-REGEXP."
+ (let ((face (get-text-property position 'face)))
+ (when (or
+ ;; Pass a non-string to do an `equal' check (against a symbol or
nil).
+ (unless (stringp face-regexp)
+ (not (equal face-regexp face)))
+ ;; Otherwise do the matching.
+ (when (stringp face-regexp)
+ (not (string-match-p face-regexp (symbol-name face)))))
+ (ert-fail (format (concat "Expected face at position %s, "
+ "which is \"%s\", to be %s; "
+ "but it was %s")
+ position
+ (buffer-substring-no-properties position (1+
position)) face-regexp
+ face)))))
+
+(defun context-coloring-test-assert-position-comment (position)
+ (context-coloring-test-assert-position-face
+ position "\\`font-lock-comment\\(-delimiter\\)?-face\\'"))
+
+(defun context-coloring-test-assert-position-constant-comment (position)
+ (context-coloring-test-assert-position-face position
'(font-lock-constant-face
+
font-lock-comment-face)))
+
+(defun context-coloring-test-assert-position-string (position)
+ (context-coloring-test-assert-position-face position 'font-lock-string-face))
+
+(defun context-coloring-test-assert-position-nil (position)
+ (context-coloring-test-assert-position-face position nil))
+
+(defun context-coloring-test-assert-coloring (map)
+ "Assert that the current buffer's coloring matches MAP."
+ ;; Omit the superfluous, formatting-related leading newline. Can't use
+ ;; `save-excursion' here because if an assertion fails it will cause future
+ ;; tests to get messed up.
+ (goto-char (point-min))
+ (let* ((map (substring map 1))
+ (index 0)
+ char-string
+ char)
+ (while (< index (length map))
+ (setq char-string (substring map index (1+ index)))
+ (setq char (string-to-char char-string))
+ (cond
+ ;; Newline
+ ((= char 10)
+ (forward-line)
+ (beginning-of-line))
+ ;; Number
+ ((and (>= char 48)
+ (<= char 57))
+ (context-coloring-test-assert-position-level
+ (point) (string-to-number char-string))
+ (forward-char))
+ ;; 'C' = Constant comment
+ ((= char 67)
+ (context-coloring-test-assert-position-constant-comment (point))
+ (forward-char))
+ ;; 'c' = Comment
+ ((= char 99)
+ (context-coloring-test-assert-position-comment (point))
+ (forward-char))
+ ;; 'n' = nil
+ ((= char 110)
+ (context-coloring-test-assert-position-nil (point))
+ (forward-char))
+ ;; 's' = String
+ ((= char 115)
+ (context-coloring-test-assert-position-string (point))
+ (forward-char))
+ (t
+ (forward-char)))
+ (setq index (1+ index)))))
+
(context-coloring-test-deftest-js-js2 function-scopes
(lambda ()
(context-coloring-test-assert-coloring "
- [elpa] master c337716 01/79: Add statistics., (continued)
- [elpa] master c337716 01/79: Add statistics., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ac22f0a 02/79: Silence obsolete warnings., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 57e87f0 04/79: Refactor js test definitions., Jackson Ray Hamilton, 2015/06/13
- [elpa] master cfcf112 03/79: Add define-deftest macro., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ae03324 05/79: Define js and js2 tests simultaneously., Jackson Ray Hamilton, 2015/06/13
- [elpa] master af536a4 07/79: Update coloring assertion syntax., Jackson Ray Hamilton, 2015/06/13
- [elpa] master c1b6b52 06/79: Update function scopes and global tests., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 5e0a0d9 10/79: Newlines., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 23cf7b3 09/79: Refactor derived mode tests., Jackson Ray Hamilton, 2015/06/13
- [elpa] master fd2f2d0 08/79: Refactor remaining js tests., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 1f474d9 11/79: Reorganize functions.,
Jackson Ray Hamilton <=
- [elpa] master 92166ba 13/79: Add no-fixture option., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 8ea8c9c 15/79: Pass defun test with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master ea6b4ef 14/79: Increase test documentation., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 7975003 18/79: Pass ignored test with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master d8b5f03 12/79: Remove before-all and after-all., Jackson Ray Hamilton, 2015/06/13
- [elpa] master bc0cb0d 16/79: Pass lambda test with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master 6090eb3 17/79: Pass quote test with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master f1ed39f 21/79: Pass comment and string tests with recursive colorizer., Jackson Ray Hamilton, 2015/06/13
- [elpa] master d146af8 23/79: Fix string coloring., Jackson Ray Hamilton, 2015/06/13
- [elpa] master aaf4835 20/79: Remove let-varlist data structure. Cleanup., Jackson Ray Hamilton, 2015/06/13