emacs/test/lisp/erc/erc-stamp-tests.el

471 lines
20 KiB
EmacsLisp
Raw Normal View History

;;; erc-stamp-tests.el --- Tests for erc-stamp. -*- lexical-binding:t -*-
2024-01-02 10:30:05 +08:00
;; Copyright (C) 2023-2024 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation, either version 3 of the License,
;; or (at your option) any later version.
;;
;; GNU Emacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Code:
(require 'erc-stamp)
(require 'erc-goodies) ; for `erc-make-read-only'
(require 'ert-x)
Move ERC test utilities to common file * lisp/erc/erc-common.el (erc--define-catalog): Update name of reference to convenience command now located in `erc-tests-common'. * test/lisp/erc/erc-button-tests.el: Require common test-util library `erc-tests-common', located under test/lisp/erc/resources. ; (erc-button-alist--url, ; erc-button-tests--erc-button-alist--function-as-form, ; erc-button-tests--erc-button-alist--nil-form, ; erc-button--display-error-notice-with-keys): Use common helper ; `erc-tests-common-init-server-proc' from test-utils library. * test/lisp/erc/erc-fill-tests.el: Require `erc-tests-common'. (erc-fill-tests--wrap-populate): Use helper `erc-tests-common-init-server-proc'. (erc-fill-tests--save-p): Remove. See replacement `erc-tests-common-snapshot-save-p' in erc-tests-common. (erc-fill-tests--graphic-dir): Add trailing slash. (erc-fill-tests--compare): Move body to generalized utility `erc-tests-common-snapshot-compare' in erc-tests-common. * test/lisp/erc/erc-goodies-tests.el: Require `erc-tests-common'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move here from erc-tests.el. * test/lisp/erc/erc-networks-tests.el: Load `erc-tests-common'. (erc-networks-tests--create-live-proc): Defer to `erc-tests-common-init-server-proc' and drop optional buffer param. (erc-networks-tests--clean-bufs): Defer to `erc-tests-common-kill-buffers'. (erc-networks--rename-server-buffer--existing--live): Call `erc-networks-tests--create-live-proc' in server buffer. * test/lisp/erc/erc-scenarios-internal.el: Load `erc-tests-common'. (erc-scenarios-internal--run-graphical-all): Use `erc-tests-common-create-subprocess' to create process. * test/lisp/erc/erc-scenarios-sasl.el (erc-scenarios-sasl--plain-fail): Silence error message. * test/lisp/erc/erc-stamp-tests.el: Require `erc-tests-common'. (erc-stamp-tests--insert-right, erc-timestamp-intangible--left): Use `erc-tests-common-init-server-proc'. (erc-tests--assert-get-inserted-msg/stamp, erc-stamp-tests--assert-get-inserted-msg/stamp): Move from erc-tests.el, renaming to latter. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move here from erc-tests.el. * test/lisp/erc/erc-tests.el: Require `erc-tests-common'. (erc-with-server-buffer): Use renamed test-helper utility `erc-tests-common-init-server-proc'. (erc-tests--send-prep, erc-tests--set-fake-server-process): Move to `erc-tests-common' library and rename to `erc-tests-common-prep-for-insertion' and `erc-tests-common-init-server-proc', respectively. ; (erc-hide-prompt, erc--refresh-prompt, ; erc-setup-buffer--custom-action, erc--parsed-prefix, ; erc--update-channel-modes, erc--channel-modes, ; erc--channel-modes/graphic-p, erc-ring-previous-command): Use ; `erc-tests-common-prep-for-insertion' instead of ; `erc-tests--send-prep', and use `erc-tests-common-init-server-proc' ; instead of `erc-tests--set-fake-server-process'. (erc-tests--with-process-input-spy): Move to `erc-tests-common' and rename `erc-tests-common-with-process-input-spy'. ; (erc--check-prompt-input-functions, erc-send-current-line, ; erc--check-prompt-input-for-multiline-blanks, ; erc-send-whitespace-lines): Use renamed ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. ; (erc-process-input-line): Use renamed ; `erc-tests-common-init-server-proc'. (erc-tests--get-inserted-msg-setup, erc-tests--assert-get-inserted-msg, erc-tests--assert-get-inserted-msg/basic, erc-tests--assert-get-inserted-msg-readonly-with): Move to `erc-tests-common' and rename with "common" prefix, using single instead of double hyphen. (erc-tests--assert-get-inserted-msg/stamp): Move to `erc-stamp-tests' and rename with "stamp" prefix. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move to `erc-stamp-tests'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move to `erc-goodies-tests'. ; (erc--get-inserted-msg-beg/basic, ; erc--get-inserted-msg-end/basic, ; erc--get-inserted-msg-bounds/basic): Use common helpers. ; (erc--route-insertion): Use renamed helper functions ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. (erc-tests--make-server-buf): Move to `erc-common-tests' and rename with "common" prefix. (erc-tests--make-client-buf): Remove unused function without supplying replacement. ; (erc-handle-irc-url): Use renamed `erc-tests-common-make-server-buf' ; utility function. ; (erc-tests--assert-printed-in-subprocess): Use helper from common lib ; `erc-tests-common-create-subprocess code' to do the heavy lifting. (erc-tests--string-to-propertized-parts, erc-tests-pp-propertized-parts): Move to `erc-tests-common' and rename with "common" prefix. * test/lisp/erc/resources/erc-tests-common.el: New file containing helper utilities and fixtures used by multiple files in test/lisp/erc.
2023-12-24 12:21:49 -08:00
(eval-and-compile
(let ((load-path (cons (ert-resource-directory) load-path)))
(require 'erc-tests-common)))
;; These display-oriented tests are brittle because many factors
;; influence how text properties are applied. We should just
;; rework these into full scenarios.
(defun erc-stamp-tests--insert-right (test)
(let ((val (list 0 0))
(erc-insert-modify-hook '(erc-add-timestamp))
(erc-insert-post-hook '(erc-make-read-only)) ; see comment above
(erc-timestamp-only-if-changed-flag nil)
;;
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
(advice-add 'erc-format-timestamp :filter-args
(lambda (args) (cons (cl-incf (cadr val) 60) (cdr args)))
'((name . ert-deftest--erc-timestamp-use-align-to)))
(with-current-buffer (get-buffer-create "*erc-stamp-tests--insert-right*")
(erc-mode)
(erc-stamp--manage-local-options-state)
Don't insert prompt input before markers in ERC * etc/ERC-NEWS: Update entry in 5.6 section announcing a persistent prompt. * lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Use helper `erc--initialize-markers' to set up prompt. * lisp/erc/erc.el (erc--initialize-markers): Change `erc-insert-marker' type to t. Do this to spare modules that want to remember the current message location from resorting to workarounds, like leaving a marker one char before the end of a message, which is not foolproof. (erc--refresh-prompt): Temporarily change type of `erc-insert-marker' when inserting prompt. (erc-display-line-1): Insert incoming message normally instead of forcing before markers, thus respecting markers left by third parties. Strictly speaking, this is a breaking change. (erc-display-msg): Insert normally instead of calling `insert-before-markers', which was a regression introduced by 05f6fdb9 "Preserve ERC prompt and its bounding markers". * test/lisp/erc/erc-dcc-tests.el (erc-dcc-tests--dcc-handle-ctcp-send, erc-dcc-tests--erc-dcc-do-GET-command): Use helper to initialize prompt and markers. * test/lisp/erc/erc-networks-tests.el (erc-networks--ensure-announced, erc-networks--rename-server-buffer--existing--reuse, erc-networks--rename-server-buffer--existing--noreuse, erc-networks--rename-server-buffer--reconnecting, erc-networks--rename-server-buffer--id, erc-networks--rename-server-buffer--existing--live, erc-networks--rename-server-buffer--local-match, erc-networks--rename-server-buffer--local-nomatch): Use helper to initialize prompt and bounding markers. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--insert-right): Use `erc--initialize-markers' for setting up prompt. * test/lisp/erc/erc-tests.el (erc--refresh-prompt): Adjust assertions for expected prompt content. (Bug#60936)
2023-06-10 00:17:44 -07:00
(erc--initialize-markers (point) nil)
Move ERC test utilities to common file * lisp/erc/erc-common.el (erc--define-catalog): Update name of reference to convenience command now located in `erc-tests-common'. * test/lisp/erc/erc-button-tests.el: Require common test-util library `erc-tests-common', located under test/lisp/erc/resources. ; (erc-button-alist--url, ; erc-button-tests--erc-button-alist--function-as-form, ; erc-button-tests--erc-button-alist--nil-form, ; erc-button--display-error-notice-with-keys): Use common helper ; `erc-tests-common-init-server-proc' from test-utils library. * test/lisp/erc/erc-fill-tests.el: Require `erc-tests-common'. (erc-fill-tests--wrap-populate): Use helper `erc-tests-common-init-server-proc'. (erc-fill-tests--save-p): Remove. See replacement `erc-tests-common-snapshot-save-p' in erc-tests-common. (erc-fill-tests--graphic-dir): Add trailing slash. (erc-fill-tests--compare): Move body to generalized utility `erc-tests-common-snapshot-compare' in erc-tests-common. * test/lisp/erc/erc-goodies-tests.el: Require `erc-tests-common'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move here from erc-tests.el. * test/lisp/erc/erc-networks-tests.el: Load `erc-tests-common'. (erc-networks-tests--create-live-proc): Defer to `erc-tests-common-init-server-proc' and drop optional buffer param. (erc-networks-tests--clean-bufs): Defer to `erc-tests-common-kill-buffers'. (erc-networks--rename-server-buffer--existing--live): Call `erc-networks-tests--create-live-proc' in server buffer. * test/lisp/erc/erc-scenarios-internal.el: Load `erc-tests-common'. (erc-scenarios-internal--run-graphical-all): Use `erc-tests-common-create-subprocess' to create process. * test/lisp/erc/erc-scenarios-sasl.el (erc-scenarios-sasl--plain-fail): Silence error message. * test/lisp/erc/erc-stamp-tests.el: Require `erc-tests-common'. (erc-stamp-tests--insert-right, erc-timestamp-intangible--left): Use `erc-tests-common-init-server-proc'. (erc-tests--assert-get-inserted-msg/stamp, erc-stamp-tests--assert-get-inserted-msg/stamp): Move from erc-tests.el, renaming to latter. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move here from erc-tests.el. * test/lisp/erc/erc-tests.el: Require `erc-tests-common'. (erc-with-server-buffer): Use renamed test-helper utility `erc-tests-common-init-server-proc'. (erc-tests--send-prep, erc-tests--set-fake-server-process): Move to `erc-tests-common' library and rename to `erc-tests-common-prep-for-insertion' and `erc-tests-common-init-server-proc', respectively. ; (erc-hide-prompt, erc--refresh-prompt, ; erc-setup-buffer--custom-action, erc--parsed-prefix, ; erc--update-channel-modes, erc--channel-modes, ; erc--channel-modes/graphic-p, erc-ring-previous-command): Use ; `erc-tests-common-prep-for-insertion' instead of ; `erc-tests--send-prep', and use `erc-tests-common-init-server-proc' ; instead of `erc-tests--set-fake-server-process'. (erc-tests--with-process-input-spy): Move to `erc-tests-common' and rename `erc-tests-common-with-process-input-spy'. ; (erc--check-prompt-input-functions, erc-send-current-line, ; erc--check-prompt-input-for-multiline-blanks, ; erc-send-whitespace-lines): Use renamed ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. ; (erc-process-input-line): Use renamed ; `erc-tests-common-init-server-proc'. (erc-tests--get-inserted-msg-setup, erc-tests--assert-get-inserted-msg, erc-tests--assert-get-inserted-msg/basic, erc-tests--assert-get-inserted-msg-readonly-with): Move to `erc-tests-common' and rename with "common" prefix, using single instead of double hyphen. (erc-tests--assert-get-inserted-msg/stamp): Move to `erc-stamp-tests' and rename with "stamp" prefix. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move to `erc-stamp-tests'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move to `erc-goodies-tests'. ; (erc--get-inserted-msg-beg/basic, ; erc--get-inserted-msg-end/basic, ; erc--get-inserted-msg-bounds/basic): Use common helpers. ; (erc--route-insertion): Use renamed helper functions ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. (erc-tests--make-server-buf): Move to `erc-common-tests' and rename with "common" prefix. (erc-tests--make-client-buf): Remove unused function without supplying replacement. ; (erc-handle-irc-url): Use renamed `erc-tests-common-make-server-buf' ; utility function. ; (erc-tests--assert-printed-in-subprocess): Use helper from common lib ; `erc-tests-common-create-subprocess code' to do the heavy lifting. (erc-tests--string-to-propertized-parts, erc-tests-pp-propertized-parts): Move to `erc-tests-common' and rename with "common" prefix. * test/lisp/erc/resources/erc-tests-common.el: New file containing helper utilities and fixtures used by multiple files in test/lisp/erc.
2023-12-24 12:21:49 -08:00
(erc-tests-common-init-server-proc "sleep" "1")
(funcall test)
(when noninteractive
(kill-buffer)))
(advice-remove 'erc-format-timestamp
'ert-deftest--erc-timestamp-use-align-to)))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
(defun erc-stamp-tests--use-align-to--nil (compat)
(erc-stamp-tests--insert-right
(lambda ()
(ert-info ("nil, normal")
(let ((erc-timestamp-use-align-to nil))
(erc-display-message nil 'notice (current-buffer) "begin"))
(goto-char (point-min))
(should (search-forward-regexp
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(rx "begin" (+ "\t") (* " ") "[") nil t))
;; Field includes intervening spaces
(should (eql ?n (char-before (field-beginning (point)))))
;; Timestamp extends to the end of the line
(should (eql ?\n (char-after (field-end (point))))))
;; The option `erc-timestamp-right-column' is normally nil by
;; default, but it's a convenient stand in for a sufficiently
;; small `erc-fill-column' (we can force a line break without
;; involving that module).
(should-not erc-timestamp-right-column)
(ert-info ("nil, overlong (hard wrap)")
(let ((erc-timestamp-use-align-to nil)
(erc-timestamp-right-column 20))
(erc-display-message nil 'notice (current-buffer)
"twenty characters"))
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
;; Field includes leading whitespace.
(should (eql (if compat ?\[ ?\n)
(char-after (field-beginning (point)))))
;; Timestamp extends to the end of the line.
(should (eql ?\n (char-after (field-end (point)))))))))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
(ert-deftest erc-timestamp-use-align-to--nil ()
(ert-info ("Field starts on stamp text (compat)")
(let ((erc-stamp--omit-properties-on-folded-lines t))
(erc-stamp-tests--use-align-to--nil 'compat)))
(ert-info ("Field includes leaidng white space")
(erc-stamp-tests--use-align-to--nil nil)))
(defun erc-stamp-tests--use-align-to--t (compat)
(erc-stamp-tests--insert-right
(lambda ()
(ert-info ("t, normal")
(let ((erc-timestamp-use-align-to t))
(let ((msg (erc-format-privmessage "bob" "msg one" nil t)))
(erc-display-message nil nil (current-buffer) msg)))
(goto-char (point-min))
;; Exactly two spaces, one from format, one added by erc-stamp.
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (search-forward "msg one [" nil t))
;; Field covers space between.
(should (eql ?e (char-before (field-beginning (point)))))
(should (eql ?\n (char-after (field-end (point))))))
(ert-info ("t, overlong (hard wrap)")
(let ((erc-timestamp-use-align-to t)
(erc-timestamp-right-column 20))
(let ((msg (erc-format-privmessage "bob" "tttt wwww oooo" nil t)))
(erc-display-message nil nil (current-buffer) msg)))
;; Indented to pos (this is arguably a bug).
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (search-forward-regexp (rx bol (+ "\t") (* " ") "[") nil t))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
;; Field includes leading space.
(should (eql (if compat ?\[ ?\n) (char-after (field-beginning (point)))))
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (eql ?\n (char-after (field-end (point)))))))))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
(ert-deftest erc-timestamp-use-align-to--t ()
(ert-info ("Field starts on stamp text (compat)")
(let ((erc-stamp--omit-properties-on-folded-lines t))
(erc-stamp-tests--use-align-to--t 'compat)))
(ert-info ("Field includes leaidng white space")
(erc-stamp-tests--use-align-to--t nil)))
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(ert-deftest erc-timestamp-use-align-to--integer ()
(erc-stamp-tests--insert-right
(lambda ()
(ert-info ("integer, normal")
(let ((erc-timestamp-use-align-to 1))
(let ((msg (erc-format-privmessage "bob" "msg one" nil t)))
(erc-display-message nil nil (current-buffer) msg)))
(goto-char (point-min))
;; Space not added because included in format string.
(should (search-forward "msg one [" nil t))
;; Field covers space between.
(should (eql ?e (char-before (field-beginning (point)))))
(should (eql ?\n (char-after (field-end (point))))))
(ert-info ("integer, overlong (hard wrap)")
(let ((erc-timestamp-use-align-to 1)
(erc-timestamp-right-column 20))
(let ((msg (erc-format-privmessage "bob" "tttt wwww oooo" nil t)))
(erc-display-message nil nil (current-buffer) msg)))
;; No hard wrap
(should (search-forward "oooo [" nil t))
;; Field starts at leading space.
(should (eql ?\s (char-after (field-beginning (point)))))
(should (eql ?\n (char-after (field-end (point)))))))))
Make erc-fill-wrap work with left-sided stamps * etc/ERC-NEWS: Remove all mention of option `erc-timestamp-align-to' supporting a value of `margin', which has been abandoned. Do mention leading white space before stamps now having stamp-related properties. * lisp/erc/erc-backend.el (erc--reveal-prompt, erc--conceal-prompt): New generic functions with default implementations factored out from `erc--unhide-prompt' and `erc--hide-prompt'. (erc--prompt-hidden-p): New internal predicate function. (erc--unhide-prompt): Defer to `erc--reveal-prompt', and set `erc-prompt' text property to t. (erc--hide-prompt): Defer to `erc--conceal-prompt', and set `erc-prompt' text property to `hidden'. * lisp/erc/erc-compat.el (erc-compat--29-browse-url-irc): Don't use `function-equal'. * lisp/erc/erc-fill.el (erc-fill-wrap-margin-width, erc-fill-wrap-margin-side): New options to control side and initial width of `fill-wrap' margin. (erc-fill--wrap-beginning-of-line): Fix bug involving non-string valued `display' props. (erc-fill-wrap-toggle-truncate-lines): New command to re-enable `visual-line-mode' when toggling off `truncate-lines'. (erc-fill-wrap-mode-map): Remap `toggle-truncate-lines' to `erc-fill-wrap-toggle-truncate-lines'. (erc-fill-wrap-mode, erc-fill-wrap-enable, erc-fill-wrap-disable): Update doc string, persist a few local vars, and conditionally set `erc-stamp--margin-left-p'. When deactivating, disable `visual-line-mode' first. (erc-fill--wrap-continued-message-p): Use `erc-speaker' instead of heuristics when comparing nicks between consecutive messages. (erc-fill-wrap-nudge): Update doc string and account for left-sided stamps. (erc-timestamp-offset): Add comment regarding conditional guard based on function-valued option. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Remove value variant `margin', which was originally intended to be new in ERC 5.6. This functionality was all but useless without the internal minor mode `erc-stamp--display-margin-mode' active. (erc-stamp-right-margin-width): Remove unused option new in 5.6. (erc-stamp--display-margin-force): Remove unused function. (erc-stamp--margin-width, erc-stamp--margin-left-p): New internal variables. (erc-stamp--init-margins-on-connect): New function for initializing mode-managed margin after connecting. (erc-stamp--adjust-right-margin, erc-stamp--adjust-margin): Rename function to latter and accommodate left-hand stamps. (erc-stamp--inherited-props): Move definition higher up in same file. (erc-stamp--display-margin-mode): Update function name, and adjust setup and teardown to accommodate left-handed stamps. Don't add advice around `erc-insert-timestamp-function'. (erc-stamp--last-prompt, erc-stamp--display-prompt-in-left-margin): New function and helper var to convert a normal inserted prompt so that it appears in the left margin. (erc-stamp--refresh-left-margin-prompt): Helper for other modules to quickly refresh prompt outside of insert hooks. (erc--reveal-prompt, erc--conceal-prompt): New implementations for when `erc-stamp--display-margin-mode' is active. (erc-insert-timestamp-left): Convert to generic function and provide implementation for `erc-stamp--display-margin-mode'. (erc-stamp--omit-properties-on-folded-lines): New variable, an escape hatch for propertizing white space before right-side stamps folded over onto another line. (erc-insert-timestamp-right): Don't expect `erc-timestamp-align-to' to ever be the symbol `margin'. Move handling for that case to one contingent on the internal minor mode `erc-stamp--display-margin-mode' being active. Add text properties preceding stamps that occupy a line by their lonesome. See related news entry for rationale. This is arguably a breaking change. * lisp/erc/erc.el (erc--refresh-prompt-hook): New hook variable for modules to adjust prompt properties whenever it's refreshed. (erc--refresh-prompt): Fix bug in which user-defined prompt functions failed to hide when quitting in server buffers. Run new hook `erc--refresh-prompt-hook'. (erc-display-prompt): Add comment noting that the text property `erc-prompt' now actually matters: it's t while a session is running and `hidden' when disconnected. * test/lisp/erc/erc-fill-tests.el (erc-fill--left-hand-stamps): New test. * test/lisp/erc/erc-stamp-tests.el (erc-stamp-tests--use-align-to--nil, erc-stamp-tests--use-align-to--t): New functions forged from old test bodies to allow optionally asserting pre-5.6 behavior regarding leading white space on right-hand stamps that exist on their own line. (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Parameterize with compatibility flag. (erc-timestamp-use-align-to--margin, erc-stamp--display-margin-mode--right): Rename test to latter. * test/lisp/erc/erc-tests.el (erc-hide-prompt): Add some assertions for new possible value of `erc-prompt' text property. * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: New test data file. (Bug#60936)
2023-07-14 06:12:30 -07:00
(ert-deftest erc-stamp--display-margin-mode--right ()
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(erc-stamp-tests--insert-right
(lambda ()
(erc-stamp--display-margin-mode +1)
(ert-info ("margin, normal")
(let ((erc-timestamp-use-align-to 'margin))
(let ((msg (erc-format-privmessage "bob" "msg one" nil t)))
(put-text-property 0 (length msg) 'wrap-prefix 10 msg)
(erc-display-message nil nil (current-buffer) msg)))
(goto-char (point-min))
;; Leading space added as part of the stamp's field.
(should (search-forward "msg one [" nil t))
;; Field covers stamp and space.
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (eql ?e (char-before (field-beginning (point)))))
;; Vanity props extended.
Put display properties to better use in erc-stamp * lisp/erc/erc-log.el (erc-log-filter-function): Add new value `erc-stamp-prefix-log-filter'. * lisp/erc/erc-stamp.el (erc-timestamp-use-align-to): Enhance meaning of option to accept numeric value for dynamically aligned right-hand stamps. Use `graphic-display-p' to determine default value even though, as stated in the manual, terminal Emacs also supports the "space" display spec. (erc-stamp-right-margin-width): New option to determine width of right margin when `erc-stamp--display-margin-mode' is active or `erc-timestamp-use-align-to' is set to `margin'. (erc-stamp--display-margin-force): Add new helper function for `erc-stamp--display-margin-mode'. (erc-stamp--adjust-right-margin): New function to adjust width of right margin. (erc-stamp-prefix-log-filter): New value for `erc-log-filter-function' compatible with modules that activate `erc-stamp--display-margin-mode'. (erc-stamp--display-margin-mode): Add internal minor mode to help other modules quickly ensure left-right, display-prop-oriented stamps are showing correctly. Does not support left-hand-only stamps. (erc-insert-aligned): Deprecate function and remove from primary client code path. (erc-stamp--inherited-props): Add internal constant to hold properties that should be inherited from any stamp-bearing message being inserted. (erc-insert-timestamp-right): Account for new display-related values of `erc-timestamp-use-align-to'. * test/lisp/erc/erc-stamp-tests.el (erc-timestamp-use-align-to--nil, erc-timestamp-use-align-to--t): Adjust spacing for new default right-hand stamp, `erc-format-timestamp', which lacks a leading space. (erc-timestamp-use-align-to--integer, erc-timestamp-use-align-to--margin): New tests. (Bug#60936.)
2021-11-24 05:35:35 -08:00
(should (get-text-property (field-beginning (point)) 'wrap-prefix))
(should (get-text-property (1+ (field-beginning (point))) 'wrap-prefix))
(should (get-text-property (1- (field-end (point))) 'wrap-prefix))
(should (eql ?\n (char-after (field-end (point))))))
(ert-info ("margin, overlong (hard wrap)")
(let ((erc-timestamp-use-align-to 'margin)
(erc-timestamp-right-column 20))
(let ((msg (erc-format-privmessage "bob" "tttt wwww oooo" nil t)))
(erc-display-message nil nil (current-buffer) msg)))
;; No hard wrap.
(should (search-forward "oooo [" nil t))
;; Field starts at managed space before format string.
(should (eql ?\s (char-after (field-beginning (point)))))
(should (eql ?\n (char-after (field-end (point)))))))))
;; This concerns a proposed partial reversal of the changes resulting
;; from:
;;
;; 24.1.50; Wrong behavior of move-end-of-line in ERC (Bug#11706)
;;
;; Perhaps core behavior has changed since this bug was reported, but
;; C-e stopping one char short of EOL no longer seems a problem.
;; However, invoking C-n (`next-line') exhibits a similar effect.
;; When point is in a stamp or near the beginning of a line, issuing a
;; C-n puts point one past the start of the message (i.e., two chars
;; beyond the timestamp's closing "]". Dropping the invisible
;; property when timestamps are hidden does indeed prevent this, but
;; it's also a lasting commitment. The docs mention that it's
;; pointless to pair the old `intangible' property with `invisible'
;; and suggest users look at `cursor-intangible-mode'. Turning off
;; the latter does indeed do the trick as does decrementing the end of
;; the `cursor-intangible' interval so that, in addition to C-n
;; working, a C-f from before the timestamp doesn't overshoot. This
;; appears to be the case whether `erc-hide-timestamps' is enabled or
;; not, but it may be inadvisable for some reason (a hack) and
;; therefore warrants further investigation.
;;
;; Note some striking omissions here:
;;
;; 1. a lack of `fill' module integration (we simulate it by
;; making lines short enough to not wrap)
;; 2. functions like `line-move' behave differently when
;; `noninteractive'
;; 3. no actual test assertions involving `cursor-sensor' movement
;; even though that's a huge ingredient
(ert-deftest erc-timestamp-intangible--left ()
(let ((erc-timestamp-only-if-changed-flag nil)
(erc-timestamp-intangible t) ; default changed to nil in 2014
(erc-hide-timestamps t)
(erc-insert-timestamp-function 'erc-insert-timestamp-left)
(erc-insert-modify-hook '(erc-make-read-only erc-add-timestamp))
msg
erc-kill-channel-hook erc-kill-server-hook erc-kill-buffer-hook)
(should (not cursor-sensor-inhibit))
Move ERC test utilities to common file * lisp/erc/erc-common.el (erc--define-catalog): Update name of reference to convenience command now located in `erc-tests-common'. * test/lisp/erc/erc-button-tests.el: Require common test-util library `erc-tests-common', located under test/lisp/erc/resources. ; (erc-button-alist--url, ; erc-button-tests--erc-button-alist--function-as-form, ; erc-button-tests--erc-button-alist--nil-form, ; erc-button--display-error-notice-with-keys): Use common helper ; `erc-tests-common-init-server-proc' from test-utils library. * test/lisp/erc/erc-fill-tests.el: Require `erc-tests-common'. (erc-fill-tests--wrap-populate): Use helper `erc-tests-common-init-server-proc'. (erc-fill-tests--save-p): Remove. See replacement `erc-tests-common-snapshot-save-p' in erc-tests-common. (erc-fill-tests--graphic-dir): Add trailing slash. (erc-fill-tests--compare): Move body to generalized utility `erc-tests-common-snapshot-compare' in erc-tests-common. * test/lisp/erc/erc-goodies-tests.el: Require `erc-tests-common'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move here from erc-tests.el. * test/lisp/erc/erc-networks-tests.el: Load `erc-tests-common'. (erc-networks-tests--create-live-proc): Defer to `erc-tests-common-init-server-proc' and drop optional buffer param. (erc-networks-tests--clean-bufs): Defer to `erc-tests-common-kill-buffers'. (erc-networks--rename-server-buffer--existing--live): Call `erc-networks-tests--create-live-proc' in server buffer. * test/lisp/erc/erc-scenarios-internal.el: Load `erc-tests-common'. (erc-scenarios-internal--run-graphical-all): Use `erc-tests-common-create-subprocess' to create process. * test/lisp/erc/erc-scenarios-sasl.el (erc-scenarios-sasl--plain-fail): Silence error message. * test/lisp/erc/erc-stamp-tests.el: Require `erc-tests-common'. (erc-stamp-tests--insert-right, erc-timestamp-intangible--left): Use `erc-tests-common-init-server-proc'. (erc-tests--assert-get-inserted-msg/stamp, erc-stamp-tests--assert-get-inserted-msg/stamp): Move from erc-tests.el, renaming to latter. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move here from erc-tests.el. * test/lisp/erc/erc-tests.el: Require `erc-tests-common'. (erc-with-server-buffer): Use renamed test-helper utility `erc-tests-common-init-server-proc'. (erc-tests--send-prep, erc-tests--set-fake-server-process): Move to `erc-tests-common' library and rename to `erc-tests-common-prep-for-insertion' and `erc-tests-common-init-server-proc', respectively. ; (erc-hide-prompt, erc--refresh-prompt, ; erc-setup-buffer--custom-action, erc--parsed-prefix, ; erc--update-channel-modes, erc--channel-modes, ; erc--channel-modes/graphic-p, erc-ring-previous-command): Use ; `erc-tests-common-prep-for-insertion' instead of ; `erc-tests--send-prep', and use `erc-tests-common-init-server-proc' ; instead of `erc-tests--set-fake-server-process'. (erc-tests--with-process-input-spy): Move to `erc-tests-common' and rename `erc-tests-common-with-process-input-spy'. ; (erc--check-prompt-input-functions, erc-send-current-line, ; erc--check-prompt-input-for-multiline-blanks, ; erc-send-whitespace-lines): Use renamed ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. ; (erc-process-input-line): Use renamed ; `erc-tests-common-init-server-proc'. (erc-tests--get-inserted-msg-setup, erc-tests--assert-get-inserted-msg, erc-tests--assert-get-inserted-msg/basic, erc-tests--assert-get-inserted-msg-readonly-with): Move to `erc-tests-common' and rename with "common" prefix, using single instead of double hyphen. (erc-tests--assert-get-inserted-msg/stamp): Move to `erc-stamp-tests' and rename with "stamp" prefix. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move to `erc-stamp-tests'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move to `erc-goodies-tests'. ; (erc--get-inserted-msg-beg/basic, ; erc--get-inserted-msg-end/basic, ; erc--get-inserted-msg-bounds/basic): Use common helpers. ; (erc--route-insertion): Use renamed helper functions ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. (erc-tests--make-server-buf): Move to `erc-common-tests' and rename with "common" prefix. (erc-tests--make-client-buf): Remove unused function without supplying replacement. ; (erc-handle-irc-url): Use renamed `erc-tests-common-make-server-buf' ; utility function. ; (erc-tests--assert-printed-in-subprocess): Use helper from common lib ; `erc-tests-common-create-subprocess code' to do the heavy lifting. (erc-tests--string-to-propertized-parts, erc-tests-pp-propertized-parts): Move to `erc-tests-common' and rename with "common" prefix. * test/lisp/erc/resources/erc-tests-common.el: New file containing helper utilities and fixtures used by multiple files in test/lisp/erc.
2023-12-24 12:21:49 -08:00
(erc-mode)
Move ERC test utilities to common file * lisp/erc/erc-common.el (erc--define-catalog): Update name of reference to convenience command now located in `erc-tests-common'. * test/lisp/erc/erc-button-tests.el: Require common test-util library `erc-tests-common', located under test/lisp/erc/resources. ; (erc-button-alist--url, ; erc-button-tests--erc-button-alist--function-as-form, ; erc-button-tests--erc-button-alist--nil-form, ; erc-button--display-error-notice-with-keys): Use common helper ; `erc-tests-common-init-server-proc' from test-utils library. * test/lisp/erc/erc-fill-tests.el: Require `erc-tests-common'. (erc-fill-tests--wrap-populate): Use helper `erc-tests-common-init-server-proc'. (erc-fill-tests--save-p): Remove. See replacement `erc-tests-common-snapshot-save-p' in erc-tests-common. (erc-fill-tests--graphic-dir): Add trailing slash. (erc-fill-tests--compare): Move body to generalized utility `erc-tests-common-snapshot-compare' in erc-tests-common. * test/lisp/erc/erc-goodies-tests.el: Require `erc-tests-common'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move here from erc-tests.el. * test/lisp/erc/erc-networks-tests.el: Load `erc-tests-common'. (erc-networks-tests--create-live-proc): Defer to `erc-tests-common-init-server-proc' and drop optional buffer param. (erc-networks-tests--clean-bufs): Defer to `erc-tests-common-kill-buffers'. (erc-networks--rename-server-buffer--existing--live): Call `erc-networks-tests--create-live-proc' in server buffer. * test/lisp/erc/erc-scenarios-internal.el: Load `erc-tests-common'. (erc-scenarios-internal--run-graphical-all): Use `erc-tests-common-create-subprocess' to create process. * test/lisp/erc/erc-scenarios-sasl.el (erc-scenarios-sasl--plain-fail): Silence error message. * test/lisp/erc/erc-stamp-tests.el: Require `erc-tests-common'. (erc-stamp-tests--insert-right, erc-timestamp-intangible--left): Use `erc-tests-common-init-server-proc'. (erc-tests--assert-get-inserted-msg/stamp, erc-stamp-tests--assert-get-inserted-msg/stamp): Move from erc-tests.el, renaming to latter. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move here from erc-tests.el. * test/lisp/erc/erc-tests.el: Require `erc-tests-common'. (erc-with-server-buffer): Use renamed test-helper utility `erc-tests-common-init-server-proc'. (erc-tests--send-prep, erc-tests--set-fake-server-process): Move to `erc-tests-common' library and rename to `erc-tests-common-prep-for-insertion' and `erc-tests-common-init-server-proc', respectively. ; (erc-hide-prompt, erc--refresh-prompt, ; erc-setup-buffer--custom-action, erc--parsed-prefix, ; erc--update-channel-modes, erc--channel-modes, ; erc--channel-modes/graphic-p, erc-ring-previous-command): Use ; `erc-tests-common-prep-for-insertion' instead of ; `erc-tests--send-prep', and use `erc-tests-common-init-server-proc' ; instead of `erc-tests--set-fake-server-process'. (erc-tests--with-process-input-spy): Move to `erc-tests-common' and rename `erc-tests-common-with-process-input-spy'. ; (erc--check-prompt-input-functions, erc-send-current-line, ; erc--check-prompt-input-for-multiline-blanks, ; erc-send-whitespace-lines): Use renamed ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. ; (erc-process-input-line): Use renamed ; `erc-tests-common-init-server-proc'. (erc-tests--get-inserted-msg-setup, erc-tests--assert-get-inserted-msg, erc-tests--assert-get-inserted-msg/basic, erc-tests--assert-get-inserted-msg-readonly-with): Move to `erc-tests-common' and rename with "common" prefix, using single instead of double hyphen. (erc-tests--assert-get-inserted-msg/stamp): Move to `erc-stamp-tests' and rename with "stamp" prefix. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move to `erc-stamp-tests'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move to `erc-goodies-tests'. ; (erc--get-inserted-msg-beg/basic, ; erc--get-inserted-msg-end/basic, ; erc--get-inserted-msg-bounds/basic): Use common helpers. ; (erc--route-insertion): Use renamed helper functions ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. (erc-tests--make-server-buf): Move to `erc-common-tests' and rename with "common" prefix. (erc-tests--make-client-buf): Remove unused function without supplying replacement. ; (erc-handle-irc-url): Use renamed `erc-tests-common-make-server-buf' ; utility function. ; (erc-tests--assert-printed-in-subprocess): Use helper from common lib ; `erc-tests-common-create-subprocess code' to do the heavy lifting. (erc-tests--string-to-propertized-parts, erc-tests-pp-propertized-parts): Move to `erc-tests-common' and rename with "common" prefix. * test/lisp/erc/resources/erc-tests-common.el: New file containing helper utilities and fixtures used by multiple files in test/lisp/erc.
2023-12-24 12:21:49 -08:00
(erc-tests-common-init-server-proc "true")
(with-current-buffer (get-buffer-create "*erc-timestamp-intangible*")
(erc-mode)
(erc--initialize-markers (point) nil)
(erc-stamp--manage-local-options-state)
(erc-display-message nil 'notice (current-buffer) "Welcome")
;;
;; Pretend `fill' is active and that these lines are
;; folded. Otherwise, there's an annoying issue on wrapped lines
;; (when visual-line-mode is off and stamps are visible) where
;; C-e sends you to the end of the previous line.
(setq msg "Lorem ipsum dolor sit amet")
(erc-display-message nil nil (current-buffer)
(erc-format-privmessage "alyssa" msg nil t))
(erc-display-message nil 'notice (current-buffer) "Home")
(goto-char (point-min))
;; EOL is actually EOL (Bug#11706)
(ert-info ("Notice before stamp, C-e") ; first line/stamp
(should (search-forward "Welcome" nil t))
(ert-simulate-command '(erc-bol))
(should (looking-at (rx "[")))
(let ((end (pos-eol))) ; `line-end-position' fails because fields
(ert-simulate-command '(move-end-of-line 1))
(should (= end (point)))))
(ert-info ("Privmsg before stamp, C-e")
(should (search-forward "Lorem" nil t))
(goto-char (pos-bol))
(should (looking-at (rx "[")))
(let ((end (pos-eol)))
(ert-simulate-command '(move-end-of-line 1))
(should (= end (point)))))
(ert-info ("Privmsg first line, C-e")
(goto-char (pos-bol))
(should (search-forward "ipsum" nil t))
(let ((end (pos-eol)))
(ert-simulate-command '(move-end-of-line 1))
(should (= end (point)))))
(when noninteractive
(kill-buffer)))))
Add optional timezone param to erc-echo-timestamp * etc/ERC-NEWS: Move `erc-echo-timestamp' from misc section to own entry, and mention option `erc-echo-timestamp-zone'. * lisp/erc/erc-stamp.el (erc-echo-timestamps): Mention that some finagling is required if enabling this option after activating the module. (erc-echo-timestamp-format): Add additional Custom choice constants and make the existing default one of them. (erc-echo-timestamp-zone): New option to specify timezone for option `erc-echo-timestamps' and function `erc-echo-timestamp'. (erc-stamp-mode, erc-stamp-enable, erc-stamp-disable): Call `erc-stamp--setup' instead of `erc-munge-invisibility-spec'. (erc-stamp--current-time): Use `current-time' instead of `erc-current-time'. (erc-add-timestamp): Improve readability slightly, and change `fboundp' to `functionp' to avoid signaling an error when the variable's value is not a symbol. (erc-munge-invisibility-spec): Perform teardown when boolean flag options, like `erc-timestamp-intangible' and `erc-echo-timestamps' are nil. (erc-stamp--setup): Call `erc-munge-invisibility-spec', possibly binding timestamp options to nil to force a tear down). (erc-stamp--last-stamp, erc-stamp--on-clear-message): New function and helper state variable to tell Emacs not to clear the current timestamp message when navigating within the same IRC message. (erc-echo-timestamp): Add optional `zone' parameter, to be passed directly to `format-time-string', when non-interactive, and massaged sensibly otherwise. Set the local variable `erc-stamp--last-stamp'. * test/lisp/erc/erc-stamp-tests.el (erc-echo-timestamp): New test. (Bug#60936)
2023-08-30 23:15:22 -07:00
(ert-deftest erc-echo-timestamp ()
:tags (and (null (getenv "CI")) '(:unstable))
Add optional timezone param to erc-echo-timestamp * etc/ERC-NEWS: Move `erc-echo-timestamp' from misc section to own entry, and mention option `erc-echo-timestamp-zone'. * lisp/erc/erc-stamp.el (erc-echo-timestamps): Mention that some finagling is required if enabling this option after activating the module. (erc-echo-timestamp-format): Add additional Custom choice constants and make the existing default one of them. (erc-echo-timestamp-zone): New option to specify timezone for option `erc-echo-timestamps' and function `erc-echo-timestamp'. (erc-stamp-mode, erc-stamp-enable, erc-stamp-disable): Call `erc-stamp--setup' instead of `erc-munge-invisibility-spec'. (erc-stamp--current-time): Use `current-time' instead of `erc-current-time'. (erc-add-timestamp): Improve readability slightly, and change `fboundp' to `functionp' to avoid signaling an error when the variable's value is not a symbol. (erc-munge-invisibility-spec): Perform teardown when boolean flag options, like `erc-timestamp-intangible' and `erc-echo-timestamps' are nil. (erc-stamp--setup): Call `erc-munge-invisibility-spec', possibly binding timestamp options to nil to force a tear down). (erc-stamp--last-stamp, erc-stamp--on-clear-message): New function and helper state variable to tell Emacs not to clear the current timestamp message when navigating within the same IRC message. (erc-echo-timestamp): Add optional `zone' parameter, to be passed directly to `format-time-string', when non-interactive, and massaged sensibly otherwise. Set the local variable `erc-stamp--last-stamp'. * test/lisp/erc/erc-stamp-tests.el (erc-echo-timestamp): New test. (Bug#60936)
2023-08-30 23:15:22 -07:00
(should-not erc-echo-timestamps)
(should-not erc-stamp--last-stamp)
Double hyphenate internal ERC 5.6 text props * lisp/erc/erc-fill.el (erc-fill, erc-fill-static, erc-fill--wrap-continued-message-p, erc-fill-wrap, erc-fill--wrap-rejigger-region): Add second hyphen to "msg prop" text properties. Rename `erc-speaker' to `erc--speaker'. * lisp/erc/erc-goodies.el (erc--command-indicator-display): Rename `erc-msg' to `erc--msg'. * lisp/erc/erc-stamp.el (erc-stamp--current-time, erc-add-timestamp, erc-stamp-prefix-log-filter, erc-stamp--lr-date-on-pre-modify, erc-munge-invisibility-spec, erc-stamp--add-csf-on-post-modify, erc-stamp--on-clear-message, erc-echo-timestamp, erc--echo-ts-csf): Rename "msg props" with second hyphen. * lisp/erc/erc-track.el (erc-track--skipped-msgs, erc-track-modified-channels): Rename "msg prop" text properties with second hyphen. * lisp/erc/erc.el (erc--msg-props): Update doc with double-hyphenated "msg prop" names. (erc--send-action-display erc--get-inserted-msg-bounds, erc--traverse-inserted, erc-insert-line, erc-display-line, erc--ranked-properties, erc-display-message, erc--get-speaker-bounds, erc-process-ctcp-query, erc-display-msg): Update all "msg prop" names to have two hyphens. (erc--send-action-display, erc--own-property-names, erc--get-speaker-bounds, erc-format-privmessage, erc-format-my-nick, erc-ctcp-query-ACTION): Rename `erc-speaker' to `erc--speaker'. * test/lisp/erc/erc-scenarios-display-message.el (erc-scenarios-display-message--multibuf): Double hyphenate "msg prop" text properties. * test/lisp/erc/erc-scenarios-match.el (erc-scenarios-match--hide-fools/stamp-both/fill-wrap, erc-scenarios-match--hide-fools/stamp-both/fill-wrap/speak, erc-scenarios-match--stamp-both-invisible-fill-static): Update "msg prop" names. * test/lisp/erc/erc-scenarios-stamp.el (erc-scenarios-stamp--on-post-modify, erc-scenarios-stamp--left/display-margin-mode, erc-scenarios-stamp--legacy-date-stamps, erc-scenarios-stamp--on-insert-modify, erc-scenarios-stamp--date-mode/left-and-right): Add second hyphen to all "msg props". Rename `erc-speaker' to `erc--speaker'. * test/lisp/erc/erc-stamp-tests.el (erc-echo-timestamp): Rename "msg prop". * test/lisp/erc/erc-tests.el (erc--get-inserted-msg-bounds, erc--delete-inserted-message, erc--order-text-properties-from-hash, erc--route-insertion): Rename "msg props" with second hyphen. (erc-format-privmessage): Rename `erc-speaker' to `erc--speaker'. (Bug#60936) (Bug#67677) ; * test/lisp/erc/resources/fill/snapshots/merge-01-start.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/merge-02-right.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/merge-wrap-01.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/merge-wrap-indicator-post-01.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/merge-wrap-indicator-pre-01.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/monospace-01-start.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/monospace-02-right.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/monospace-03-left.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/monospace-04-reset.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/spacing-01-mono.eld: ; Add second hyphen to msg props. ; * test/lisp/erc/resources/fill/snapshots/stamps-left-01.eld: ; Add second hyphen to msg props.
2023-12-01 22:30:04 -08:00
(insert (propertize "a" 'erc--ts 433483200 'erc--msg 'msg) "bc")
Add optional timezone param to erc-echo-timestamp * etc/ERC-NEWS: Move `erc-echo-timestamp' from misc section to own entry, and mention option `erc-echo-timestamp-zone'. * lisp/erc/erc-stamp.el (erc-echo-timestamps): Mention that some finagling is required if enabling this option after activating the module. (erc-echo-timestamp-format): Add additional Custom choice constants and make the existing default one of them. (erc-echo-timestamp-zone): New option to specify timezone for option `erc-echo-timestamps' and function `erc-echo-timestamp'. (erc-stamp-mode, erc-stamp-enable, erc-stamp-disable): Call `erc-stamp--setup' instead of `erc-munge-invisibility-spec'. (erc-stamp--current-time): Use `current-time' instead of `erc-current-time'. (erc-add-timestamp): Improve readability slightly, and change `fboundp' to `functionp' to avoid signaling an error when the variable's value is not a symbol. (erc-munge-invisibility-spec): Perform teardown when boolean flag options, like `erc-timestamp-intangible' and `erc-echo-timestamps' are nil. (erc-stamp--setup): Call `erc-munge-invisibility-spec', possibly binding timestamp options to nil to force a tear down). (erc-stamp--last-stamp, erc-stamp--on-clear-message): New function and helper state variable to tell Emacs not to clear the current timestamp message when navigating within the same IRC message. (erc-echo-timestamp): Add optional `zone' parameter, to be passed directly to `format-time-string', when non-interactive, and massaged sensibly otherwise. Set the local variable `erc-stamp--last-stamp'. * test/lisp/erc/erc-stamp-tests.el (erc-echo-timestamp): New test. (Bug#60936)
2023-08-30 23:15:22 -07:00
(goto-char (point-min))
(let ((inhibit-message t)
(erc-echo-timestamp-format "%Y-%m-%d %H:%M:%S %Z")
(erc-echo-timestamp-zone (list (* 60 60 -4) "EDT")))
;; No-op when non-interactive and option is nil
(should-not (erc--echo-ts-csf nil nil 'entered))
(should-not erc-stamp--last-stamp)
;; Non-interactive (cursor sensor function)
(let ((erc-echo-timestamps t))
(should (equal (erc--echo-ts-csf nil nil 'entered)
"1983-09-27 00:00:00 EDT")))
(should (= 433483200 erc-stamp--last-stamp))
;; Interactive
(should (equal (call-interactively #'erc-echo-timestamp)
"1983-09-27 00:00:00 EDT"))
;; Interactive with zone
(let ((current-prefix-arg '(4)))
(should (member (call-interactively #'erc-echo-timestamp)
'("1983-09-27 04:00:00 GMT"
"1983-09-27 04:00:00 UTC"))))
Add optional timezone param to erc-echo-timestamp * etc/ERC-NEWS: Move `erc-echo-timestamp' from misc section to own entry, and mention option `erc-echo-timestamp-zone'. * lisp/erc/erc-stamp.el (erc-echo-timestamps): Mention that some finagling is required if enabling this option after activating the module. (erc-echo-timestamp-format): Add additional Custom choice constants and make the existing default one of them. (erc-echo-timestamp-zone): New option to specify timezone for option `erc-echo-timestamps' and function `erc-echo-timestamp'. (erc-stamp-mode, erc-stamp-enable, erc-stamp-disable): Call `erc-stamp--setup' instead of `erc-munge-invisibility-spec'. (erc-stamp--current-time): Use `current-time' instead of `erc-current-time'. (erc-add-timestamp): Improve readability slightly, and change `fboundp' to `functionp' to avoid signaling an error when the variable's value is not a symbol. (erc-munge-invisibility-spec): Perform teardown when boolean flag options, like `erc-timestamp-intangible' and `erc-echo-timestamps' are nil. (erc-stamp--setup): Call `erc-munge-invisibility-spec', possibly binding timestamp options to nil to force a tear down). (erc-stamp--last-stamp, erc-stamp--on-clear-message): New function and helper state variable to tell Emacs not to clear the current timestamp message when navigating within the same IRC message. (erc-echo-timestamp): Add optional `zone' parameter, to be passed directly to `format-time-string', when non-interactive, and massaged sensibly otherwise. Set the local variable `erc-stamp--last-stamp'. * test/lisp/erc/erc-stamp-tests.el (erc-echo-timestamp): New test. (Bug#60936)
2023-08-30 23:15:22 -07:00
(let ((current-prefix-arg -7))
(should (equal (call-interactively #'erc-echo-timestamp)
"1983-09-26 21:00:00 -07")))))
Move ERC test utilities to common file * lisp/erc/erc-common.el (erc--define-catalog): Update name of reference to convenience command now located in `erc-tests-common'. * test/lisp/erc/erc-button-tests.el: Require common test-util library `erc-tests-common', located under test/lisp/erc/resources. ; (erc-button-alist--url, ; erc-button-tests--erc-button-alist--function-as-form, ; erc-button-tests--erc-button-alist--nil-form, ; erc-button--display-error-notice-with-keys): Use common helper ; `erc-tests-common-init-server-proc' from test-utils library. * test/lisp/erc/erc-fill-tests.el: Require `erc-tests-common'. (erc-fill-tests--wrap-populate): Use helper `erc-tests-common-init-server-proc'. (erc-fill-tests--save-p): Remove. See replacement `erc-tests-common-snapshot-save-p' in erc-tests-common. (erc-fill-tests--graphic-dir): Add trailing slash. (erc-fill-tests--compare): Move body to generalized utility `erc-tests-common-snapshot-compare' in erc-tests-common. * test/lisp/erc/erc-goodies-tests.el: Require `erc-tests-common'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move here from erc-tests.el. * test/lisp/erc/erc-networks-tests.el: Load `erc-tests-common'. (erc-networks-tests--create-live-proc): Defer to `erc-tests-common-init-server-proc' and drop optional buffer param. (erc-networks-tests--clean-bufs): Defer to `erc-tests-common-kill-buffers'. (erc-networks--rename-server-buffer--existing--live): Call `erc-networks-tests--create-live-proc' in server buffer. * test/lisp/erc/erc-scenarios-internal.el: Load `erc-tests-common'. (erc-scenarios-internal--run-graphical-all): Use `erc-tests-common-create-subprocess' to create process. * test/lisp/erc/erc-scenarios-sasl.el (erc-scenarios-sasl--plain-fail): Silence error message. * test/lisp/erc/erc-stamp-tests.el: Require `erc-tests-common'. (erc-stamp-tests--insert-right, erc-timestamp-intangible--left): Use `erc-tests-common-init-server-proc'. (erc-tests--assert-get-inserted-msg/stamp, erc-stamp-tests--assert-get-inserted-msg/stamp): Move from erc-tests.el, renaming to latter. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move here from erc-tests.el. * test/lisp/erc/erc-tests.el: Require `erc-tests-common'. (erc-with-server-buffer): Use renamed test-helper utility `erc-tests-common-init-server-proc'. (erc-tests--send-prep, erc-tests--set-fake-server-process): Move to `erc-tests-common' library and rename to `erc-tests-common-prep-for-insertion' and `erc-tests-common-init-server-proc', respectively. ; (erc-hide-prompt, erc--refresh-prompt, ; erc-setup-buffer--custom-action, erc--parsed-prefix, ; erc--update-channel-modes, erc--channel-modes, ; erc--channel-modes/graphic-p, erc-ring-previous-command): Use ; `erc-tests-common-prep-for-insertion' instead of ; `erc-tests--send-prep', and use `erc-tests-common-init-server-proc' ; instead of `erc-tests--set-fake-server-process'. (erc-tests--with-process-input-spy): Move to `erc-tests-common' and rename `erc-tests-common-with-process-input-spy'. ; (erc--check-prompt-input-functions, erc-send-current-line, ; erc--check-prompt-input-for-multiline-blanks, ; erc-send-whitespace-lines): Use renamed ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. ; (erc-process-input-line): Use renamed ; `erc-tests-common-init-server-proc'. (erc-tests--get-inserted-msg-setup, erc-tests--assert-get-inserted-msg, erc-tests--assert-get-inserted-msg/basic, erc-tests--assert-get-inserted-msg-readonly-with): Move to `erc-tests-common' and rename with "common" prefix, using single instead of double hyphen. (erc-tests--assert-get-inserted-msg/stamp): Move to `erc-stamp-tests' and rename with "stamp" prefix. (erc--get-inserted-msg-beg/stamp, erc--get-inserted-msg-beg/readonly/stamp, erc--get-inserted-msg-end/stamp, erc--get-inserted-msg-end/readonly/stamp, erc--get-inserted-msg-bounds/stamp, erc--get-inserted-msg-bounds/readonly/stamp): Move to `erc-stamp-tests'. (erc--get-inserted-msg-beg/readonly, erc--get-inserted-msg-end/readonly, erc--get-inserted-msg-bounds/readonly): Move to `erc-goodies-tests'. ; (erc--get-inserted-msg-beg/basic, ; erc--get-inserted-msg-end/basic, ; erc--get-inserted-msg-bounds/basic): Use common helpers. ; (erc--route-insertion): Use renamed helper functions ; `erc-tests-common-with-process-input-spy' and ; `erc-tests-common-init-server-proc'. (erc-tests--make-server-buf): Move to `erc-common-tests' and rename with "common" prefix. (erc-tests--make-client-buf): Remove unused function without supplying replacement. ; (erc-handle-irc-url): Use renamed `erc-tests-common-make-server-buf' ; utility function. ; (erc-tests--assert-printed-in-subprocess): Use helper from common lib ; `erc-tests-common-create-subprocess code' to do the heavy lifting. (erc-tests--string-to-propertized-parts, erc-tests-pp-propertized-parts): Move to `erc-tests-common' and rename with "common" prefix. * test/lisp/erc/resources/erc-tests-common.el: New file containing helper utilities and fixtures used by multiple files in test/lisp/erc.
2023-12-24 12:21:49 -08:00
(defun erc-stamp-tests--assert-get-inserted-msg/stamp (test-fn)
(let ((erc-insert-modify-hook erc-insert-modify-hook)
(erc-insert-timestamp-function 'erc-insert-timestamp-right)
(erc-timestamp-use-align-to 0)
(erc-timestamp-format "[00:00]"))
(cl-pushnew 'erc-add-timestamp erc-insert-modify-hook)
(erc-tests-common-get-inserted-msg-setup))
(goto-char 19)
(should (looking-back (rx "<bob> hi [00:00]")))
(erc-tests-common-assert-get-inserted-msg 3 19 test-fn))
(ert-deftest erc--get-inserted-msg-beg/stamp ()
(erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg) (should (= 3 (erc--get-inserted-msg-beg arg))))))
(ert-deftest erc--get-inserted-msg-beg/readonly/stamp ()
(erc-tests-common-assert-get-inserted-msg-readonly-with
#'erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg) (should (= 3 (erc--get-inserted-msg-beg arg))))))
(ert-deftest erc--get-inserted-msg-end/stamp ()
(erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg) (should (= 19 (erc--get-inserted-msg-end arg))))))
(ert-deftest erc--get-inserted-msg-end/readonly/stamp ()
(erc-tests-common-assert-get-inserted-msg-readonly-with
#'erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg) (should (= 19 (erc--get-inserted-msg-end arg))))))
(ert-deftest erc--get-inserted-msg-bounds/stamp ()
(erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg)
(should (equal '(3 . 19) (erc--get-inserted-msg-bounds arg))))))
(ert-deftest erc--get-inserted-msg-bounds/readonly/stamp ()
(erc-tests-common-assert-get-inserted-msg-readonly-with
#'erc-stamp-tests--assert-get-inserted-msg/stamp
(lambda (arg)
(should (equal '(3 . 19) (erc--get-inserted-msg-bounds arg))))))
Reconcile erc-stamp--date-stamps when merging buffers * etc/ERC-NEWS: Mention new face `erc-information'. * lisp/erc/erc-button.el (erc-button-add-buttons): Skip buttonization when the "msg prop" `erc--skip' is present and contains the symbol `button'. Set `alist' to nil in the same guard condition as a roundabout way of suppressing further processing. * lisp/erc/erc-networks.el (erc--insert-admin-message): Forward declaration. (erc-networks--insert-transplanted-content) (erc-networks--transplant-buffer-content): Replace former with latter. Change signature to take source and destination buffers as parameters. (erc-networks--transplant-target-buffer-function): New function-valued variable. (erc-networks--target-transplant-in-progress-p): New variable, a flag for downstream code to detect when a transplant is underway. (erc-networks--reclaim-orphaned-target-buffers): Defer to `erc-networks--transplant-target-buffer-function' to handle the actual transplant business. Crucially, kill the buffer afterwards instead of beforehand. If new buffer-association bugs emerge related to the combining of old or renamed target buffers, this reordering may be at fault. (erc-networks--copy-over-server-buffer-contents): Pass old and new buffers to `erc-networks--insert-transplanted-content'. * lisp/erc/erc-stamp.el (erc-stamp--defer-date-insertion-on-post-modify): Set `fn' slot of `erc-stamp--date' instance to `ignore' when running the actual callback in order to conserve a little space. (erc-stamp--date-mode): Add and remove hook members for `erc-networks--copy-server-buffer-functions' and `erc-networks--transplant-target-buffer-function'. (erc-insert-timestamp-left-and-right): Always clear `erc-timestamp-last-inserted-right' to ensure a right stamp accompanies every date stamp. (erc-stamp--dedupe-date-stamps) (erc-stamp--dedupe-date-stamps-from-buffer) (erc-stamp--dedupe-date-stamps-from-target-buffer): New functions. Date stamp behavior was revamped as part of bug#60936. * lisp/erc/erc.el (erc-informational): New face. (erc--insert-admin-message): New function to hide some "msg prop" complexity from "upstream" libraries, like `erc-networks', and thus avoid more forward-declarations. A less smelly approach would be to devise a general interface owned by such libraries, or erc-common, that `erc-mode' could then hook into on init. (erc-display-message-highlight): Make face matching more limber to accommodate the convention of face names lacking a "-face" suffix. (erc-message-english-graft): New variable. (erc-kill-channel): Inhibit execution of hook when `erc-networks--target-transplant-in-progress-p' is non-nil. * test/lisp/erc/erc-networks-tests.el (erc-networks--rename-server-buffer--no-existing--orphan) (erc-networks--rename-server-buffer--existing--reuse) (erc-networks--rename-server-buffer--local-match) (erc-networks--rename-server-buffer--local-nomatch): Use helper to initialize markers. * test/lisp/erc/erc-stamp-tests.el (erc-stamp--dedupe-date-stamps): New test. (Bug#70928)
2024-05-08 19:03:58 -07:00
(ert-deftest erc-stamp--dedupe-date-stamps-from-target-buffer ()
(unless (>= emacs-major-version 29)
(ert-skip "Requires hz-ticks lisp time format"))
(let ((erc-modules erc-modules)
(erc-stamp--tz t))
(erc-tests-common-make-server-buf)
(erc-stamp-mode +1)
;; Create two buffers with an overlapping date stamp.
(with-current-buffer (erc--open-target "#chan@old")
(let ((erc-stamp--current-time '(1690761600001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-07-31T00:00:00.001Z"))
(let ((erc-stamp--current-time '(1690761601001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "0.0"))
(let ((erc-stamp--current-time '(1690848000001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-08-01T00:00:00.001Z"))
(let ((erc-stamp--current-time '(1690848001001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "1.0"))
(let ((erc-stamp--current-time '(1690848060001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "1.1"))
(let ((erc-stamp--current-time '(1690934400001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-08-02T00:00:00.001Z"))
(let ((erc-stamp--current-time '(1690934401001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "2.0"))
(let ((erc-stamp--current-time '(1690956000001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "2.6")))
(with-current-buffer (erc--open-target "#chan@new")
(let ((erc-stamp--current-time '(1690956001001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-08-02T06:00:01.001Z"))
(let ((erc-stamp--current-time '(1690963200001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "2.8"))
(let ((erc-stamp--current-time '(1691020800001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-08-03T00:00:00.001Z"))
(let ((erc-stamp--current-time '(1691020801001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "3.0"))
(let ((erc-stamp--current-time '(1691053200001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "3.9"))
(let ((erc-stamp--current-time '(1691107200001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer)
"2023-08-04T00:00:00.001Z"))
(let ((erc-stamp--current-time '(1691107201001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "4.0"))
(let ((erc-stamp--current-time '(1691110800001 . 1000)))
(erc-tests-common-display-message nil 'notice (current-buffer) "4.1")))
(erc-stamp--dedupe-date-stamps-from-target-buffer
#'erc-networks--transplant-buffer-content
(get-buffer "#chan@old")
(get-buffer "#chan@new"))
;; Ensure the "model", `erc-stamp--date-stamps', matches reality
;; in the buffer's contents.
(with-current-buffer "#chan@new"
(let ((stamps erc-stamp--date-stamps))
(goto-char 3)
(should (looking-at (rx "\n[Mon Jul 31 2023]")))
(should (= (erc--get-inserted-msg-beg (point))
(erc-stamp--date-marker (pop stamps))))
(goto-char (1+ (match-end 0)))
(should (looking-at (rx "*** 2023-07-31T00:00:00.001Z")))
(forward-line 1)
(should (looking-at (rx "*** 0.0")))
(forward-line 1)
(should (looking-at (rx "\n[Tue Aug 1 2023]")))
(should (= (erc--get-inserted-msg-beg (point))
(erc-stamp--date-marker (pop stamps))))
(goto-char (1+ (match-end 0)))
(should (looking-at (rx "*** 2023-08-01T00:00:00.001Z")))
(forward-line 1)
(should (looking-at (rx "*** 1.0")))
(forward-line 1)
(should (looking-at (rx "*** 1.1")))
(forward-line 1)
(should (looking-at (rx "\n[Wed Aug 2 2023]")))
(should (= (erc--get-inserted-msg-beg (point))
(erc-stamp--date-marker (pop stamps))))
(goto-char (1+ (match-end 0)))
(should (looking-at (rx "*** 2023-08-02T00:00:00.001Z")))
(forward-line 1)
(should (looking-at (rx "*** 2.0")))
(forward-line 1)
(should (looking-at (rx "*** 2.6")))
(forward-line 1)
(should (looking-at
(rx "*** Grafting buffer `#chan@new' onto `#chan@old'")))
(forward-line 1)
(should (looking-at (rx "*** 2023-08-02T06:00:01.001Z")))
(forward-line 1)
(should (looking-at (rx "*** 2.8")))
(forward-line 1)
(should (looking-at (rx "\n[Thu Aug 3 2023]")))
(should (= (erc--get-inserted-msg-beg (point))
(erc-stamp--date-marker (pop stamps))))
(goto-char (1+ (match-end 0)))
(should (looking-at (rx "*** 2023-08-03T00:00:00.001Z")))
(forward-line 3) ; ...
(should (looking-at (rx "\n[Fri Aug 4 2023]")))
(should (= (erc--get-inserted-msg-beg (point))
(erc-stamp--date-marker (pop stamps))))
(should-not stamps))))
(when noninteractive
(erc-tests-common-kill-buffers)))
;;; erc-stamp-tests.el ends here