blob: d694e4079f14feb4c885897c18c7cf86869e0b87 (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
;;; test-custom-functions-join-line-or-region.el --- Test cj/join-line-or-region -*- lexical-binding: t; -*-
;; Author: Craig Jennings <c@cjennings.net>
;;
;;; 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 'ert)
(require 'custom-functions)
(ert-deftest test-cj/join-line-or-region-normal-case ()
(let* ((given "Line1\nLine2\nLine3\n")
(expected "Line1 Line2 Line3\n")) ; Note: join-line adds newline.
(with-temp-buffer
(insert given)
;; Properly set and activate the region
(push-mark (point-min) t t) ; Set mark, no message, activate
(goto-char (point-max)) ; This creates active region from min to max
;; Call the function being tested
(cj/join-line-or-region)
;; Perform assertions to check the expected result
(should (equal (buffer-substring-no-properties (point-min) (point-max))
expected)))))
(ert-deftest test-cj/join-line-or-region-multiple-spaces ()
(let* ((given "Line1\n\n\n\n\nLine2\nLine3\n")
(expected "Line1 Line2 Line3\n")) ; Note: join-line adds newline.
(with-temp-buffer
(insert given)
;; Properly set and activate the region
(push-mark (point-min) t t)
(goto-char (point-max))
;; Call the function being tested
(cj/join-line-or-region)
;; Perform assertions to check the expected result
(should (equal (buffer-substring-no-properties (point-min) (point-max))
expected)))))
(ert-deftest test-cj/join-line-or-region-single-line ()
(let* ((given "Line1\n")
(expected "Line1\n")) ; Note: join-line adds newline.
(with-temp-buffer
(insert given)
;; push the mark mid-way on the line
(goto-char (/ (point-max) 2))
;; Call the function being tested
(cj/join-line-or-region)
;; Perform assertions to check the expected result
(should (equal (buffer-substring-no-properties (point-min) (point-max))
expected)))))
(ert-deftest test-cj/join-line-or-region-nothing ()
(let* ((given "")
(expected "\n")) ; Note: join-line adds newline.
(with-temp-buffer
(insert given)
;; Properly set and activate the region
(push-mark (point-min) t t)
(goto-char (point-max))
;; Call the function being tested
(cj/join-line-or-region)
;; Perform assertions to check the expected result
(should (equal (buffer-substring-no-properties (point-min) (point-max))
expected)))))
(provide 'test-custom-functions.el-join-line-or-region)
;;; test-custom-functions-join-line-or-region.el ends here.
|