From dc8ec3fa8e996b605e01dc54dd41534ce0558335 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 14 Apr 2024 00:22:26 -0500 Subject: tests and more bug fixing - make org todo starting priority the lowest ("D") - better default prompt for gptel - added function to browse arch-wiki-docs - added tests for join line or region - added tests for format region or buffer - added region arguments to cj/join-paragraph - updated tasks --- tests/test-format-region.el | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/test-format-region.el (limited to 'tests/test-format-region.el') diff --git a/tests/test-format-region.el b/tests/test-format-region.el new file mode 100644 index 00000000..b1d1532c --- /dev/null +++ b/tests/test-format-region.el @@ -0,0 +1,47 @@ +;;; test-format-region.el --- tests for cj/format-region-or-buffer -*- lexical-binding: t; -*- + +;;; Commentary: +;; Some basic tests for the custom function cj/format-region-or-buffer in custom-functions.el + +;;; Code: + +(add-to-list 'load-path (concat user-emacs-directory "modules")) +(require 'custom-functions) + +;; ----------------------------- Utility Functions ----------------------------- + +(defun buffer-string-no-properties () + "Return the contents of the current buffer without any text properties." + (buffer-substring-no-properties (point-min) (point-max))) + +;; ----------------------------------- Tests ----------------------------------- + +(ert-deftest cj/format-region-or-buffer-test/region () + "Test cj/format-region-or-buffer on a selected region." + (with-temp-buffer + (insert " line with leading spaces and a \n tab\there") + (goto-char (point-min)) + (push-mark (point) t t) + (goto-char (point-max)) + (cj/format-region-or-buffer) + ;; expected: trailing whitespace and leading spaces are removed, tabs are replaced by spaces + (should (string= (buffer-string-no-properties) "line with leading spaces and a\ntab here")))) + +(ert-deftest cj/format-region-or-buffer-test/whole-buffer () + "Test cj/format-region-or-buffer on an entire buffer." + (with-temp-buffer + (insert " \n\t\n line with leading spaces and a \n tab\there") + ;; expected: trailing and leading whitespace of buffer and lines are removed, tabs are replaced by spaces + (cj/format-region-or-buffer) + (should (string= (buffer-string-no-properties) "\nline with leading spaces and a\ntab here")))) + +(ert-deftest cj/format-region-or-buffer-test/extreme-buffer-size () + "Tests cj/format-region-or-buffer on an very large buffer." + (with-temp-buffer + (insert (make-string most-positive-fixnum ?\s)) + (cj/format-region-or-buffer) + ;; expected: even large buffers should not cause an error + (should (string= (buffer-string-no-properties) "")))) + +(provide 'test-format-region) +;;; test-format-region.el ends here. -- cgit v1.2.3