aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPhilipp Stephani2017-06-01 00:09:43 +0200
committerPhilipp Stephani2017-06-02 00:22:13 +0200
commit0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab (patch)
tree279fbd070724c1d04945b69db32eb69957274e72 /test/src
parent404273aeacba39833ae3a38ce6764cc7a636e9d9 (diff)
downloademacs-0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab.tar.gz
emacs-0dd1bbb0bb228acab21b8e16f2f2a0b5a17b19ab.zip
Implement field numbers in format strings
A field number explicitly specifies the argument to be formatted. This is especially important for potential localization work, since grammars of various languages dictate different word orders. * src/editfns.c (Fformat): Update documentation. (styled_format): Implement field numbers. * doc/lispref/strings.texi (Formatting Strings): Document field numbers. * lisp/emacs-lisp/bytecomp.el (byte-compile-format-warn): Adapt. * test/src/editfns-tests.el (format-with-field): New unit test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/editfns-tests.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 8019eb03838..f76c6c9fd36 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -177,4 +177,22 @@
177 (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" nil 177 (format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" nil
178 (concat (make-string 2048 ?X) "0"))))) 178 (concat (make-string 2048 ?X) "0")))))
179 179
180(ert-deftest format-with-field ()
181 (should (equal (format "First argument %2$s, then %s, then %1$s" 1 2 3)
182 "First argument 2, then 3, then 1"))
183 (should (equal (format "a %2$s %d %1$d %2$S %d %d b" 11 "22" 33 44)
184 "a 22 33 11 \"22\" 33 44 b"))
185 (should (equal (format "a %08$s %s b" 1 2 3 4 5 6 7 8 9) "a 8 9 b"))
186 (should (equal (should-error (format "a %999999$s b" 11))
187 '(error "Not enough arguments for format string")))
188 (should (equal (should-error (format "a %$s b" 11))
189 ;; FIXME: there shouldn't be two % in the error
190 ;; string!
191 '(error "Invalid format operation %%$")))
192 (should (equal (should-error (format "a %0$s b" 11))
193 '(error "Invalid field number `0'")))
194 (should (equal
195 (should-error (format "a %1$% %s b" 11))
196 '(error "Field number specified together with `%' conversion"))))
197
180;;; editfns-tests.el ends here 198;;; editfns-tests.el ends here