summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMattias Engdegård <mattiase@acm.org>2022-07-11 10:34:40 +0200
committerMattias Engdegård <mattiase@acm.org>2022-07-11 10:38:49 +0200
commit69b68099ecfb053ac77e0a954ab7467c440321ff (patch)
tree57f810ec7d6addf847ca4b1c70ff5d0cf5d02e21 /test
parent96846877930f580e122e9af85b4653918c542f89 (diff)
downloademacs-69b68099ecfb053ac77e0a954ab7467c440321ff.tar.gz
Simplify and speed up string-to-multibyte
* src/character.h (str_to_multibyte): * src/character.c (str_to_multibyte): Change signature and simplify; the conversion is no longer done in-place. * src/fns.c (string_to_multibyte): Drop temporary buffer and memcpy; adapt to new str_to_multibyte signature. * src/print.c (print_string): Drop memcpy; adapt call to str_to_multibyte. * test/src/fns-tests.el (fns--string-to-unibyte): Rename to... (fns--string-to-unibyte-multibyte): ... this and strengthen, so that the test covers string-to-multibyte reasonably well.
Diffstat (limited to 'test')
-rw-r--r--test/src/fns-tests.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 0119e31df11..20074ca0d21 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1344,18 +1344,24 @@
(should (equal (plist-member plist (copy-sequence "a") #'equal)
'("a" "c")))))
-(ert-deftest fns--string-to-unibyte ()
- (dolist (str '("" "a" "abc" "a\x00\x7fz" "a\xaa\xbbz ""\x80\xdd\xff"))
+(ert-deftest fns--string-to-unibyte-multibyte ()
+ (dolist (str (list "" "a" "abc" "a\x00\x7fz" "a\xaa\xbbz" "\x80\xdd\xff"
+ (apply #'unibyte-string (number-sequence 0 255))))
(ert-info ((prin1-to-string str) :prefix "str: ")
(should-not (multibyte-string-p str))
(let* ((u (string-to-unibyte str)) ; should be identity
(m (string-to-multibyte u)) ; lossless conversion
- (uu (string-to-unibyte m))) ; also lossless
+ (mm (string-to-multibyte m)) ; should be identity
+ (uu (string-to-unibyte m)) ; also lossless
+ (ml (mapcar (lambda (c) (if (<= c #x7f) c (+ c #x3fff00))) u)))
(should-not (multibyte-string-p u))
(should (multibyte-string-p m))
+ (should (multibyte-string-p mm))
(should-not (multibyte-string-p uu))
(should (equal str u))
- (should (equal str uu)))))
+ (should (equal m mm))
+ (should (equal str uu))
+ (should (equal (append m nil) ml)))))
(should-error (string-to-unibyte "å"))
(should-error (string-to-unibyte "ABC∀BC")))