commit 6586e398d1c61651ea6a4132f1ffc2672af6fdd3
parent f9641b3e9158182e4e88d31bca40032f49a3d29d
Author: Iqbal Ansari <iqbalansari02@yahoo.com>
Date: Mon, 5 Sep 2016 21:06:10 +0530
Add tests for custom emojis
Diffstat:
2 files changed, 41 insertions(+), 5 deletions(-)
diff --git a/test/emojify-test.el b/test/emojify-test.el
@@ -63,13 +63,34 @@
(emojify-redisplay-emojis-in-region)
(emojify-tests-should-not-be-emojified (point-min))))
+(ert-deftest emojify-test-custom-emojis ()
+ :tags '(core custom-images)
+ (let ((emojify-user-emojis emojify-test-custom-emojis))
+ (emojify-set-emoji-data)
+ (emojify-tests-with-emojified-static-buffer ":neckbeard:
+:troll:"
+ (emojify-tests-should-be-emojified (point-min))
+ (should (equal (get-text-property (point) 'emojify-buffer) (current-buffer)))
+ (should (= (get-text-property (point-min) 'emojify-beginning) (point-min-marker)))
+ (should (= (get-text-property (point) 'emojify-end) (line-end-position 1)))
+ (should (equal (get-text-property (point) 'emojify-text) ":neckbeard:"))
+
+ (emojify-tests-should-be-emojified (line-beginning-position 2))
+ (should (equal (get-text-property (line-beginning-position 2) 'emojify-buffer) (current-buffer)))
+ (should (= (get-text-property (line-beginning-position 2) 'emojify-beginning) (line-beginning-position 2)))
+ (should (= (get-text-property (line-beginning-position 2) 'emojify-end) (point-max-marker)))
+ (should (equal (get-text-property (line-beginning-position 2) 'emojify-text) ":troll:")))))
+
(ert-deftest emojify-tests-mixed-emoji-test ()
:tags '(core mixed)
- (emojify-tests-with-emojified-static-buffer "😉\n:D\nD:\n:smile:"
- (emojify-tests-should-be-emojified (point-min))
- (emojify-tests-should-be-emojified (line-beginning-position 2))
- (emojify-tests-should-be-emojified (line-beginning-position 3))
- (emojify-tests-should-be-emojified (line-beginning-position 4))))
+ (let ((emojify-user-emojis emojify-test-custom-emojis))
+ (emojify-set-emoji-data)
+ (emojify-tests-with-emojified-static-buffer "😉\n:D\nD:\n:smile:\n:neckbeard:"
+ (emojify-tests-should-be-emojified (point-min))
+ (emojify-tests-should-be-emojified (line-beginning-position 2))
+ (emojify-tests-should-be-emojified (line-beginning-position 3))
+ (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 ()
diff --git a/test/test-helper.el b/test/test-helper.el
@@ -28,6 +28,15 @@
;; Load emojify
(require 'emojify)
+;; Define custom emoji config
+(defvar emojify-test-custom-emojis)
+(let* ((project-dir (locate-dominating-file (or (buffer-file-name) load-file-name)
+ ".cask"))
+ (custom-emoji-dir (expand-file-name "test/assets/" project-dir)))
+ (setq emojify-test-custom-emojis
+ `((":troll:" . (("name" . "Troll") ("image" . ,(expand-file-name "trollface.png" custom-emoji-dir)) ("style" . "github")))
+ (":neckbeard:" . (("name" . "Neckbeard") ("image" . ,(expand-file-name "neckbeard.png" custom-emoji-dir)) ("style" . "github"))))))
+
;; Helper macros for tests
(defmacro emojify-tests-with-saved-customizations (&rest forms)
"Run forms saving current customizations and restoring them on completion.
@@ -35,6 +44,9 @@
Helps isolate tests from each other's customizations."
(declare (indent 0))
`(let ((emojify-saved-emoji-json emojify-emoji-json)
+ (emojify-saved-user-emojis emojify-user-emojis)
+ (emojify-saved-user-emojis-parsed emojify--user-emojis)
+ (emojify-saved-emojify-regexps emojify-regexps)
(emojify-saved-display-style emojify-display-style)
(emojify-saved-inhibit-major-modes emojify-inhibit-major-modes)
(emojify-saved-inhibit-in-buffer-functions emojify-inhibit-in-buffer-functions)
@@ -53,6 +65,9 @@ Helps isolate tests from each other's customizations."
(setq emojify-emoji-json emojify-saved-emoji-json
emojify-display-style emojify-saved-display-style
emojify-inhibit-major-modes emojify-saved-inhibit-major-modes
+ emojify-user-emojis emojify-saved-user-emojis
+ emojify--user-emojis emojify-saved-user-emojis-parsed
+ emojify-regexps emojify-saved-emojify-regexps
emojify-inhibit-in-buffer-functions emojify-saved-inhibit-in-buffer-functions
emojify-program-contexts emojify-saved-program-contexts
emojify-inhibit-functions emojify-saved-inhibit-functions