aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond2026-02-25 10:18:39 -0500
committerEric S. Raymond2026-02-25 10:24:38 -0500
commitbb403e70aec25677393d4f37d544487a9aebab9e (patch)
tree298f9624a76a2f56bbbde6995588c88993e530c5
parent8992eea7d5f603dbe6ed519482c4e12a7425be6d (diff)
downloademacs-bb403e70aec25677393d4f37d544487a9aebab9e.tar.gz
emacs-bb403e70aec25677393d4f37d544487a9aebab9e.zip
Tests for 7 editor primitives previously not covered.
- byte-to-position - byte-to-string - insert-byte - insert-buffer-substring - insert-before-markers-and-inherit - field-string-and-delete - constrain-to-field
-rw-r--r--test/src/editfns-tests.el83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 9bdd5cf5db6..91dc8750935 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -938,4 +938,87 @@ sufficiently large to avoid truncation."
938 (pos-bol 2) (pos-eol 2)) 938 (pos-bol 2) (pos-eol 2))
939 (should (equal (buffer-string) "toto\nEmacs forever!\n")))) 939 (should (equal (buffer-string) "toto\nEmacs forever!\n"))))
940 940
941;; Additional coverage for editfns primitives used in batch mode.
942
943(ert-deftest editfns-tests--byte-to-position ()
944 (with-temp-buffer
945 (insert "éa")
946 (let* ((b1 (position-bytes 1))
947 (b2 (position-bytes 2)))
948 (should (= b1 1))
949 (should (> b2 b1))
950 (should (= (byte-to-position b1) 1))
951 (should (= (byte-to-position b2) 2))
952 ;; Byte position in the middle of a multibyte character maps back
953 ;; to the character head.
954 (should (= (byte-to-position (1- b2)) 1))
955 (should-not (byte-to-position 0))
956 (should-not (byte-to-position (1+ (position-bytes (point-max))))))))
957
958(ert-deftest editfns-tests--byte-to-string ()
959 (let ((s (byte-to-string 65)))
960 (should (stringp s))
961 (should (not (multibyte-string-p s)))
962 (should (= (length s) 1))
963 (should (= (aref s 0) 65)))
964 (should-error (byte-to-string -1))
965 (should-error (byte-to-string 256)))
966
967(ert-deftest editfns-tests--insert-byte ()
968 (with-temp-buffer
969 (insert-byte ?A 3)
970 (should (equal (buffer-string) "AAA")))
971 (with-temp-buffer
972 (insert-byte 200 1)
973 (should (= (aref (buffer-string) 0) 200)))
974 (should-error (with-temp-buffer (insert-byte 256 1))))
975
976(ert-deftest editfns-tests--insert-buffer-substring ()
977 (with-temp-buffer
978 (let ((source (current-buffer)))
979 (insert "abcDEF")
980 (put-text-property 4 6 'foo t)
981 (with-temp-buffer
982 (insert "X")
983 (insert-buffer-substring source 2 5)
984 (should (equal (buffer-string) "XbcD"))
985 (should-not (get-text-property 2 'foo))
986 (should (get-text-property 4 'foo))))))
987
988(ert-deftest editfns-tests--insert-before-markers-and-inherit ()
989 (with-temp-buffer
990 (insert (propertize "a" 'foo t))
991 (let ((m (point-marker)))
992 (insert-before-markers-and-inherit "b")
993 (should (equal (buffer-string) "ab"))
994 (should (= (marker-position m) (point)))
995 (should (eq (get-text-property 2 'foo) t)))))
996
997(ert-deftest editfns-tests--field-string-and-delete ()
998 (with-temp-buffer
999 (insert "abcDEFghi")
1000 (put-text-property 1 4 'field 'a)
1001 (put-text-property 4 7 'field 'b)
1002 (put-text-property 7 10 'field 'c)
1003 (let ((s (field-string-no-properties 2)))
1004 (should (equal s "abc"))
1005 (should-not (text-properties-at 0 s)))
1006 (should (equal (field-string-no-properties 5) "DEF"))
1007 (delete-field 5)
1008 (should (equal (buffer-string) "abcghi"))
1009 (should (equal (field-string-no-properties 5) "ghi"))))
1010
1011(ert-deftest editfns-tests--constrain-to-field ()
1012 (let ((inhibit-field-text-motion nil))
1013 (with-temp-buffer
1014 (insert "abcDEFghi")
1015 (put-text-property 1 4 'field 'a)
1016 (put-text-property 4 7 'field 'b)
1017 (put-text-property 7 10 'field 'c)
1018 (should (= (constrain-to-field 2 5) 4))
1019 (should (= (constrain-to-field 8 5) 7))
1020 (goto-char 2)
1021 (should (= (constrain-to-field nil 5) 4))
1022 (should (= (point) 4)))))
1023
941;;; editfns-tests.el ends here 1024;;; editfns-tests.el ends here