[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master e09d9ad 227/271: Add tests for comments and strings.
From: |
Jackson Ray Hamilton |
Subject: |
[elpa] master e09d9ad 227/271: Add tests for comments and strings. |
Date: |
Thu, 05 Feb 2015 18:31:28 +0000 |
branch: master
commit e09d9adaff20912cd600af31d58dc23f331a60f8
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Add tests for comments and strings.
---
test/context-coloring-test.el | 90 +++++++++++++++++++++++++--------
test/fixtures/comments-and-strings.js | 3 +
2 files changed, 72 insertions(+), 21 deletions(-)
diff --git a/test/context-coloring-test.el b/test/context-coloring-test.el
index 4f72ff2..64ed6e4 100644
--- a/test/context-coloring-test.el
+++ b/test/context-coloring-test.el
@@ -48,13 +48,15 @@ is done."
(kill-buffer temp-buffer))
(set-buffer previous-buffer))))))
-(defun context-coloring-test-with-fixture-async (fixture callback)
+(defun context-coloring-test-with-fixture-async (fixture callback &optional
setup)
"Evaluate CALLBACK in a temporary buffer with the relative
FIXTURE. A teardown callback is passed to CALLBACK for it to
-invoke when it is done."
+invoke when it is done. An optional SETUP callback can be passed
+to run arbitrary code before the mode is invoked."
(context-coloring-test-with-temp-buffer-async
(lambda (done-with-temp-buffer)
(context-coloring-test-setup)
+ (if setup (funcall setup))
(insert (context-coloring-test-read-file fixture))
(funcall
callback
@@ -62,7 +64,7 @@ invoke when it is done."
(context-coloring-test-cleanup)
(funcall done-with-temp-buffer))))))
-(defun context-coloring-test-js-mode (fixture callback)
+(defun context-coloring-test-js-mode (fixture callback &optional setup)
(context-coloring-test-with-fixture-async
fixture
(lambda (done-with-test)
@@ -70,7 +72,8 @@ invoke when it is done."
(context-coloring-mode)
(context-coloring-colorize
(lambda ()
- (funcall callback done-with-test))))))
+ (funcall callback done-with-test))))
+ setup))
(defmacro context-coloring-test-js2-mode (fixture &rest body)
`(context-coloring-test-with-fixture
@@ -82,27 +85,46 @@ invoke when it is done."
(context-coloring-mode)
,@body))
+(defmacro context-coloring-test-assert-region (&rest body)
+ `(let ((i 0)
+ (length (- end start)))
+ (while (< i length)
+ (let* ((point (+ i start))
+ (face (get-text-property point 'face))
+ actual-level)
+ ,@body)
+ (setq i (+ i 1)))))
+
(defconst context-coloring-test-level-regexp
"context-coloring-level-\\([[:digit:]]+\\)-face")
(defun context-coloring-test-assert-region-level (start end level)
- (let ((i 0)
- (length (- end start)))
- (while (< i length)
- (let* ((point (+ i start))
- (face (get-text-property point 'face))
- actual-level)
- (when (not (when face
- (let* ((face-string (symbol-name face))
- (matches (string-match
context-coloring-test-level-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 "Expected level in region [%s, %s), which is
\"%s\", to be %s; but at point %s, it was %s"
- start end (buffer-substring-no-properties start
end) level point actual-level))))
- (setq i (+ i 1)))))
+ (context-coloring-test-assert-region
+ (when (not (when face
+ (let* ((face-string (symbol-name face))
+ (matches (string-match
context-coloring-test-level-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 "Expected level in region [%s, %s), which is \"%s\", to
be %s; but at point %s, it was %s"
+ start end (buffer-substring-no-properties start end)
level point actual-level)))))
+
+(defun context-coloring-test-assert-region-face (start end expected-face)
+ (context-coloring-test-assert-region
+ (when (not (eq face expected-face))
+ (ert-fail (format "Expected face in region [%s, %s), which is \"%s\", to
be %s; but at point %s, it was %s"
+ start end (buffer-substring-no-properties start end)
expected-face point face)))))
+
+(defun context-coloring-test-assert-region-comment-delimiter (start end)
+ (context-coloring-test-assert-region-face start end
'font-lock-comment-delimiter-face))
+
+(defun context-coloring-test-assert-region-comment (start end)
+ (context-coloring-test-assert-region-face start end 'font-lock-comment-face))
+
+(defun context-coloring-test-assert-region-string (start end)
+ (context-coloring-test-assert-region-face start end 'font-lock-string-face))
(defun context-coloring-test-assert-message (expected)
(with-current-buffer "*Messages*"
@@ -258,4 +280,30 @@ invoke when it is done."
"./fixtures/key-values.js"
(context-coloring-test-js-key-values)))
+(defun context-coloring-test-js-comments-and-strings ()
+ (context-coloring-test-assert-region-comment-delimiter 1 4)
+ (context-coloring-test-assert-region-comment 4 8)
+ (context-coloring-test-assert-region-comment-delimiter 9 12)
+ (context-coloring-test-assert-region-comment 12 19)
+ (context-coloring-test-assert-region-string 20 32)
+ (context-coloring-test-assert-region-level 32 33 0))
+
+(ert-deftest-async context-coloring-test-js-mode-comments-and-strings (done)
+ (context-coloring-test-js-mode
+ "./fixtures/comments-and-strings.js"
+ (lambda (teardown)
+ (unwind-protect
+ (context-coloring-test-js-comments-and-strings)
+ (funcall teardown))
+ (funcall done))
+ (lambda ()
+ (setq context-coloring-comments-and-strings t))))
+
+(ert-deftest context-coloring-test-js2-mode-comments-and-strings ()
+ (context-coloring-test-js2-mode
+ "./fixtures/comments-and-strings.js"
+ (setq context-coloring-comments-and-strings t)
+ (context-coloring-colorize)
+ (context-coloring-test-js-comments-and-strings)))
+
(provide 'context-coloring-test)
diff --git a/test/fixtures/comments-and-strings.js
b/test/fixtures/comments-and-strings.js
new file mode 100644
index 0000000..9910b02
--- /dev/null
+++ b/test/fixtures/comments-and-strings.js
@@ -0,0 +1,3 @@
+// Foo.
+/* Bar. */
+'use strict';
- [elpa] master 5cc5224 249/271: Update sentence spacing., (continued)
- [elpa] master 5cc5224 249/271: Update sentence spacing., Jackson Ray Hamilton, 2015/02/05
- [elpa] master de8eacd 204/271: Update benchmarks in readme., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f15c193 189/271: Escape., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 31ee972 197/271: Improve property lookup test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3d034f9 262/271: Merge branch 'develop', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6d24750 206/271: Update docs., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 6059dca 179/271: Add Travis CI., Jackson Ray Hamilton, 2015/02/05
- [elpa] master f2ace00 224/271: Add faces dynamically. Stop looping around at the last level., Jackson Ray Hamilton, 2015/02/05
- [elpa] master d44b426 208/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3cff176 210/271: Add failing key-value pair test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master e09d9ad 227/271: Add tests for comments and strings.,
Jackson Ray Hamilton <=
- [elpa] master 21cc6c6 200/271: Save benchmark logs to an untracked directory., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 30a24f9 265/271: Add 'packages/context-coloring/' from commit 'f2b5d796d4dffc71b10503a8ae119bfa3274978e', Jackson Ray Hamilton, 2015/02/05
- [elpa] master 03d111c 235/271: Cleanup., Jackson Ray Hamilton, 2015/02/05
- [elpa] master eba74ae 192/271: Improve assertion functions., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 127b312 225/271: Remove rear-nonsticky., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 441dde0 178/271: Cleanup, comments., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 9fb06d8 254/271: Merge branch 'master' into develop, Jackson Ray Hamilton, 2015/02/05
- [elpa] master 5826178 239/271: Update the dispatch API., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 3c8f842 195/271: Write failing property lookup test., Jackson Ray Hamilton, 2015/02/05
- [elpa] master 4ac1eaa 242/271: Version 3.0.0., Jackson Ray Hamilton, 2015/02/05