aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorEli Zaretskii2021-04-14 11:47:55 +0300
committerEli Zaretskii2021-04-14 11:47:55 +0300
commitd1559ede54684513b79025ade2b4677447c7a487 (patch)
tree5bbb4c12e05a3ea4f260d204f3f8e9b854d5a22d /test/src
parent844b8949a71f180d395a237c768b22d91cf91ded (diff)
downloademacs-d1559ede54684513b79025ade2b4677447c7a487.tar.gz
emacs-d1559ede54684513b79025ade2b4677447c7a487.zip
Add two optional arguments to 'string-width'
* src/character.c (Fstring_width, lisp_string_width): Accept two optional arguments FROM and TO, to indicate the substring to be considered. (Fstring_width): Add caveats in the doc string about display features ignored by the function. (Bug#47712) * src/character.h (lisp_string_width): Update prototype. * src/editfns.c (styled_format): Adjust call of lisp_string_width to its changed signature. * test/src/character-tests.el (character-test-string-width): New file with tests for 'string-width'. * doc/lispref/display.texi (Size of Displayed Text): Document caveats of using 'string-width'. * etc/NEWS: Announce the change.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/character-tests.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/src/character-tests.el b/test/src/character-tests.el
new file mode 100644
index 00000000000..10fc4dbf353
--- /dev/null
+++ b/test/src/character-tests.el
@@ -0,0 +1,45 @@
1;;; character-tests.el -- tests for character.c -*- lexical-binding:t -*-
2
3;; Copyright (C) 2021 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23
24(ert-deftest character-test-string-width ()
25 "Test `string-width' with and without compositions."
26 (should (= (string-width "1234") 4))
27 (should (= (string-width "12\t34") (+ 4 tab-width)))
28 (should (= (string-width "áëòç") 4))
29 (should (= (string-width "áëòç") 4))
30 (should (= (string-width "הַרְבֵּה אַהֲבָה") 9))
31 (should (= (string-width "1234" 1 3) 2))
32 (should (= (string-width "1234" nil -1) 3))
33 (should (= (string-width "1234" 2) 2))
34 (should-error (string-width "1234" nil 5))
35 (should-error (string-width "1234" -5))
36 (should (= (string-width "12\t34") (+ 4 tab-width)))
37 (should (= (string-width "1234\t56") (+ 6 tab-width)))
38 (should (= (string-width "áëòç") 4))
39 (should (= (string-width "áëòç" nil 3) 3))
40 (should (= (string-width "áëòç" 1 3) 2))
41 (should (= (string-width "áëòç" nil 2) 1))
42 (should (= (string-width "áëòç" nil 3) 2))
43 (should (= (string-width "áëòç" nil 4) 2))
44 (should (= (string-width "הַרְבֵּה אַהֲבָה") 9))
45 (should (= (string-width "הַרְבֵּה אַהֲבָה" nil 8) 4)))