diff options
author | Eli Zaretskii <eliz@gnu.org> | 2016-07-19 18:59:41 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2016-07-19 18:59:41 +0300 |
commit | 00b6647651e4276ac5c47aa33e0fec6726469bc7 (patch) | |
tree | 8e03635aac3f32b806b85e1a7bf976741d85cc30 /test | |
parent | 439f3c3e567692b6823923d569a06ac206d1c3be (diff) |
Fix 'transpose-regions' when LEAVE-MARKERS arg is non-nil
* src/insdel.c (adjust_markers_bytepos): New function.
* src/lisp.h (adjust_markers_bytepos): Add prototype.
* src/insdel.c (replace_range, replace_range_2):
* src/editfns.c (Ftranspose_regions): Call
adjust_markers_bytepos. (Bug#5131)
* test/src/editfns-tests.el (transpose-test-reverse-word)
(transpose-test-get-byte-positions): New functions.
(transpose-ascii-regions-test)
(transpose-nonascii-regions-test-1)
(transpose-nonascii-regions-test-2): New tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/src/editfns-tests.el | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 507ceef2f7..2f90d1e749 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -89,3 +89,48 @@ (propertize "23" 'face 'underline) (propertize "45" 'face 'italic))) #("012345 " 0 2 (face bold) 2 4 (face underline) 4 10 (face italic))))) + +;; Tests for bug#5131. +(defun transpose-test-reverse-word (start end) + "Reverse characters in a word by transposing pairs of characters." + (let ((begm (make-marker)) + (endm (make-marker))) + (set-marker begm start) + (set-marker endm end) + (while (> endm begm) + (progn (transpose-regions begm (1+ begm) endm (1+ endm) t) + (set-marker begm (1+ begm)) + (set-marker endm (1- endm)))))) + +(defun transpose-test-get-byte-positions (len) + "Validate character position to byte position translation." + (let ((bytes '())) + (dotimes (pos len) + (setq bytes (add-to-list 'bytes (position-bytes (1+ pos)) t))) + bytes)) + +(ert-deftest transpose-ascii-regions-test () + (with-temp-buffer + (erase-buffer) + (insert "abcd") + (transpose-test-reverse-word 1 4) + (should (string= (buffer-string) "dcba")) + (should (equal (transpose-test-get-byte-positions 5) '(1 2 3 4 5))))) + +(ert-deftest transpose-nonascii-regions-test-1 () + (with-temp-buffer + (erase-buffer) + (insert "÷bcd") + (transpose-test-reverse-word 1 4) + (should (string= (buffer-string) "dcb÷")) + (should (equal (transpose-test-get-byte-positions 5) '(1 2 3 4 6))))) + +(ert-deftest transpose-nonascii-regions-test-2 () + (with-temp-buffer + (erase-buffer) + (insert "÷ab\"äé") + (transpose-test-reverse-word 1 6) + (should (string= (buffer-string) "éä\"ba÷")) + (should (equal (transpose-test-get-byte-positions 7) '(1 3 5 6 7 8 10))))) + +;;; editfns-tests.el ends here |