2019-07-11 16:37:55 +00:00
|
|
|
;;; format-spec-tests.el --- tests for format-spec.el -*- lexical-binding: t -*-
|
|
|
|
|
2021-01-01 09:13:56 +00:00
|
|
|
;; Copyright (C) 2019-2021 Free Software Foundation, Inc.
|
2019-07-11 16:37:55 +00:00
|
|
|
|
|
|
|
;; 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/>.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'ert)
|
|
|
|
(require 'format-spec)
|
|
|
|
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
(ert-deftest format-spec-make ()
|
|
|
|
"Test `format-spec-make'."
|
|
|
|
(should-not (format-spec-make))
|
|
|
|
(should-error (format-spec-make ?b))
|
|
|
|
(should (equal (format-spec-make ?b "b") '((?b . "b"))))
|
|
|
|
(should-error (format-spec-make ?b "b" ?a))
|
|
|
|
(should (equal (format-spec-make ?b "b" ?a 'a)
|
|
|
|
'((?b . "b")
|
|
|
|
(?a . a)))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-parse-flags ()
|
|
|
|
"Test `format-spec--parse-flags'."
|
|
|
|
(should-not (format-spec--parse-flags nil))
|
|
|
|
(should-not (format-spec--parse-flags ""))
|
|
|
|
(should (equal (format-spec--parse-flags "-") '(:pad-right)))
|
|
|
|
(should (equal (format-spec--parse-flags " 0") '(:pad-zero)))
|
|
|
|
(should (equal (format-spec--parse-flags " -x0y< >^_z ")
|
|
|
|
'(:pad-right :pad-zero :chop-left :chop-right
|
|
|
|
:upcase :downcase))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-do-flags ()
|
|
|
|
"Test `format-spec--do-flags'."
|
|
|
|
(should (equal (format-spec--do-flags "" () nil nil) ""))
|
|
|
|
(dolist (flag '(:pad-zero :pad-right :upcase :downcase
|
|
|
|
:chop-left :chop-right))
|
|
|
|
(should (equal (format-spec--do-flags "" (list flag) nil nil) "")))
|
|
|
|
(should (equal (format-spec--do-flags "FOOBAR" '(:downcase :chop-right) 5 2)
|
|
|
|
" fo"))
|
|
|
|
(should (equal (format-spec--do-flags
|
|
|
|
"foobar" '(:pad-zero :pad-right :upcase :chop-left) 5 2)
|
|
|
|
"AR000")))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-do-flags-truncate ()
|
|
|
|
"Test `format-spec--do-flags' truncation."
|
|
|
|
(let (flags)
|
|
|
|
(should (equal (format-spec--do-flags "" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags nil 1) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 1) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 2) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags nil 1) "a")))
|
|
|
|
(let ((flags '(:chop-left)))
|
|
|
|
(should (equal (format-spec--do-flags "" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags nil 1) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 1) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil 2) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags nil 0) ""))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags nil 1) "d"))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-do-flags-pad ()
|
|
|
|
"Test `format-spec--do-flags' padding."
|
|
|
|
(let (flags)
|
|
|
|
(should (equal (format-spec--do-flags "" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 1 nil) " "))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 2 nil) " a")))
|
|
|
|
(let ((flags '(:pad-zero)))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 1 nil) "0"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 2 nil) "0a")))
|
|
|
|
(let ((flags '(:pad-right)))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 1 nil) " "))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 2 nil) "a ")))
|
|
|
|
(let ((flags '(:pad-right :pad-zero)))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "" flags 1 nil) "0"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 2 nil) "a0"))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-do-flags-chop ()
|
|
|
|
"Test `format-spec--do-flags' chopping."
|
|
|
|
(let ((flags '(:chop-left)))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags 1 nil) "d")))
|
|
|
|
(let ((flags '(:chop-right)))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags 1 nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags 0 nil) ""))
|
|
|
|
(should (equal (format-spec--do-flags "asd" flags 1 nil) "a"))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec-do-flags-case ()
|
|
|
|
"Test `format-spec--do-flags' case fiddling."
|
|
|
|
(dolist (flag '(:pad-zero :pad-right :chop-left :chop-right))
|
|
|
|
(let ((flags (list flag)))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "A" flags nil nil) "A")))
|
|
|
|
(let ((flags (list flag :downcase)))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil nil) "a"))
|
|
|
|
(should (equal (format-spec--do-flags "A" flags nil nil) "a")))
|
|
|
|
(let ((flags (list flag :upcase)))
|
|
|
|
(should (equal (format-spec--do-flags "a" flags nil nil) "A"))
|
|
|
|
(should (equal (format-spec--do-flags "A" flags nil nil) "A")))))
|
|
|
|
|
|
|
|
(ert-deftest format-spec ()
|
|
|
|
(should (equal (format-spec "" ()) ""))
|
|
|
|
(should (equal (format-spec "a" ()) "a"))
|
|
|
|
(should (equal (format-spec "b" '((?b . "bar"))) "b"))
|
|
|
|
(should (equal (format-spec "%%%b%%b%b%%" '((?b . "bar"))) "%bar%bbar%"))
|
2019-07-11 16:44:30 +00:00
|
|
|
(should (equal (format-spec "foo %b zot" `((?b . "bar")))
|
2019-07-11 16:37:55 +00:00
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal (format-spec "foo %-10b zot" '((?b . "bar")))
|
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal (format-spec "foo %10b zot" '((?b . "bar")))
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal-including-properties
|
|
|
|
(format-spec (propertize "a" 'a 'b) '((?a . "foo")))
|
|
|
|
#("a" 0 1 (a b))))
|
|
|
|
(let ((fmt (concat (propertize "%a" 'a 'b)
|
|
|
|
(propertize "%%" 'c 'd)
|
|
|
|
"%b"
|
|
|
|
(propertize "%b" 'e 'f))))
|
|
|
|
(should (equal-including-properties
|
|
|
|
(format-spec fmt '((?b . "asd") (?a . "fgh")))
|
|
|
|
#("fgh%asdasd" 0 3 (a b) 3 4 (c d) 7 10 (e f))))))
|
2019-07-11 16:37:55 +00:00
|
|
|
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
(ert-deftest format-spec-unknown ()
|
2019-07-11 18:01:57 +00:00
|
|
|
(should-error (format-spec "foo %b %z zot" '((?b . "bar"))))
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
(should-error (format-spec "foo %b %%%z zot" '((?b . "bar"))))
|
2019-07-11 16:44:30 +00:00
|
|
|
(should (equal (format-spec "foo %b %z zot" '((?b . "bar")) t)
|
|
|
|
"foo bar %z zot"))
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
(should (equal (format-spec "foo %4b %%%4z %%4 zot" '((?b . "bar")) t)
|
|
|
|
"foo bar %%%4z %%4 zot"))
|
|
|
|
(should (equal (format-spec "foo %4b %%%4z %%4 zot" '((?b . "bar")) 'ignore)
|
|
|
|
"foo bar %%4z %4 zot"))
|
|
|
|
(should (equal (format-spec "foo %4b %%%4z %%4 zot" '((?b . "bar")) 'delete)
|
|
|
|
"foo bar % %4 zot")))
|
2019-07-11 16:44:30 +00:00
|
|
|
|
Fix and extend format-spec (bug#41758)
* lisp/format-spec.el: Use lexical-binding. Remove dependence on
subr-x.el.
(format-spec-make): Clarify docstring.
(format-spec--parse-modifiers): Rename to...
(format-spec--parse-flags): ...this and simplify. In particular,
don't bother parsing :space-pad which is redundant and unused.
(format-spec--pad): Remove, replacing with...
(format-spec--do-flags): ...this new helper function which performs
more of format-spec's supported text manipulation.
(format-spec): Autoload. Allow optional argument to take on special
values 'ignore' and 'delete' for more control over what happens when
a replacement for a format specification isn't provided. Bring back
proper support for a precision modifier similar to that of 'format'.
* lisp/battery.el (battery-format): Rewrite in terms of format-spec.
(battery-echo-area-format, battery-mode-line-format): Mention
support of format-spec syntax in docstrings.
* doc/lispref/strings.texi (Custom Format Strings):
* etc/NEWS: Document and announce these changes.
* lisp/dired-aux.el (dired-do-compress-to):
* lisp/erc/erc-match.el (erc-log-matches):
* lisp/erc/erc.el (erc-update-mode-line-buffer):
* lisp/gnus/gnus-sieve.el (gnus-sieve-update):
* lisp/gnus/gssapi.el (open-gssapi-stream):
* lisp/gnus/mail-source.el (mail-source-fetch-file)
(mail-source-fetch-directory, mail-source-fetch-pop)
(mail-source-fetch-imap):
* lisp/gnus/message.el (message-insert-formatted-citation-line):
* lisp/image-dired.el:
* lisp/net/eww.el:
* lisp/net/imap.el (imap-kerberos4-open, imap-gssapi-open)
(imap-shell-open):
* lisp/net/network-stream.el (network-stream-open-shell):
* lisp/obsolete/tls.el (open-tls-stream):
* lisp/textmodes/tex-mode.el:
Remove extraneous loads and autoloads of format-spec now that it is
autoloaded and simplify its uses where possible.
* test/lisp/battery-tests.el (battery-format): Test new format-spec
support.
* test/lisp/format-spec-tests.el (test-format-spec): Rename to...
(format-spec) ...this, extending test cases.
(test-format-unknown): Rename to...
(format-spec-unknown): ...this, extending test cases.
(test-format-modifiers): Rename to...
(format-spec-flags): ...this.
(format-spec-make, format-spec-parse-flags, format-spec-do-flags)
(format-spec-do-flags-truncate, format-spec-do-flags-pad)
(format-spec-do-flags-chop, format-spec-do-flags-case): New tests.
2020-05-29 18:56:14 +00:00
|
|
|
(ert-deftest format-spec-flags ()
|
2019-07-13 01:50:43 +00:00
|
|
|
(should (equal (format-spec "foo %10b zot" '((?b . "bar")))
|
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal (format-spec "foo % 10b zot" '((?b . "bar")))
|
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal (format-spec "foo %-010b zot" '((?b . "bar")))
|
|
|
|
"foo bar0000000 zot"))
|
|
|
|
(should (equal (format-spec "foo %0-10b zot" '((?b . "bar")))
|
|
|
|
"foo bar0000000 zot"))
|
|
|
|
(should (equal (format-spec "foo %^10b zot" '((?b . "bar")))
|
|
|
|
"foo BAR zot"))
|
|
|
|
(should (equal (format-spec "foo %_10b zot" '((?b . "BAR")))
|
|
|
|
"foo bar zot"))
|
|
|
|
(should (equal (format-spec "foo %<4b zot" '((?b . "longbar")))
|
|
|
|
"foo gbar zot"))
|
|
|
|
(should (equal (format-spec "foo %>4b zot" '((?b . "longbar")))
|
|
|
|
"foo long zot")))
|
|
|
|
|
2020-12-29 02:04:51 +00:00
|
|
|
(ert-deftest format-spec-split ()
|
|
|
|
(should (equal (format-spec "foo %b bar" '((?b . "zot")) nil t)
|
|
|
|
'("foo " "zot" " bar")))
|
|
|
|
(should (equal (format-spec "%b bar" '((?b . "zot")) nil t)
|
|
|
|
'("zot" " bar")))
|
|
|
|
(should (equal (format-spec "%b" '((?b . "zot")) nil t)
|
|
|
|
'("zot")))
|
|
|
|
(should (equal (format-spec "foo %b" '((?b . "zot")) nil t)
|
|
|
|
'("foo " "zot"))))
|
|
|
|
|
2019-07-11 16:37:55 +00:00
|
|
|
;;; format-spec-tests.el ends here
|