aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Kangas2022-09-27 18:16:51 +0200
committerStefan Kangas2022-09-29 15:39:27 +0200
commit5281946fbf6b3cdbec5ce82e0057c71849faf4d2 (patch)
tree8f519625372642a2faaa4a1bf314a07e2e283a6b /test
parent423bdd5f7f273f40f750eac83017074501d52823 (diff)
downloademacs-5281946fbf6b3cdbec5ce82e0057c71849faf4d2.tar.gz
emacs-5281946fbf6b3cdbec5ce82e0057c71849faf4d2.zip
Make format-spec accept function substitutions
* lisp/format-spec.el (format-spec): Accept a function producing the substitution for a character. * doc/lispref/strings.texi (Custom Format Strings): Document the above change. * test/lisp/format-spec-tests.el (format-spec/function): New test. Ref. https://lists.gnu.org/r/emacs-devel/2022-09/msg01875.html
Diffstat (limited to 'test')
-rw-r--r--test/lisp/format-spec-tests.el11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/lisp/format-spec-tests.el b/test/lisp/format-spec-tests.el
index 4a3cc74c334..bd493ae1d71 100644
--- a/test/lisp/format-spec-tests.el
+++ b/test/lisp/format-spec-tests.el
@@ -148,6 +148,17 @@
148 (format-spec fmt '((?b . "asd") (?a . "fgh"))) 148 (format-spec fmt '((?b . "asd") (?a . "fgh")))
149 #("fgh%asdasd" 0 3 (a b) 3 4 (c d) 7 10 (e f)))))) 149 #("fgh%asdasd" 0 3 (a b) 3 4 (c d) 7 10 (e f))))))
150 150
151(ert-deftest format-spec/function ()
152 (let* (called
153 (spec `((?a . "foo")
154 (?f . ,(lambda ()
155 (setq called t)
156 "bar")))))
157 (should (equal (format-spec "%a" spec) "foo"))
158 (should-not called)
159 (should (equal (format-spec "%f" spec) "bar"))
160 (should called)))
161
151(ert-deftest format-spec-unknown () 162(ert-deftest format-spec-unknown ()
152 (should-error (format-spec "foo %b %z zot" '((?b . "bar")))) 163 (should-error (format-spec "foo %b %z zot" '((?b . "bar"))))
153 (should-error (format-spec "foo %b %%%z zot" '((?b . "bar")))) 164 (should-error (format-spec "foo %b %%%z zot" '((?b . "bar"))))