summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-14 00:22:26 -0500
committerCraig Jennings <c@cjennings.net>2024-04-14 00:22:26 -0500
commitdc8ec3fa8e996b605e01dc54dd41534ce0558335 (patch)
treedec4c6850b4acff604fd6f080ab5fb70b6e8d6c1 /tests
parent61393683774458a18a99d8548b03e841045b239d (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/test-format-region.el47
-rw-r--r--tests/test-join-line-or-region.el10
2 files changed, 52 insertions, 5 deletions
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.
diff --git a/tests/test-join-line-or-region.el b/tests/test-join-line-or-region.el
index f949a62c..74625b65 100644
--- a/tests/test-join-line-or-region.el
+++ b/tests/test-join-line-or-region.el
@@ -1,12 +1,12 @@
-;;; test-join-line-or-region.el --- Test Join Line/Region -*- lexical-binding: t; -*-
+;;; test-join-line-or-region.el --- Test cj/join-line-or-region -*- lexical-binding: t; -*-
;;; Commentary:
-;; Tests for the join-line-or-region function
+;; Tests for the cj/join-line-or-region function in custom-functions.el
-;;; Code:x
-
-;; (require 'custom-functions)
+;;; Code:
+(add-to-list 'load-path (concat user-emacs-directory "modules"))
+(require 'custom-functions)
(require 'ert)
(defun cj/join-line-or-region (beg end)