emojify-test.el (31702B)
1 ;;; emojify-test.el --- Tests for emojify -*- lexical-binding: t; -*- 2 3 ;;; Commentary: 4 ;;; Tests for emojify, major use case is to run from the command-line 5 ;;; but can use can be interactively as well. Do M-x `eval-buffer' RET 6 7 ;;; Code: 8 9 ;; For interactive testing 10 (unless noninteractive 11 (load (expand-file-name "test-helper.el") t)) 12 13 ;; Used for testing integration with programming modes 14 (require 'org) 15 (require 'org-agenda) 16 (require 'cc-mode) 17 (require 'bytecomp) 18 19 (ert-deftest emojify-tests-simple-ascii-emoji-test () 20 :tags '(ascii simple) 21 (emojify-tests-with-emojified-static-buffer ":)" 22 (emojify-tests-should-be-emojified (point-min)) 23 (should (equal (get-text-property (point-min) 'emojify-buffer) (current-buffer))) 24 (should (equal (get-text-property (point-min) 'emojify-beginning) (point-min-marker))) 25 (should (equal (get-text-property (point-min) 'emojify-end) (point-max-marker))) 26 (should (equal (get-text-property (point-min) 'emojify-text) ":)")))) 27 28 (ert-deftest emojify-tests-simple-github-emoji-test () 29 :tags '(github simple) 30 (emojify-tests-with-emojified-static-buffer ":smile:" 31 (emojify-tests-should-be-emojified (point-min)) 32 (should (equal (get-text-property (point) 'emojify-buffer) (current-buffer))) 33 (should (equal (get-text-property (point-min) 'emojify-beginning) (point-min-marker))) 34 (should (equal (get-text-property (point) 'emojify-end) (point-max-marker))) 35 (should (equal (get-text-property (point) 'emojify-text) ":smile:")))) 36 37 (ert-deftest emojify-tests-simple-unicode-emoji-test () 38 :tags '(unicode simple) 39 (emojify-tests-with-emojified-static-buffer "😉" 40 (emojify-tests-should-be-emojified (point-min)) 41 (should (equal (get-text-property (point) 'emojify-buffer) (current-buffer))) 42 (should (equal (get-text-property (point-min) 'emojify-beginning) (point-min-marker))) 43 (should (equal (get-text-property (point) 'emojify-end) (point-max-marker))) 44 (should (equal (get-text-property (point) 'emojify-text) "😉"))) 45 46 (emojify-tests-with-emojified-static-buffer "😉" 47 ;; Emojis should be displayed by default in programming mode 48 (emacs-lisp-mode) 49 (emojify-tests-should-be-emojified (point-min)) 50 (should (equal (get-text-property (point) 'emojify-buffer) (current-buffer))) 51 (should (equal (get-text-property (point-min) 'emojify-beginning) (point-min-marker))) 52 (should (equal (get-text-property (point) 'emojify-end) (point-max-marker))) 53 (should (equal (get-text-property (point) 'emojify-text) "😉")) 54 55 ;; Emojis should be displayed by default in non-programming mode 56 (fundamental-mode) 57 (emojify-redisplay-emojis-in-region) 58 (emojify-tests-should-be-emojified (point-min)) 59 60 ;; Emojis should not be displayed if code is not an element in emojify-program-contexts 61 (setq emojify-program-contexts '()) 62 (emacs-lisp-mode) 63 (emojify-redisplay-emojis-in-region) 64 (emojify-tests-should-not-be-emojified (point-min)))) 65 66 (ert-deftest emojify-test-custom-emojis () 67 :tags '(core custom-images) 68 (let ((emojify-user-emojis emojify-test-custom-emojis)) 69 (emojify-set-emoji-data) 70 (emojify-tests-with-emojified-static-buffer ":neckbeard: 71 :troll:" 72 (emojify-tests-should-be-emojified (point-min)) 73 (should (equal (get-text-property (point) 'emojify-buffer) (current-buffer))) 74 (should (= (get-text-property (point-min) 'emojify-beginning) (point-min-marker))) 75 (should (= (get-text-property (point) 'emojify-end) (line-end-position 1))) 76 (should (equal (get-text-property (point) 'emojify-text) ":neckbeard:")) 77 78 (emojify-tests-should-be-emojified (line-beginning-position 2)) 79 (should (equal (get-text-property (line-beginning-position 2) 'emojify-buffer) (current-buffer))) 80 (should (= (get-text-property (line-beginning-position 2) 'emojify-beginning) (line-beginning-position 2))) 81 (should (= (get-text-property (line-beginning-position 2) 'emojify-end) (point-max-marker))) 82 (should (equal (get-text-property (line-beginning-position 2) 'emojify-text) ":troll:"))))) 83 84 (ert-deftest emojify-tests-mixed-emoji-test () 85 :tags '(core mixed) 86 (let ((emojify-user-emojis emojify-test-custom-emojis)) 87 (emojify-set-emoji-data) 88 (emojify-tests-with-emojified-static-buffer "😉\n:D\nD:\n:smile:\n:neckbeard:" 89 (emojify-tests-should-be-emojified (point-min)) 90 (emojify-tests-should-be-emojified (line-beginning-position 2)) 91 (emojify-tests-should-be-emojified (line-beginning-position 3)) 92 (emojify-tests-should-be-emojified (line-beginning-position 4)) 93 (emojify-tests-should-be-emojified (line-beginning-position 5))))) 94 95 (ert-deftest emojify-tests-emoji-uncovering () 96 :tags '(behaviour point-motion) 97 (emojify-tests-with-emojified-buffer " :)" 98 (setq emojify-point-entered-behaviour 'uncover) 99 (execute-kbd-macro (kbd "C-f") 2) 100 (emojify-tests-should-be-uncovered (point)))) 101 102 (ert-deftest emojify-tests-emoji-echoing () 103 :tags '(behaviour point-motion) 104 (emojify-tests-with-emojified-buffer " :)" 105 (with-mock 106 ;; Since emojify checks that there is no message being displayed 107 ;; before echoing the emoji, we need to stub out current-message 108 ;; too otherwise emojify does not echo the message since messages 109 ;; from other tests are being displayed 110 (stub current-message => nil) 111 (mock (message ":)")) 112 (setq emojify-point-entered-behaviour 'echo) 113 (execute-kbd-macro (kbd "C-f")) 114 (emojify-tests-should-be-emojified (point))))) 115 116 (ert-deftest emojify-tests-custom-point-entered-function () 117 :tags '(behaviour point-motion) 118 (emojify-tests-with-emojified-buffer " :)" 119 (setq emojify-point-entered-behaviour (lambda (buffer emoji-text emoji-start emoji-end) 120 (should (equal buffer (current-buffer))) 121 (should (equal emoji-text ":)")) 122 (should (equal emoji-start (1+ (point-min)))) 123 (should (equal emoji-start (point-max))))) 124 (goto-char (1+ (point-min))) 125 (emojify-tests-should-be-emojified (point)))) 126 127 (ert-deftest emojify-tests-emojify-setting-styles () 128 :tags '(styles github ascii) 129 (emojify-tests-with-emojified-static-buffer ":) 😄 :smile: return" 130 (let ((ascii-emoji-pos (point-min)) 131 (unicode-emoji-pos (+ (point-min) (length ":) "))) 132 (github-emoji-pos (+ (point-min) (length ":) 😄 "))) 133 (prettify-emoji-pos (+ (point-min) (length ":) 😄 :smile: ")))) 134 135 (setq emojify-composed-text-p t) 136 (setq prettify-symbols-alist 137 '(("return" . ?↪))) 138 139 (setq emojify-composed-text-p t) 140 141 (when (fboundp 'prettify-symbols-mode) 142 (prettify-symbols-mode +1) 143 ;; On Emacs 25.1 fontification does not happen automatically 144 (when (fboundp 'font-lock-ensure) (font-lock-ensure))) 145 146 (emojify-set-emoji-styles '(ascii)) 147 (emojify-tests-should-be-emojified ascii-emoji-pos) 148 (emojify-tests-should-not-be-emojified unicode-emoji-pos) 149 (emojify-tests-should-not-be-emojified prettify-emoji-pos) 150 (emojify-tests-should-not-be-emojified github-emoji-pos) 151 152 (emojify-set-emoji-styles '(unicode)) 153 (emojify-tests-should-not-be-emojified ascii-emoji-pos) 154 (emojify-tests-should-be-emojified unicode-emoji-pos) 155 (when (fboundp 'prettify-symbols-mode) 156 (emojify-tests-should-be-emojified prettify-emoji-pos)) 157 (emojify-tests-should-not-be-emojified github-emoji-pos) 158 159 (emojify-set-emoji-styles '(github)) 160 (emojify-tests-should-not-be-emojified ascii-emoji-pos) 161 (emojify-tests-should-not-be-emojified unicode-emoji-pos) 162 (emojify-tests-should-not-be-emojified prettify-emoji-pos) 163 (emojify-tests-should-be-emojified github-emoji-pos) 164 165 (emojify-set-emoji-styles '(ascii unicode github)) 166 (emojify-tests-should-be-emojified ascii-emoji-pos) 167 (emojify-tests-should-be-emojified unicode-emoji-pos) 168 (when (fboundp 'prettify-symbols-mode) 169 (emojify-tests-should-be-emojified prettify-emoji-pos)) 170 (emojify-tests-should-be-emojified github-emoji-pos) 171 172 (emojify-set-emoji-styles nil) 173 (emojify-tests-should-not-be-emojified ascii-emoji-pos) 174 (emojify-tests-should-not-be-emojified unicode-emoji-pos) 175 (emojify-tests-should-not-be-emojified prettify-emoji-pos) 176 (emojify-tests-should-not-be-emojified github-emoji-pos)))) 177 178 (ert-deftest emojify-tests-program-contexts () 179 :tags '(core prog contextual) 180 (emojify-tests-with-emojified-static-buffer ";; :) :smile:\n\":smile:\"\n8) 💜 :smile:" 181 (let* ((comment-ascii-emoji-pos (+ 3 (point-min))) 182 (comment-github-emoji-pos (+ comment-ascii-emoji-pos (length ":) "))) 183 (string-github-emoji-pos (1+ (line-beginning-position 2))) 184 (prog-ascii-emoji-pos (line-beginning-position 3)) 185 (prog-unicode-emoji-pos (+ 3 prog-ascii-emoji-pos)) 186 (prog-github-emoji-pos (+ 2 prog-unicode-emoji-pos))) 187 (emacs-lisp-mode) 188 (setq emojify-program-contexts '(comments string code)) 189 (emojify-redisplay-emojis-in-region) 190 (emojify-tests-should-be-emojified comment-ascii-emoji-pos) 191 (emojify-tests-should-be-emojified comment-github-emoji-pos) 192 (emojify-tests-should-be-emojified string-github-emoji-pos) 193 (emojify-tests-should-not-be-emojified prog-ascii-emoji-pos) 194 (emojify-tests-should-be-emojified prog-unicode-emoji-pos) 195 (emojify-tests-should-not-be-emojified prog-github-emoji-pos) 196 197 (setq emojify-program-contexts '(comments)) 198 (emojify-redisplay-emojis-in-region) 199 (emojify-tests-should-be-emojified comment-ascii-emoji-pos) 200 (emojify-tests-should-be-emojified comment-github-emoji-pos) 201 (emojify-tests-should-not-be-emojified string-github-emoji-pos) 202 (emojify-tests-should-not-be-emojified prog-ascii-emoji-pos) 203 (emojify-tests-should-not-be-emojified prog-unicode-emoji-pos) 204 (emojify-tests-should-not-be-emojified prog-github-emoji-pos) 205 206 (setq emojify-program-contexts '(string)) 207 (emojify-redisplay-emojis-in-region) 208 (emojify-tests-should-not-be-emojified comment-ascii-emoji-pos) 209 (emojify-tests-should-not-be-emojified comment-github-emoji-pos) 210 (emojify-tests-should-be-emojified string-github-emoji-pos) 211 (emojify-tests-should-not-be-emojified prog-ascii-emoji-pos) 212 (emojify-tests-should-not-be-emojified prog-unicode-emoji-pos) 213 (emojify-tests-should-not-be-emojified prog-github-emoji-pos) 214 215 (setq emojify-program-contexts '(code)) 216 (emojify-redisplay-emojis-in-region) 217 (emojify-tests-should-not-be-emojified comment-ascii-emoji-pos) 218 (emojify-tests-should-not-be-emojified comment-github-emoji-pos) 219 (emojify-tests-should-not-be-emojified string-github-emoji-pos) 220 (emojify-tests-should-not-be-emojified prog-ascii-emoji-pos) 221 (emojify-tests-should-be-emojified prog-unicode-emoji-pos) 222 (emojify-tests-should-not-be-emojified prog-github-emoji-pos) 223 224 (setq emojify-program-contexts '()) 225 (emojify-redisplay-emojis-in-region) 226 (emojify-tests-should-not-be-emojified comment-ascii-emoji-pos) 227 (emojify-tests-should-not-be-emojified comment-github-emoji-pos) 228 (emojify-tests-should-not-be-emojified string-github-emoji-pos) 229 (emojify-tests-should-not-be-emojified prog-ascii-emoji-pos) 230 (emojify-tests-should-not-be-emojified prog-unicode-emoji-pos) 231 (emojify-tests-should-not-be-emojified prog-github-emoji-pos)))) 232 233 (ert-deftest emojify-tests-ascii-emoji-contexts () 234 :tags '(core text contextual) 235 ;; At start of comment 236 (emojify-tests-with-emojified-static-buffer ";:)" 237 (emacs-lisp-mode) 238 (emojify-redisplay-emojis-in-region) 239 (emojify-tests-should-be-emojified (1+ (point-min)))) 240 241 ;; In comment after space 242 (emojify-tests-with-emojified-static-buffer "; :)" 243 (emacs-lisp-mode) 244 (emojify-redisplay-emojis-in-region) 245 (emojify-tests-should-be-emojified (+ 2 (point-min)))) 246 247 ;; Inside a comment 248 (emojify-tests-with-emojified-static-buffer "/**\n:)" 249 (c-mode) 250 (emojify-redisplay-emojis-in-region) 251 (emojify-tests-should-be-emojified (line-beginning-position 2))) 252 253 ;; Immediately after a word 254 (emojify-tests-with-emojified-static-buffer "A:)" 255 (emojify-tests-should-not-be-emojified (1+ (point-min)))) 256 257 ;; Immediately before a word 258 (emojify-tests-with-emojified-static-buffer ":)A" 259 (emojify-tests-should-not-be-emojified (1+ (point-min)))) 260 261 ;; Immediately before a closing bracket 262 (emojify-tests-with-emojified-static-buffer ":))" 263 (emojify-tests-should-be-emojified (1+ (point-min)))) 264 265 ;; Immediately after a punctuation character 266 (emojify-tests-with-emojified-static-buffer "!:)" 267 (emojify-tests-should-not-be-emojified (1+ (point-min)))) 268 269 ;; Following a punctuation and a space 270 (emojify-tests-with-emojified-static-buffer "! :)" 271 (emojify-tests-should-be-emojified (+ 2 (point-min)))) 272 273 ;; Outside a comment 274 (emojify-tests-with-emojified-static-buffer "/**/:)" 275 (c-mode) 276 (emojify-redisplay-emojis-in-region) 277 (emojify-tests-should-not-be-emojified (+ 4 (point-min)))) 278 279 ;; Surrounded by comments 280 (emojify-tests-with-emojified-static-buffer "/*:)*/" 281 (c-mode) 282 (emojify-redisplay-emojis-in-region) 283 (emojify-tests-should-not-be-emojified (+ 2 (point-min))))) 284 285 (ert-deftest emojify-tests-multiple-emojis-in-sequence () 286 "See Github issue #6" 287 :tags '(core contextual) 288 (emojify-tests-with-emojified-static-buffer ":100::smile: 289 :100:a:smile: 290 🎆😃 291 🎆a😃 292 😉:wink: 293 :100:😃 294 :100:a😃" 295 ;; Github emojis 296 (emojify-tests-should-be-emojified (point-min)) 297 (emojify-tests-should-be-emojified (+ (point-min) 5)) 298 (emojify-tests-should-be-emojified (line-beginning-position 2)) 299 (emojify-tests-should-be-emojified (+ (line-beginning-position 2) 6)) 300 301 ;; Unicode emojis 302 (emojify-tests-should-be-emojified (line-beginning-position 3)) 303 (emojify-tests-should-be-emojified (+ (line-beginning-position 3) 1)) 304 (emojify-tests-should-be-emojified (line-beginning-position 4)) 305 (emojify-tests-should-be-emojified (+ (line-beginning-position 4) 2)) 306 307 ;; Mixed emojis 308 (emojify-tests-should-be-emojified (line-beginning-position 5)) 309 (emojify-tests-should-be-emojified (+ (line-beginning-position 5) 1)) 310 (emojify-tests-should-be-emojified (line-beginning-position 6)) 311 (emojify-tests-should-be-emojified (+ (line-beginning-position 6) 5)) 312 (emojify-tests-should-be-emojified (line-beginning-position 7)) 313 (emojify-tests-should-be-emojified (+ (line-beginning-position 7) 6)))) 314 315 (ert-deftest emojify-tests-emojifying-lists () 316 :tags '(core contextual) 317 (emojify-tests-with-emojified-static-buffer ":]" 318 (emojify-tests-should-be-emojified (point-min))) 319 320 (emojify-tests-with-emojified-static-buffer "[ :]" 321 (emojify-tests-should-not-be-emojified (+ 3 (point-min)))) 322 323 (emojify-tests-with-emojified-static-buffer ";; 8)" 324 (emojify-tests-should-be-emojified (+ 3 (point-min)))) 325 326 (emojify-tests-with-emojified-static-buffer ":( 327 :)" 328 (fundamental-mode) 329 (emojify-redisplay-emojis-in-region) 330 (emojify-tests-should-be-emojified (point-min)) 331 (emojify-tests-should-be-emojified (line-beginning-position 2))) 332 333 (emojify-tests-with-emojified-static-buffer "( 334 :)" 335 (fundamental-mode) 336 (emojify-redisplay-emojis-in-region) 337 (emojify-tests-should-not-be-emojified (point-min)) 338 (emojify-tests-should-not-be-emojified (line-beginning-position 2))) 339 340 (emojify-tests-with-emojified-static-buffer ";; (lambda () 8)" 341 (emacs-lisp-mode) 342 (emojify-redisplay-emojis-in-region) 343 (emojify-tests-should-not-be-emojified (+ 14 (point-min))))) 344 345 (ert-deftest emojify-tests-overlapping-emojis () 346 :tags '(core) 347 (emojify-tests-with-emojified-static-buffer "👲🏽" 348 (fundamental-mode) 349 (let ((count 0)) 350 (emojify-do-for-emojis-in-region (point-min) (point-max) 351 (cl-incf count)) 352 ;; Only one emoji should be displayed 353 (should (= count 1)) 354 ;; The larger emoji should be preferred 355 (should (string= (get-text-property (point-min) 'emojify-text) 356 "👲🏽"))))) 357 358 (ert-deftest emojify-tests-emojifying-org-mode-buffers () 359 :tags '(org-mode contextual) 360 (emojify-tests-with-emojified-static-buffer "* Test :books:\n:books:\n* Test :book:tag:\n" 361 (org-mode) 362 (emojify-redisplay-emojis-in-region) 363 (emojify-tests-should-not-be-emojified (1- (line-end-position))) 364 (emojify-tests-should-be-emojified (line-beginning-position 2)) 365 (emojify-tests-should-not-be-emojified (- (line-end-position 3) 5))) 366 367 (emojify-tests-with-emojified-static-buffer "8)" 368 ;; org-mode in Emacs v24.3 failed in read only buffers 369 ;; if first item was not a headline 370 (with-mock (stub org-set-startup-visibility => nil) 371 (org-mode)) 372 (emojify-redisplay-emojis-in-region) 373 (emojify-tests-should-not-be-emojified (point-min))) 374 375 (emojify-tests-with-emojified-static-buffer "* 8)" 376 (org-mode) 377 (emojify-redisplay-emojis-in-region) 378 (emojify-tests-should-be-emojified (1- (point-max)))) 379 380 (emojify-tests-with-emojified-static-buffer "#+BEGIN_SRC emacs-lisp\n:)\n#+END_SRC" 381 (org-mode) 382 (emojify-redisplay-emojis-in-region) 383 (emojify-tests-should-not-be-emojified (line-beginning-position 2))) 384 385 ;; TODO: This does not work yet 386 ;; (emojify-tests-with-emojified-static-buffer "8) 8)" 387 ;; (org-mode) 388 ;; (emojify-redisplay-emojis-in-region) 389 ;; (emojify-tests-should-be-emojified (1- (point-max))) 390 ;; (emojify-tests-should-not-be-emojified (1+ (point-min)))) 391 392 ;; 8) should not emojified if it is a list item 393 (emojify-tests-with-emojified-static-buffer "7) *) 394 8) 8) 395 9) :/" 396 (org-mode) 397 (emojify-redisplay-emojis-in-region) 398 (emojify-tests-should-not-be-emojified (line-beginning-position 2)) 399 (emojify-tests-should-be-emojified (1- (line-end-position 2)))) 400 401 ;; Emojis that are part of org-mode tags should not be emojified 402 (emojify-tests-with-emojified-static-buffer "* Test :p\n* Test2 :p:" 403 (org-mode) 404 (emojify-redisplay-emojis-in-region) 405 (emojify-tests-should-be-emojified (1- (line-end-position))) 406 (emojify-tests-should-not-be-emojified (- (line-end-position 2) 3))) 407 408 (emojify-tests-with-emojified-static-buffer "* Test :books:\n:books:" 409 (org-agenda-mode) 410 (emojify-redisplay-emojis-in-region) 411 (emojify-tests-should-not-be-emojified (1- (line-end-position))) 412 (emojify-tests-should-be-emojified (line-beginning-position 2)))) 413 414 (ert-deftest emojify-tests-uncover-on-isearch () 415 :tags '(isearch) 416 (emojify-tests-with-emojified-buffer "Testing isearch\n:books:" 417 (with-mock 418 (setq emojify-reveal-on-isearch t) 419 ;; We do not want to be bothered with isearch messages 420 (stub message => nil) 421 (emojify-tests-should-be-emojified (line-beginning-position 2)) 422 (isearch-mode +1) 423 (execute-kbd-macro "boo") 424 ;; Emoji should be uncovered when point enters it in isearch-mode 425 (emojify-tests-should-be-uncovered (line-beginning-position)) 426 ;; Emoji should be restored on leaving the underlying text 427 (execute-kbd-macro "") 428 (emojify-tests-should-be-emojified (line-beginning-position 2)) 429 430 ;; Turn off revealing on isearch 431 (setq emojify-reveal-on-isearch nil) 432 ;; We do not want to be bothered with isearch messages 433 (stub message => nil) 434 (emojify-tests-should-be-emojified (line-beginning-position 2)) 435 (isearch-mode +1) 436 (execute-kbd-macro "boo") 437 ;; Emoji should be uncovered when point enters it in isearch-mode 438 (emojify-tests-should-be-emojified (line-beginning-position))))) 439 440 (ert-deftest emojify-tests-electric-delete () 441 :tags '(electric-delete) 442 (emojify-tests-with-emojified-buffer "Unicode emoji 😉\nGithub emoji :wink:\nAscii emoji ;)" 443 (goto-char (line-end-position)) 444 (let ((final-line-end (get-text-property (1- (point)) 'emojify-beginning))) 445 (execute-kbd-macro [backspace]) 446 (emojify-tests-should-not-be-emojified (line-end-position)) 447 (should (equal (copy-marker (line-end-position)) final-line-end)))) 448 449 (emojify-tests-with-emojified-buffer "Unicode emoji 😉\nGithub emoji :wink:\nAscii emoji ;)" 450 (goto-char (line-end-position 2)) 451 (let ((final-line-end (get-text-property (1- (point)) 'emojify-beginning))) 452 (execute-kbd-macro [backspace]) 453 (emojify-tests-should-not-be-emojified (line-end-position)) 454 (should (equal (copy-marker (line-end-position)) final-line-end)))) 455 456 (emojify-tests-with-emojified-buffer "Unicode emoji 😉\nGithub emoji :wink:\nAscii emoji ;)" 457 (goto-char (line-end-position 3)) 458 (let ((final-line-end (get-text-property (1- (point)) 'emojify-beginning))) 459 (execute-kbd-macro [backspace]) 460 (emojify-tests-should-not-be-emojified (line-end-position)) 461 (should (equal (copy-marker (line-end-position)) final-line-end)))) 462 463 (emojify-tests-with-emojified-buffer ";) 😉:wink:" 464 (dotimes (n 4) 465 (execute-kbd-macro (kbd "C-d")) 466 (emojify-redisplay-emojis-in-region)) 467 (should (equal (point-min) (point-max)))) 468 469 (emojify-tests-with-emojified-buffer "😉:wink: ;)" 470 (goto-char (point-max)) 471 (dotimes (_ 4) 472 (execute-kbd-macro [backspace])) 473 (should (equal (point-min) (point-max)))) 474 475 (emojify-tests-with-emojified-buffer "😉 :smile:" 476 (goto-char (1+ (point-min))) 477 (dotimes (_ 3) 478 (execute-kbd-macro (kbd "C-d")) 479 (emojify-redisplay-emojis-in-region)) 480 (should (equal (1+ (point-min)) (point-max)))) 481 482 (emojify-tests-with-emojified-buffer "😉:wink: ;)" 483 "Integration with delsel mode" 484 (with-mock 485 (stub message => nil) 486 (delete-selection-mode +1) 487 (set-mark-command nil) 488 (activate-mark) 489 (goto-char (point-max)) 490 (exchange-point-and-mark) 491 (let ((this-command 'emojify-delete-emoji-forward)) 492 (delete-selection-pre-hook)) 493 (should (equal (point-min) (point-max)))))) 494 495 (ert-deftest emojify-test-composition () 496 :tags '(composition) 497 (emojify-tests-with-emojified-static-buffer "a == b" 498 (setq emojify-composed-text-p t) 499 (compose-region 1 2 (concat " " (list #Xe154))) 500 (compose-region 3 5 (concat " " (list #Xe10f))) 501 (compose-region 6 7 (concat " " (list #Xe155))) 502 (emojify-string (buffer-string)))) 503 504 (ert-deftest emojify-tests-prettify-symbols () 505 :tags '(prettify-symbols) 506 (when (fboundp 'prettify-symbols-mode) 507 (emojify-tests-with-emojified-static-buffer "try: 508 x = 1 509 except: 510 raise(Exception) 511 lambdalambda 512 \"lambda\" 513 yield 3 514 return 4 515 " 516 (setq emojify-composed-text-p t) 517 (emojify-set-emoji-styles '(ascii unicode github)) 518 (python-mode) 519 (setq-local prettify-symbols-alist 520 '(("return" . ?↪) 521 ("try" . ?😱) 522 ("except" . ?⛐) 523 ("raise" . ?💥))) 524 (emojify-tests-should-not-be-emojified (point-min)) 525 (emojify-tests-should-not-be-emojified (line-beginning-position 3)) 526 (emojify-tests-should-not-be-emojified (+ (line-beginning-position 4) 5)) 527 (emojify-tests-should-not-be-emojified (line-beginning-position 5)) 528 (emojify-tests-should-not-be-emojified (line-beginning-position 6)) 529 (emojify-tests-should-not-be-emojified (line-beginning-position 7)) 530 (emojify-tests-should-not-be-emojified (line-beginning-position 8)) 531 (prettify-symbols-mode +1) 532 ;; On Emacs 25.1 fontification does not happen automatically 533 (when (fboundp 'font-lock-ensure) 534 (font-lock-ensure) 535 (emojify-redisplay-emojis-in-region)) 536 (emojify-tests-should-be-emojified (point-min)) 537 (should (equal (get-text-property (point-min) 'emojify-text) "😱")) 538 (emojify-tests-should-not-be-emojified (line-beginning-position 3)) 539 (emojify-tests-should-be-emojified (+ (line-beginning-position 4) 5)) 540 (should (equal (get-text-property (+ (line-beginning-position 4) 5) 'emojify-text) "💥")) 541 (emojify-tests-should-not-be-emojified (line-beginning-position 5)) 542 (emojify-tests-should-not-be-emojified (line-beginning-position 6)) 543 (emojify-tests-should-not-be-emojified (line-beginning-position 7)) 544 (emojify-tests-should-be-emojified (line-beginning-position 8)) 545 (should (equal (get-text-property (line-beginning-position 8) 'emojify-text) "↪")) 546 (prettify-symbols-mode -1) 547 ;; On Emacs 25.1 fontification does not happen automatically 548 (when (fboundp 'font-lock-ensure) 549 (font-lock-ensure) 550 (emojify-redisplay-emojis-in-region)) 551 (emojify-tests-should-not-be-emojified (point-min)) 552 (emojify-tests-should-not-be-emojified (line-beginning-position 3)) 553 (emojify-tests-should-not-be-emojified (+ (line-beginning-position 4) 5)) 554 (emojify-tests-should-not-be-emojified (line-beginning-position 6)) 555 (emojify-tests-should-not-be-emojified (line-beginning-position 5)) 556 (emojify-tests-should-not-be-emojified (line-beginning-position 6)) 557 (emojify-tests-should-not-be-emojified (line-beginning-position 7))))) 558 559 560 (unless (version< emacs-version "26.1") 561 (ert-deftest emojify-tests-org-source-blocks () 562 :tags '(org-mode contextual) 563 (emojify-tests-with-emojified-static-buffer "#+begin_src markdown 564 :smile: 565 :) 566 :slight_smile: 567 #+end_src 568 569 #+begin_src emacs-lisp 570 \":smile:\" 571 ;; :smile: 572 :smile: 573 574 \":)\" 575 ;; :) 576 :) 577 578 \"🙂\" 579 ;; 🙂 580 🙂 581 #+end_src 582 " 583 (emojify-set-emoji-styles '(ascii unicode github)) 584 (setq emojify-program-contexts '(comments string code)) 585 586 (org-mode) 587 (when (fboundp 'font-lock-ensure) 588 (font-lock-ensure) 589 (emojify-redisplay-emojis-in-region)) 590 591 ;; The emojis should be always displayed for org source block for 592 ;; non-programming languages 593 (emojify-tests-should-be-emojified (line-beginning-position 2)) 594 (emojify-tests-should-be-emojified (line-beginning-position 3)) 595 (emojify-tests-should-be-emojified (line-beginning-position 4)) 596 597 ;; In org source block for programming languages emojis should 598 ;; be displayed according to emojify-program-contexts 599 (emojify-tests-should-be-emojified (1+ (line-beginning-position 8))) 600 (emojify-tests-should-be-emojified (+ 3 (line-beginning-position 9))) 601 (emojify-tests-should-not-be-emojified (line-beginning-position 10)) 602 603 (emojify-tests-should-be-emojified (1+ (line-beginning-position 12))) 604 (emojify-tests-should-be-emojified (+ 3 (line-beginning-position 13))) 605 (emojify-tests-should-not-be-emojified (line-beginning-position 14)) 606 607 (emojify-tests-should-be-emojified (1+ (line-beginning-position 16))) 608 (emojify-tests-should-be-emojified (+ 3 (line-beginning-position 17))) 609 (emojify-tests-should-be-emojified (line-beginning-position 18))))) 610 611 (ert-deftest emojify-tests-prettify-symbols-with-custom-images () 612 :tags '(prettify-symbols) 613 (when (fboundp 'prettify-symbols-mode) 614 (let ((emojify-user-emojis emojify-test-custom-emojis)) 615 (emojify-set-emoji-data) 616 (emojify-tests-with-emojified-static-buffer "try: 617 lambda x: x 618 except: 619 raise(Exception) 620 621 yield 3 622 return 4 623 " 624 (setq emojify-composed-text-p t) 625 (emojify-set-emoji-styles '(ascii unicode github)) 626 (python-mode) 627 (setq-local prettify-symbols-alist 628 '(("return" . ?↪) 629 ("try" . ?😱) 630 ("except" . ?⛐) 631 ("lambda" . ?λ) 632 ("raise" . ?💥))) 633 (emojify-tests-should-not-be-emojified (+ (line-beginning-position 2) 5)) 634 (prettify-symbols-mode +1) 635 ;; On Emacs 25.1 fontification does not happen automatically 636 (when (fboundp 'font-lock-ensure) 637 (font-lock-ensure) 638 (emojify-redisplay-emojis-in-region)) 639 (emojify-tests-should-be-emojified (point-min)) 640 (emojify-tests-should-be-emojified (+ (line-beginning-position 2) 5)) 641 (emojify-tests-should-not-be-emojified (line-beginning-position 3)) 642 (emojify-tests-should-be-emojified (+ (line-beginning-position 4) 5)) 643 (emojify-tests-should-not-be-emojified (line-beginning-position 6)) 644 (emojify-tests-should-be-emojified (line-beginning-position 7)))))) 645 646 (ert-deftest emojify-tests-apropos () 647 :tags '(apropos) 648 (emojify-apropos-emoji "squi") 649 ;; Window with results should be visible 650 (with-mock 651 (stub message => nil) 652 (should (get-buffer-window emojify-apropos-buffer-name)) 653 (let ((matches 0)) 654 655 (with-current-buffer emojify-apropos-buffer-name 656 ;; Force a display of emojis 657 (emojify-redisplay-emojis-in-region (point-min) (point-max)) 658 (emojify-do-for-emojis-in-region (point-min) (point-max) 659 (goto-char emoji-start) 660 (call-interactively #'emojify-apropos-copy-emoji) 661 (should (string= (car kill-ring) (get-text-property (point) 'emojify-text))) 662 (cl-incf matches))) 663 664 (should (= matches 2))) 665 666 ;; Test with custom emoji 667 (let ((emojify-user-emojis emojify-test-custom-emojis) 668 (matches 0)) 669 670 (emojify-set-emoji-data) 671 (emojify-apropos-emoji "lambda") 672 (should (get-buffer-window emojify-apropos-buffer-name)) 673 674 (with-current-buffer emojify-apropos-buffer-name 675 (emojify-redisplay-emojis-in-region (point-min) (point-max)) 676 (emojify-do-for-emojis-in-region (point-min) (point-max) 677 (goto-char emoji-start) 678 (call-interactively #'emojify-apropos-copy-emoji) 679 (should (string= (car kill-ring) (get-text-property (point) 'emojify-text))) 680 (cl-incf matches))) 681 682 (should (= matches 1))))) 683 684 (ert-deftest emojify-tests-download-confirmation () 685 :tags '(download) 686 ;; Tests in interactive mode 687 (let ((noninteractive nil)) 688 ;; Prompt user for confirmation if `emojify-download-emojis-p' is `ask' 689 (let ((emojify-download-emojis-p 'ask)) 690 (with-mock 691 (mock (yes-or-no-p *) => t) 692 (should (emojify--confirm-emoji-download))) 693 (with-mock 694 (mock (yes-or-no-p *) => nil) 695 (should-not (emojify--confirm-emoji-download)))) 696 697 ;; Do not prompt user for confirmation if `emojify-download-emojis-p' is `t' 698 (let ((emojify-download-emojis-p t)) 699 (with-mock 700 (stub yes-or-no-p => (error "`emojify--confirm-emoji-download' should prompt user, if `emojify-download-emojis-p' is t")) 701 (should (emojify--confirm-emoji-download)))) 702 703 ;; Do not prompt user for confirmation if `emojify-download-emojis-p' is `nil' 704 (let ((emojify-download-emojis-p nil)) 705 (with-mock 706 (stub yes-or-no-p => (error "`emojify--confirm-emoji-download' should prompt user, if `emojify-download-emojis-p' is nil")) 707 (should-not (emojify--confirm-emoji-download))))) 708 709 ;; Do not prompt user for confirmation in noninteractive mode 710 (let ((emojify-download-emojis-p 'ask) 711 (noninteractive t)) 712 (with-mock 713 (stub yes-or-no-p => (error "`emojify--confirm-emoji-download' should prompt user, in non-interactive mode")) 714 (should-not (emojify--confirm-emoji-download))))) 715 716 (ert-deftest emojify-tests-no-byte-compilation-warnings () 717 :tags '(byte-compilation) 718 (with-mock 719 (stub message => nil) 720 (stub byte-compile-dest-file => "/tmp/emojify.elc") 721 (should (byte-compile-file (locate-library "emojify.el"))))) 722 723 ;; So that tests can be run simply by doing `eval-buffer' 724 (unless noninteractive 725 (ert "^emojify-")) 726 727 (provide 'emojify-test) 728 ;;; emojify-test.el ends here