diff options
| author | F. Jason Park | 2021-07-09 20:03:51 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-04-08 14:23:51 -0700 |
| commit | 22104de5daa12e82bb6a246f05f4cd2927eb37a3 (patch) | |
| tree | 6741dfc2814abf9b9893011d94ea323a774c07af | |
| parent | 9aa2806fdc3a440a9f108779f2f4a6972c203aff (diff) | |
| download | emacs-22104de5daa12e82bb6a246f05f4cd2927eb37a3.tar.gz emacs-22104de5daa12e82bb6a246f05f4cd2927eb37a3.zip | |
Add missing colors to erc-irccontrols-mode
* lisp/erc/erc-goodies.el (erc-spoiler-face): Add new face.
(erc--controls-additional-colors): Add remaining 16-99 colors.
(erc-get-bg-color-face, erc-get-fg-color-face): Look up extended
colors in table.
(erc-controls-remove-regexp, erc-controls-highlight-regexp): Convert
to `rx' forms and move above first use to eliminate intra-file forward
declarations.
(erc-controls-propertize): Support spoilers.
* test/lisp/erc/erc-goodies-tests.el: New file. (Bug#60954.)
| -rw-r--r-- | lisp/erc/erc-goodies.el | 77 | ||||
| -rw-r--r-- | test/lisp/erc/erc-goodies-tests.el | 253 |
2 files changed, 312 insertions, 18 deletions
diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 7ff5b1aecdf..5ddacb643fd 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el | |||
| @@ -30,8 +30,6 @@ | |||
| 30 | ;;; Code: | 30 | ;;; Code: |
| 31 | 31 | ||
| 32 | (eval-when-compile (require 'cl-lib)) | 32 | (eval-when-compile (require 'cl-lib)) |
| 33 | (defvar erc-controls-highlight-regexp) | ||
| 34 | (defvar erc-controls-remove-regexp) | ||
| 35 | (require 'erc) | 33 | (require 'erc) |
| 36 | 34 | ||
| 37 | (defun erc-imenu-setup () | 35 | (defun erc-imenu-setup () |
| @@ -243,6 +241,12 @@ The value `erc-interpret-controls-p' must also be t for this to work." | |||
| 243 | "ERC inverse face." | 241 | "ERC inverse face." |
| 244 | :group 'erc-faces) | 242 | :group 'erc-faces) |
| 245 | 243 | ||
| 244 | (defface erc-spoiler-face | ||
| 245 | '((((background light)) :foreground "DimGray" :background "DimGray") | ||
| 246 | (((background dark)) :foreground "LightGray" :background "LightGray")) | ||
| 247 | "ERC spoiler face." | ||
| 248 | :group 'erc-faces) | ||
| 249 | |||
| 246 | (defface erc-underline-face '((t :underline t)) | 250 | (defface erc-underline-face '((t :underline t)) |
| 247 | "ERC underline face." | 251 | "ERC underline face." |
| 248 | :group 'erc-faces) | 252 | :group 'erc-faces) |
| @@ -345,19 +349,38 @@ The value `erc-interpret-controls-p' must also be t for this to work." | |||
| 345 | "ERC face." | 349 | "ERC face." |
| 346 | :group 'erc-faces) | 350 | :group 'erc-faces) |
| 347 | 351 | ||
| 352 | ;; https://lists.gnu.org/archive/html/emacs-erc/2021-07/msg00005.html | ||
| 353 | (defvar erc--controls-additional-colors | ||
| 354 | ["#470000" "#472100" "#474700" "#324700" "#004700" "#00472c" | ||
| 355 | "#004747" "#002747" "#000047" "#2e0047" "#470047" "#47002a" | ||
| 356 | "#740000" "#743a00" "#747400" "#517400" "#007400" "#007449" | ||
| 357 | "#007474" "#004074" "#000074" "#4b0074" "#740074" "#740045" | ||
| 358 | "#b50000" "#b56300" "#b5b500" "#7db500" "#00b500" "#00b571" | ||
| 359 | "#00b5b5" "#0063b5" "#0000b5" "#7500b5" "#b500b5" "#b5006b" | ||
| 360 | "#ff0000" "#ff8c00" "#ffff00" "#b2ff00" "#00ff00" "#00ffa0" | ||
| 361 | "#00ffff" "#008cff" "#0000ff" "#a500ff" "#ff00ff" "#ff0098" | ||
| 362 | "#ff5959" "#ffb459" "#ffff71" "#cfff60" "#6fff6f" "#65ffc9" | ||
| 363 | "#6dffff" "#59b4ff" "#5959ff" "#c459ff" "#ff66ff" "#ff59bc" | ||
| 364 | "#ff9c9c" "#ffd39c" "#ffff9c" "#e2ff9c" "#9cff9c" "#9cffdb" | ||
| 365 | "#9cffff" "#9cd3ff" "#9c9cff" "#dc9cff" "#ff9cff" "#ff94d3" | ||
| 366 | "#000000" "#131313" "#282828" "#363636" "#4d4d4d" "#656565" | ||
| 367 | "#818181" "#9f9f9f" "#bcbcbc" "#e2e2e2" "#ffffff"]) | ||
| 368 | |||
| 348 | (defun erc-get-bg-color-face (n) | 369 | (defun erc-get-bg-color-face (n) |
| 349 | "Fetches the right face for background color N (0-15)." | 370 | "Fetches the right face for background color N (0-15)." |
| 350 | (if (stringp n) (setq n (string-to-number n))) | 371 | (if (stringp n) (setq n (string-to-number n))) |
| 351 | (if (not (numberp n)) | 372 | (if (not (numberp n)) |
| 352 | (prog1 'default | 373 | (prog1 'default |
| 353 | (erc-error "erc-get-bg-color-face: n is NaN: %S" n)) | 374 | (erc-error "erc-get-bg-color-face: n is NaN: %S" n)) |
| 354 | (when (> n 16) | 375 | (when (> n 99) |
| 355 | (erc-log (format " Wrong color: %s" n)) | 376 | (erc-log (format " Wrong color: %s" n)) |
| 356 | (setq n (mod n 16))) | 377 | (setq n (mod n 16))) |
| 357 | (cond | 378 | (cond |
| 358 | ((and (>= n 0) (< n 16)) | 379 | ((and (>= n 0) (< n 16)) |
| 359 | (intern (concat "bg:erc-color-face" (number-to-string n)))) | 380 | (intern (concat "bg:erc-color-face" (number-to-string n)))) |
| 360 | (t (erc-log (format " Wrong color: %s" n)) 'default)))) | 381 | ((< 15 n 99) |
| 382 | (list :background (aref erc--controls-additional-colors (- n 16)))) | ||
| 383 | (t (erc-log (format " Wrong color: %s" n)) '(default))))) | ||
| 361 | 384 | ||
| 362 | (defun erc-get-fg-color-face (n) | 385 | (defun erc-get-fg-color-face (n) |
| 363 | "Fetches the right face for foreground color N (0-15)." | 386 | "Fetches the right face for foreground color N (0-15)." |
| @@ -365,13 +388,15 @@ The value `erc-interpret-controls-p' must also be t for this to work." | |||
| 365 | (if (not (numberp n)) | 388 | (if (not (numberp n)) |
| 366 | (prog1 'default | 389 | (prog1 'default |
| 367 | (erc-error "erc-get-fg-color-face: n is NaN: %S" n)) | 390 | (erc-error "erc-get-fg-color-face: n is NaN: %S" n)) |
| 368 | (when (> n 16) | 391 | (when (> n 99) |
| 369 | (erc-log (format " Wrong color: %s" n)) | 392 | (erc-log (format " Wrong color: %s" n)) |
| 370 | (setq n (mod n 16))) | 393 | (setq n (mod n 16))) |
| 371 | (cond | 394 | (cond |
| 372 | ((and (>= n 0) (< n 16)) | 395 | ((and (>= n 0) (< n 16)) |
| 373 | (intern (concat "fg:erc-color-face" (number-to-string n)))) | 396 | (intern (concat "fg:erc-color-face" (number-to-string n)))) |
| 374 | (t (erc-log (format " Wrong color: %s" n)) 'default)))) | 397 | ((< 15 n 99) |
| 398 | (list :foreground (aref erc--controls-additional-colors (- n 16)))) | ||
| 399 | (t (erc-log (format " Wrong color: %s" n)) '(default))))) | ||
| 375 | 400 | ||
| 376 | ;;;###autoload(autoload 'erc-irccontrols-mode "erc-goodies" nil t) | 401 | ;;;###autoload(autoload 'erc-irccontrols-mode "erc-goodies" nil t) |
| 377 | (define-erc-module irccontrols nil | 402 | (define-erc-module irccontrols nil |
| @@ -383,6 +408,25 @@ The value `erc-interpret-controls-p' must also be t for this to work." | |||
| 383 | (remove-hook 'erc-send-modify-hook #'erc-controls-highlight) | 408 | (remove-hook 'erc-send-modify-hook #'erc-controls-highlight) |
| 384 | (erc--modify-local-map nil "C-c C-c" #'erc-toggle-interpret-controls))) | 409 | (erc--modify-local-map nil "C-c C-c" #'erc-toggle-interpret-controls))) |
| 385 | 410 | ||
| 411 | ;; These patterns were moved here to circumvent compiler warnings but | ||
| 412 | ;; otherwise translated verbatim from their original string-literal | ||
| 413 | ;; definitions (minus a small bug fix to satisfy newly added tests). | ||
| 414 | (defvar erc-controls-remove-regexp | ||
| 415 | (rx (or ?\C-b ?\C-\] ?\C-_ ?\C-v ?\C-g ?\C-o | ||
| 416 | (: ?\C-c (? (any "0-9")) (? (any "0-9")) | ||
| 417 | (? (group ?, (any "0-9") (? (any "0-9"))))))) | ||
| 418 | "Regular expression matching control characters to remove.") | ||
| 419 | |||
| 420 | ;; Before the change to `rx', group 3 used to be a sibling of group 2. | ||
| 421 | ;; This was assumed to be a bug. A few minor simplifications were | ||
| 422 | ;; also performed. If incorrect, please admonish. | ||
| 423 | (defvar erc-controls-highlight-regexp | ||
| 424 | (rx (group (or ?\C-b ?\C-\] ?\C-v ?\C-_ ?\C-g ?\C-o | ||
| 425 | (: ?\C-c (? (group (** 1 2 (any "0-9"))) | ||
| 426 | (? (group ?, (group (** 1 2 (any "0-9"))))))))) | ||
| 427 | (group (* (not (any ?\C-b ?\C-c ?\C-g ?\n ?\C-o ?\C-v ?\C-\] ?\C-_))))) | ||
| 428 | "Regular expression matching control chars to highlight.") | ||
| 429 | |||
| 386 | (defun erc-controls-interpret (str) | 430 | (defun erc-controls-interpret (str) |
| 387 | "Return a copy of STR after dealing with IRC control characters. | 431 | "Return a copy of STR after dealing with IRC control characters. |
| 388 | See `erc-interpret-controls-p' and `erc-interpret-mirc-color' for options." | 432 | See `erc-interpret-controls-p' and `erc-interpret-mirc-color' for options." |
| @@ -444,16 +488,6 @@ See `erc-interpret-controls-p' and `erc-interpret-mirc-color' for options." | |||
| 444 | (setq s (replace-match "" nil nil s))) | 488 | (setq s (replace-match "" nil nil s))) |
| 445 | s))) | 489 | s))) |
| 446 | 490 | ||
| 447 | (defvar erc-controls-remove-regexp | ||
| 448 | "\C-b\\|\C-]\\|\C-_\\|\C-v\\|\C-g\\|\C-o\\|\C-c[0-9]?[0-9]?\\(,[0-9][0-9]?\\)?" | ||
| 449 | "Regular expression which matches control characters to remove.") | ||
| 450 | |||
| 451 | (defvar erc-controls-highlight-regexp | ||
| 452 | (concat "\\(\C-b\\|\C-]\\|\C-v\\|\C-_\\|\C-g\\|\C-o\\|" | ||
| 453 | "\C-c\\([0-9][0-9]?\\)?\\(,\\([0-9][0-9]?\\)\\)?\\)" | ||
| 454 | "\\([^\C-b\C-]\C-v\C-_\C-c\C-g\C-o\n]*\\)") | ||
| 455 | "Regular expression which matches control chars and the text to highlight.") | ||
| 456 | |||
| 457 | (defun erc-controls-highlight () | 491 | (defun erc-controls-highlight () |
| 458 | "Highlight IRC control chars in the buffer. | 492 | "Highlight IRC control chars in the buffer. |
| 459 | This is useful for `erc-insert-modify-hook' and `erc-send-modify-hook'. | 493 | This is useful for `erc-insert-modify-hook' and `erc-send-modify-hook'. |
| @@ -510,6 +544,13 @@ Also see `erc-interpret-controls-p' and `erc-interpret-mirc-color'." | |||
| 510 | "Prepend properties from IRC control characters between FROM and TO. | 544 | "Prepend properties from IRC control characters between FROM and TO. |
| 511 | If optional argument STR is provided, apply to STR, otherwise prepend properties | 545 | If optional argument STR is provided, apply to STR, otherwise prepend properties |
| 512 | to a region in the current buffer." | 546 | to a region in the current buffer." |
| 547 | (if (and fg bg (equal fg bg)) | ||
| 548 | (progn | ||
| 549 | (setq fg 'erc-spoiler-face | ||
| 550 | bg nil) | ||
| 551 | (put-text-property from to 'mouse-face 'erc-inverse-face str)) | ||
| 552 | (when fg (setq fg (erc-get-fg-color-face fg))) | ||
| 553 | (when bg (setq bg (erc-get-bg-color-face bg)))) | ||
| 513 | (font-lock-prepend-text-property | 554 | (font-lock-prepend-text-property |
| 514 | from | 555 | from |
| 515 | to | 556 | to |
| @@ -527,10 +568,10 @@ to a region in the current buffer." | |||
| 527 | '(erc-underline-face) | 568 | '(erc-underline-face) |
| 528 | nil) | 569 | nil) |
| 529 | (if fg | 570 | (if fg |
| 530 | (list (erc-get-fg-color-face fg)) | 571 | (list fg) |
| 531 | nil) | 572 | nil) |
| 532 | (if bg | 573 | (if bg |
| 533 | (list (erc-get-bg-color-face bg)) | 574 | (list bg) |
| 534 | nil)) | 575 | nil)) |
| 535 | str) | 576 | str) |
| 536 | str) | 577 | str) |
diff --git a/test/lisp/erc/erc-goodies-tests.el b/test/lisp/erc/erc-goodies-tests.el new file mode 100644 index 00000000000..46fcf82401b --- /dev/null +++ b/test/lisp/erc/erc-goodies-tests.el | |||
| @@ -0,0 +1,253 @@ | |||
| 1 | ;;; erc-goodies-tests.el --- Tests for erc-goodies -*- lexical-binding:t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2023 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | ;; | ||
| 7 | ;; GNU Emacs is free software: you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published | ||
| 9 | ;; by the Free Software Foundation, either version 3 of the License, | ||
| 10 | ;; or (at your option) any later version. | ||
| 11 | ;; | ||
| 12 | ;; GNU Emacs is distributed in the hope that it will be useful, but | ||
| 13 | ;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | ;; General Public License for more details. | ||
| 16 | ;; | ||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Commentary: | ||
| 21 | ;;; Code: | ||
| 22 | (require 'ert-x) | ||
| 23 | (require 'erc-goodies) | ||
| 24 | (declare-function erc--initialize-markers "erc" (old-point continued) t) | ||
| 25 | |||
| 26 | (defun erc-goodies-tests--assert-face (beg end-str present &optional absent) | ||
| 27 | (setq beg (+ beg (point-min))) | ||
| 28 | (let ((end (+ beg (1- (length end-str))))) | ||
| 29 | (while (and beg (< beg end)) | ||
| 30 | (let* ((val (get-text-property beg 'font-lock-face)) | ||
| 31 | (ft (flatten-tree (ensure-list val)))) | ||
| 32 | (dolist (p (ensure-list present)) | ||
| 33 | (if (consp p) | ||
| 34 | (should (member p val)) | ||
| 35 | (should (memq p ft)))) | ||
| 36 | (dolist (a (ensure-list absent)) | ||
| 37 | (if (consp a) | ||
| 38 | (should-not (member a val)) | ||
| 39 | (should-not (memq a ft)))) | ||
| 40 | (setq beg (text-property-not-all beg (point-max) | ||
| 41 | 'font-lock-face val)))))) | ||
| 42 | |||
| 43 | ;; These are from the "Examples" section of | ||
| 44 | ;; https://modern.ircdocs.horse/formatting.html | ||
| 45 | |||
| 46 | (ert-deftest erc-controls-highlight--examples () | ||
| 47 | ;; FIXME remove after adding | ||
| 48 | (unless (fboundp 'erc--initialize-markers) | ||
| 49 | (ert-skip "Missing required function")) | ||
| 50 | (should (eq t erc-interpret-controls-p)) | ||
| 51 | (let ((erc-insert-modify-hook '(erc-controls-highlight)) | ||
| 52 | erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook) | ||
| 53 | (with-current-buffer (get-buffer-create "#chan") | ||
| 54 | (erc-mode) | ||
| 55 | (setq-local erc-interpret-mirc-color t) | ||
| 56 | (erc--initialize-markers (point) nil) | ||
| 57 | |||
| 58 | (let* ((m "I love \C-c3IRC!\C-c It is the \C-c7best protocol ever!") | ||
| 59 | (msg (erc-format-privmessage "bob" m nil t))) | ||
| 60 | (erc-display-message nil nil (current-buffer) msg)) | ||
| 61 | (forward-line -1) | ||
| 62 | (should (search-forward "<bob> " nil t)) | ||
| 63 | (save-restriction | ||
| 64 | (narrow-to-region (point) (pos-eol)) | ||
| 65 | (erc-goodies-tests--assert-face | ||
| 66 | 0 "I love" 'erc-default-face 'fg:erc-color-face3) | ||
| 67 | (erc-goodies-tests--assert-face | ||
| 68 | 7 " IRC!" 'fg:erc-color-face3) | ||
| 69 | (erc-goodies-tests--assert-face | ||
| 70 | 11 " It is the " 'erc-default-face 'fg:erc-color-face7) | ||
| 71 | (erc-goodies-tests--assert-face | ||
| 72 | 22 "best protocol ever!" 'fg:erc-color-face7)) | ||
| 73 | |||
| 74 | (let* ((m "This is a \C-]\C-c13,9cool \C-cmessage") | ||
| 75 | (msg (erc-format-privmessage "alice" m nil t))) | ||
| 76 | (erc-display-message nil nil (current-buffer) msg)) | ||
| 77 | (should (search-forward "<alice> " nil t)) | ||
| 78 | (save-restriction | ||
| 79 | (narrow-to-region (point) (pos-eol)) | ||
| 80 | (erc-goodies-tests--assert-face | ||
| 81 | 0 "this is a " 'erc-default-face 'erc-italic-face) | ||
| 82 | (erc-goodies-tests--assert-face | ||
| 83 | 10 "cool " '(erc-italic-face fg:erc-color-face13 bg:erc-color-face9)) | ||
| 84 | (erc-goodies-tests--assert-face | ||
| 85 | 15 "message" 'erc-italic-face | ||
| 86 | '(fg:erc-color-face13 bg:erc-color-face9))) | ||
| 87 | |||
| 88 | (let* ((m "IRC \C-bis \C-c4,12so \C-cgreat\C-o!") | ||
| 89 | (msg (erc-format-privmessage "bob" m nil t))) | ||
| 90 | (erc-display-message nil nil (current-buffer) msg)) | ||
| 91 | (should (search-forward "<bob> " nil t)) | ||
| 92 | (save-restriction | ||
| 93 | (narrow-to-region (point) (pos-eol)) | ||
| 94 | (erc-goodies-tests--assert-face | ||
| 95 | 0 "IRC " 'erc-default-face 'erc-bold-face) | ||
| 96 | (erc-goodies-tests--assert-face | ||
| 97 | 4 "is " 'erc-bold-face '(fg:erc-color-face4 bg:erc-color-face12)) | ||
| 98 | (erc-goodies-tests--assert-face | ||
| 99 | 7 "so " '(erc-bold-face fg:erc-color-face4 bg:erc-color-face12)) | ||
| 100 | (erc-goodies-tests--assert-face | ||
| 101 | 10 "great" 'erc-bold-face '(fg:erc-color-face4 bg:erc-color-face12)) | ||
| 102 | (erc-goodies-tests--assert-face | ||
| 103 | 15 "!" 'erc-default-face 'erc-bold-face)) | ||
| 104 | |||
| 105 | (let* ((m (concat "Rules: Don't spam 5\C-c13,8,6\C-c,7,8, " | ||
| 106 | "and especially not \C-b9\C-b\C-]!")) | ||
| 107 | (msg (erc-format-privmessage "alice" m nil t))) | ||
| 108 | (erc-display-message nil nil (current-buffer) msg)) | ||
| 109 | (should (search-forward "<alice> " nil t)) | ||
| 110 | (save-restriction | ||
| 111 | (narrow-to-region (point) (pos-eol)) | ||
| 112 | (erc-goodies-tests--assert-face | ||
| 113 | 0 "Rules: Don't spam 5" 'erc-default-face | ||
| 114 | '(fg:erc-color-face13 bg:erc-color-face8)) | ||
| 115 | (erc-goodies-tests--assert-face | ||
| 116 | 19 ",6" '(fg:erc-color-face13 bg:erc-color-face8)) | ||
| 117 | (erc-goodies-tests--assert-face | ||
| 118 | 21 ",7,8, and especially not " 'erc-default-face | ||
| 119 | '(fg:erc-color-face13 bg:erc-color-face8 erc-bold-face)) | ||
| 120 | (erc-goodies-tests--assert-face | ||
| 121 | 44 "9" 'erc-bold-face 'erc-italic-face) | ||
| 122 | (erc-goodies-tests--assert-face | ||
| 123 | 45 "!" 'erc-italic-face 'erc-bold-face)) | ||
| 124 | |||
| 125 | (when noninteractive | ||
| 126 | (kill-buffer))))) | ||
| 127 | |||
| 128 | ;; Like the test above, this is most intuitive when run interactively. | ||
| 129 | ;; Hovering over the redacted area should reveal its underlying text | ||
| 130 | ;; in a high-contrast face. | ||
| 131 | |||
| 132 | (ert-deftest erc-controls-highlight--inverse () | ||
| 133 | ;; FIXME remove after adding | ||
| 134 | (unless (fboundp 'erc--initialize-markers) | ||
| 135 | (ert-skip "Missing required function")) | ||
| 136 | (should (eq t erc-interpret-controls-p)) | ||
| 137 | (let ((erc-insert-modify-hook '(erc-controls-highlight)) | ||
| 138 | erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook) | ||
| 139 | (with-current-buffer (get-buffer-create "#chan") | ||
| 140 | (erc-mode) | ||
| 141 | (setq-local erc-interpret-mirc-color t) | ||
| 142 | (erc--initialize-markers (point) nil) | ||
| 143 | |||
| 144 | (let* ((m "Spoiler: \C-c0,0Hello\C-c1,1World!") | ||
| 145 | (msg (erc-format-privmessage "bob" m nil t))) | ||
| 146 | (erc-display-message nil nil (current-buffer) msg)) | ||
| 147 | (forward-line -1) | ||
| 148 | (should (search-forward "<bob> " nil t)) | ||
| 149 | (save-restriction | ||
| 150 | (narrow-to-region (point) (pos-eol)) | ||
| 151 | (should (eq (get-text-property (+ 9 (point)) 'mouse-face) | ||
| 152 | 'erc-inverse-face)) | ||
| 153 | (should (eq (get-text-property (1- (pos-eol)) 'mouse-face) | ||
| 154 | 'erc-inverse-face)) | ||
| 155 | (erc-goodies-tests--assert-face | ||
| 156 | 0 "Spoiler: " 'erc-default-face | ||
| 157 | '(fg:erc-color-face0 bg:erc-color-face0)) | ||
| 158 | (erc-goodies-tests--assert-face | ||
| 159 | 9 "Hello" '(erc-spoiler-face) | ||
| 160 | '( fg:erc-color-face0 bg:erc-color-face0 | ||
| 161 | fg:erc-color-face1 bg:erc-color-face1)) | ||
| 162 | (erc-goodies-tests--assert-face | ||
| 163 | 18 " World" '(erc-spoiler-face) | ||
| 164 | '( fg:erc-color-face0 bg:erc-color-face0 | ||
| 165 | fg:erc-color-face1 bg:erc-color-face1 ))) | ||
| 166 | (when noninteractive | ||
| 167 | (kill-buffer))))) | ||
| 168 | |||
| 169 | (defvar erc-goodies-tests--motd | ||
| 170 | ;; This is from ergo's MOTD | ||
| 171 | '((":- - this is \2bold text\17.") | ||
| 172 | (":- - this is \35italics text\17.") | ||
| 173 | (":- - this is \0034red\3 and \0032blue\3 text.") | ||
| 174 | (":- - this is \0034,12red text with a light blue background\3.") | ||
| 175 | (":- - this is a normal escaped dollarsign: $") | ||
| 176 | (":- ") | ||
| 177 | (":- " | ||
| 178 | "\0031,0 00 \0030,1 01 \0030,2 02 \0030,3 03 " | ||
| 179 | "\0031,4 04 \0030,5 05 \0030,6 06 \0031,7 07 ") | ||
| 180 | (":- " | ||
| 181 | "\0031,8 08 \0031,9 09 \0030,10 10 \0031,11 11 " | ||
| 182 | "\0030,12 12 \0031,13 13 \0031,14 14 \0031,15 15 ") | ||
| 183 | (":- ") | ||
| 184 | (":- " | ||
| 185 | "\0030,16 16 \0030,17 17 \0030,18 18 \0030,19 19 " | ||
| 186 | "\0030,20 20 \0030,21 21 \0030,22 22 \0030,23 23 " | ||
| 187 | "\0030,24 24 \0030,25 25 \0030,26 26 \0030,27 27 ") | ||
| 188 | (":- " | ||
| 189 | "\0030,28 28 \0030,29 29 \0030,30 30 \0030,31 31 " | ||
| 190 | "\0030,32 32 \0030,33 33 \0030,34 34 \0030,35 35 " | ||
| 191 | "\0030,36 36 \0030,37 37 \0030,38 38 \0030,39 39 ") | ||
| 192 | (":- " | ||
| 193 | "\0030,40 40 \0030,41 41 \0030,42 42 \0030,43 43 " | ||
| 194 | "\0030,44 44 \0030,45 45 \0030,46 46 \0030,47 47 " | ||
| 195 | "\0030,48 48 \0030,49 49 \0030,50 50 \0030,51 51 ") | ||
| 196 | (":- " | ||
| 197 | "\0030,52 52 \0030,53 53 \0031,54 54 \0031,55 55 " | ||
| 198 | "\0031,56 56 \0031,57 57 \0031,58 58 \0030,59 59 " | ||
| 199 | "\0030,60 60 \0030,61 61 \0030,62 62 \0030,63 63 ") | ||
| 200 | (":- " | ||
| 201 | "\0030,64 64 \0031,65 65 \0031,66 66 \0031,67 67 " | ||
| 202 | "\0031,68 68 \0031,69 69 \0031,70 70 \0031,71 71 " | ||
| 203 | "\0030,72 72 \0030,73 73 \0030,74 74 \0030,75 75 ") | ||
| 204 | (":- " | ||
| 205 | "\0031,76 76 \0031,77 77 \0031,78 78 \0031,79 79 " | ||
| 206 | "\0031,80 80 \0031,81 81 \0031,82 82 \0031,83 83 " | ||
| 207 | "\0031,84 84 \0031,85 85 \0031,86 86 \0031,87 87 ") | ||
| 208 | (":- " | ||
| 209 | "\0030,88 88 \0030,89 89 \0030,90 90 \0030,91 91 " | ||
| 210 | "\0030,92 92 \0030,93 93 \0030,94 94 \0030,95 95 " | ||
| 211 | "\0031,96 96 \0031,97 97 \0031,98 98 \399,99 99 ") | ||
| 212 | (":- "))) | ||
| 213 | |||
| 214 | (ert-deftest erc-controls-highlight--motd () | ||
| 215 | ;; FIXME remove after adding | ||
| 216 | (unless (fboundp 'erc--initialize-markers) | ||
| 217 | (ert-skip "Missing required function")) | ||
| 218 | (should (eq t erc-interpret-controls-p)) | ||
| 219 | (let ((erc-insert-modify-hook '(erc-controls-highlight)) | ||
| 220 | erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook) | ||
| 221 | (with-current-buffer (get-buffer-create "#chan") | ||
| 222 | (erc-mode) | ||
| 223 | (setq-local erc-interpret-mirc-color t) | ||
| 224 | (erc--initialize-markers (point) nil) | ||
| 225 | |||
| 226 | (dolist (parts erc-goodies-tests--motd) | ||
| 227 | (erc-display-message nil 'notice (current-buffer) (string-join parts))) | ||
| 228 | |||
| 229 | ;; Spot check | ||
| 230 | (goto-char (point-min)) | ||
| 231 | (should (search-forward " 16 " nil t)) | ||
| 232 | (save-restriction | ||
| 233 | (narrow-to-region (point) (pos-eol)) | ||
| 234 | (erc-goodies-tests--assert-face | ||
| 235 | 0 " 17 " '(fg:erc-color-face0 (:background "#472100"))) | ||
| 236 | (erc-goodies-tests--assert-face | ||
| 237 | 4 " 18 " '(fg:erc-color-face0 (:background "#474700")) | ||
| 238 | '((:background "#472100")))) | ||
| 239 | |||
| 240 | (should (search-forward " 71 " nil t)) | ||
| 241 | (save-restriction | ||
| 242 | (narrow-to-region (point) (pos-eol)) | ||
| 243 | (erc-goodies-tests--assert-face | ||
| 244 | 0 " 72 " '(fg:erc-color-face0 (:background "#5959ff"))) | ||
| 245 | (erc-goodies-tests--assert-face | ||
| 246 | 4 " 73 " '(fg:erc-color-face0 (:background "#c459ff")) | ||
| 247 | '((:background "#5959ff")))) | ||
| 248 | |||
| 249 | (goto-char (point-min)) | ||
| 250 | (when noninteractive | ||
| 251 | (kill-buffer))))) | ||
| 252 | |||
| 253 | ;;; erc-goodies-tests.el ends here | ||