summaryrefslogtreecommitdiff
path: root/tests/test-join-line-or-region.el
blob: 74625b65f3cf1b89aa44bc4c9c8ae8acda85804e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
;;; test-join-line-or-region.el --- Test cj/join-line-or-region -*- lexical-binding: t; -*-

;;; Commentary:
;; Tests for the cj/join-line-or-region function in custom-functions.el

;;; Code:

(add-to-list 'load-path (concat user-emacs-directory "modules"))
(require 'custom-functions)
(require 'ert)

(defun cj/join-line-or-region (beg end)
  "Apply 'join-line' over the region (identified by BEG and END).
If the region's not active, join line with previous line above."
  (interactive "r")
  ;; when in region
  (if mark-active
	  (message "mark is active")
	  (let ((beg (region-beginning))
			(end (copy-marker (region-end))))
		(goto-char beg)
		;; apply join lines until point => end
		(while (< (point) end)
		  (join-line 1))
		(goto-char end)
		(newline)))
  ;; outside of region; just join line
  (join-line)(newline))


(ert-deftest test-cj/join-line-or-region ()
  (let ((given  "Line1\nLine2\nLine3\n")
		(expected "Line1Line2Line3")
		(beg nil)
		(end nil))
	(with-temp-buffer
	  (insert given)
	  ;; select the whole buffer as region
	  (setq beg (copy-marker (goto-char (point-min))))
	  (setq end (copy-marker (goto-char (point-max))))

	  ;; Call the function being tested
	  (cj/join-line-or-region beg end)

	  ;; Perform assertions to check the expected result
	  (should (equal (buffer-substring-no-properties (point-min)
													 (point-max))
					 expected)))))


(provide 'test-join-line-or-region)
;;; test-join-line-or-region.el ends here.