commit aef5f96a36a181ab3928a71d5240f9407d89dde8
parent 781d3f36aceaae4573ece9fcd5f299e349da608b
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date: Tue, 6 Sep 2016 09:09:48 +0530
Get after change tests running again
We explicitly trigger redisplay now
Diffstat:
2 files changed, 59 insertions(+), 36 deletions(-)
diff --git a/test/emojify-test.el b/test/emojify-test.el
@@ -92,37 +92,40 @@
(emojify-tests-should-be-emojified (line-beginning-position 4))
(emojify-tests-should-be-emojified (line-beginning-position 5)))))
-;; The after-change tests stopped working after moving to JIT lock :unamused:
-;; (ert-deftest emojify-tests-emojifying-on-comment-uncomment ()
-;; :tags '(core after-change)
-;; (emojify-tests-with-emojified-buffer ":smile:\n:)"
-;; (emacs-lisp-mode)
-;; (emojify-redisplay-emojis-in-region)
-;; (emojify-mode +1)
-;; (emojify-tests-should-not-be-emojified (line-beginning-position))
-;; (emojify-tests-should-not-be-emojified (line-beginning-position 2))
-
-;; (comment-region (point-min) (point-max))
-;; (emojify-tests-should-be-emojified (+ 3 (line-beginning-position)))
-;; (emojify-tests-should-be-emojified (+ 3 (line-beginning-position 2)))
-
-;; (uncomment-region (point-min) (point-max))
-;; (emojify-tests-should-not-be-emojified (line-beginning-position))
-;; (emojify-tests-should-not-be-emojified (line-beginning-position 2))))
-
-;; (ert-deftest emojify-tests-emojifying-on-typing ()
-;; :tags '(core after-change)
-;; (emojify-tests-with-emojified-buffer ""
-;; (emacs-lisp-mode)
-;; (emojify-redisplay-emojis-in-region)
-;; (emojify-mode +1)
-;; (emojify-insert-string "; :)")
-;; (emojify-tests-should-be-emojified 4)
-;; (newline)
-;; (emojify-insert-string "; :smile")
-;; (emojify-tests-should-not-be-emojified (+ 4 (line-beginning-position)))
-;; (emojify-insert-string ":")
-;; (emojify-tests-should-be-emojified (+ 4 (line-beginning-position)))))
+(ert-deftest emojify-tests-emojifying-on-comment-uncomment ()
+ :tags '(core after-change)
+ (emojify-tests-with-emojified-buffer ":smile:\n:)"
+ (emacs-lisp-mode)
+ (emojify-redisplay-emojis-in-region)
+ (emojify-mode +1)
+ (emojify-tests-should-not-be-emojified (line-beginning-position))
+ (emojify-tests-should-not-be-emojified (line-beginning-position 2))
+
+ (comment-region (point-min) (point-max))
+ (emojify-redisplay)
+ (emojify-tests-should-be-emojified (+ 3 (line-beginning-position)))
+ (emojify-tests-should-be-emojified (+ 3 (line-beginning-position 2)))
+
+ (uncomment-region (point-min) (point-max))
+ (emojify-redisplay)
+ (emojify-tests-should-not-be-emojified (line-beginning-position))
+ (emojify-tests-should-not-be-emojified (line-beginning-position 2))))
+
+(ert-deftest emojify-tests-emojifying-on-typing ()
+ :tags '(core after-change)
+ (emojify-tests-with-emojified-buffer ""
+ (emacs-lisp-mode)
+ (emojify-redisplay-emojis-in-region)
+ (emojify-mode +1)
+ (emojify-insert-string "; :)")
+ (emojify-redisplay)
+ (emojify-tests-should-be-emojified 4)
+ (newline)
+ (emojify-insert-string "; :smile")
+ (emojify-tests-should-not-be-emojified (+ 4 (line-beginning-position)))
+ (emojify-insert-string ":")
+ (emojify-redisplay)
+ (emojify-tests-should-be-emojified (+ 4 (line-beginning-position)))))
(ert-deftest emojify-tests-emoji-uncovering ()
:tags '(behaviour point-motion)
@@ -382,7 +385,7 @@
(fundamental-mode)
(let ((count 0))
(emojify-do-for-emojis-in-region (point-min) (point-max)
- (incf count))
+ (cl-incf count))
;; Only one emoji should be displayed
(should (= count 1))
;; The larger emoji should be preferred
@@ -614,7 +617,7 @@ return 4
(goto-char emoji-start)
(call-interactively #'emojify-apropos-copy-emoji)
(should (string= (car kill-ring) (get-text-property (point) 'emojify-text)))
- (incf matches)))
+ (cl-incf matches)))
(should (= matches 2)))
@@ -632,7 +635,7 @@ return 4
(goto-char emoji-start)
(call-interactively #'emojify-apropos-copy-emoji)
(should (string= (car kill-ring) (get-text-property (point) 'emojify-text)))
- (incf matches)))
+ (cl-incf matches)))
(should (= matches 1)))))
diff --git a/test/test-helper.el b/test/test-helper.el
@@ -22,7 +22,7 @@
;; Libs required for tests
(require 'ert)
(require 'el-mock)
-(require 'cl)
+(require 'cl-lib)
(require 'noflet)
;; Load emojify
@@ -40,7 +40,7 @@
;; Helper macros for tests
(defmacro emojify-tests-with-saved-customizations (&rest forms)
- "Run forms saving current customizations and restoring them on completion.
+ "Run FORMS saving current customizations and restoring them on completion.
Helps isolate tests from each other's customizations."
(declare (indent 0))
@@ -80,6 +80,9 @@ Helps isolate tests from each other's customizations."
(emojify-set-emoji-styles emojify-saved-emoji-style))))
(defmacro emojify-tests-with-emojified-buffer (str &rest forms)
+ "Create a buffer with STR and execute FORMS.
+
+The FORMS are executed with emojify enabled."
(declare (indent 1))
;; Run tests in a new buffer
`(let ((test-buffer (get-buffer-create " *emojify-test-buffer*")))
@@ -106,12 +109,17 @@ Helps isolate tests from each other's customizations."
(kill-buffer test-buffer))))))
(defmacro emojify-tests-with-emojified-static-buffer (str &rest forms)
+ "Create a buffer with STR and execute FORMS.
+
+All kinds of dynamic behaviour on buffer are disabled. See
+`emojify-with-saved-buffer-state'"
(declare (indent 1))
`(emojify-tests-with-emojified-buffer ,str
(emojify-with-saved-buffer-state
,@forms)))
(defmacro emojify-tests-should-be-emojified (point)
+ "Assert there is an emoji at POINT."
`(progn
(should-not (get-text-property ,point 'point-left))
(should (get-text-property ,point 'emojified))
@@ -124,6 +132,7 @@ Helps isolate tests from each other's customizations."
(should (get-text-property ,point 'point-entered))))
(defmacro emojify-tests-should-not-be-emojified (point)
+ "Assert there is not emoji at POINT."
`(progn
(should-not (get-text-property ,point 'point-left))
(should-not (get-text-property ,point 'emojified))
@@ -136,6 +145,7 @@ Helps isolate tests from each other's customizations."
(should-not (get-text-property ,point 'point-entered))))
(defmacro emojify-tests-should-be-uncovered (point)
+ "Assert the emoji at POINT is uncovered."
`(progn
(should (get-text-property ,point 'point-left))
(should (get-text-property ,point 'emojified))
@@ -147,9 +157,19 @@ Helps isolate tests from each other's customizations."
(should-not (get-text-property ,point 'display))))
(defun emojify-insert-string (string)
+ "Insert the STRING."
(mapc (lambda (character)
(insert character))
(string-to-vector string)))
+(defun emojify-redisplay ()
+ "Trigger a redisplay."
+ (if noninteractive
+ ;; In noninteractive mode JIT is not called
+ ;; call it
+ (jit-lock-fontify-now)
+ ;; In interactive mode just force redisplay
+ (redisplay t)))
+
(provide 'test-helper)
;;; test-helper.el ends here