aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime--truncate-title.el
blob: e888b437f44f2a8087ac5e88a5327660da5ec80f (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
;;; test-chime--truncate-title.el --- Tests for chime--truncate-title -*- lexical-binding: t; -*-

;; Copyright (C) 2024 Craig Jennings

;; Author: Craig Jennings <c@cjennings.net>

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Unit tests for chime--truncate-title function.
;; Tests title truncation with ellipsis based on chime-max-title-length.

;;; Code:

;; Initialize package system for batch mode
(when noninteractive
  (package-initialize))

(require 'ert)
(require 'dash)
(require 'alert)

;; Load chime from parent directory
(load (expand-file-name "../chime.el") nil t)

;;; Setup and Teardown

(defun test-chime--truncate-title-setup ()
  "Setup test environment."
  ;; No special setup needed
  )

(defun test-chime--truncate-title-teardown ()
  "Teardown test environment."
  ;; No special teardown needed
  )

;;; Normal Cases

(ert-deftest test-chime--truncate-title-normal-short-title-unchanged ()
  "Test that short title under max length is unchanged."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 20))
        (should (equal (chime--truncate-title "Short title")
                      "Short title")))
    (test-chime--truncate-title-teardown)))

(ert-deftest test-chime--truncate-title-normal-long-title-truncated-with-ellipsis ()
  "Test that long title is truncated with ... appended."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 15))
        (should (equal (chime--truncate-title "This is a very long title that needs truncation")
                      "This is a ve...")))
    (test-chime--truncate-title-teardown)))

(ert-deftest test-chime--truncate-title-normal-unicode-characters-truncated-correctly ()
  "Test that unicode characters are handled correctly in truncation."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 10))
        (should (equal (chime--truncate-title "Meeting 🎉 with team")
                      "Meeting...")))
    (test-chime--truncate-title-teardown)))

;;; Boundary Cases

(ert-deftest test-chime--truncate-title-boundary-exact-max-length-unchanged ()
  "Test that title exactly at max length is unchanged."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 12))
        (should (equal (chime--truncate-title "Twelve chars")
                      "Twelve chars")))
    (test-chime--truncate-title-teardown)))

(ert-deftest test-chime--truncate-title-boundary-one-char-over-max-truncated ()
  "Test that title one character over max is truncated."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 10))
        (should (equal (chime--truncate-title "Eleven char")
                      "Eleven ...")))
    (test-chime--truncate-title-teardown)))

(ert-deftest test-chime--truncate-title-boundary-empty-string-returns-empty ()
  "Test that empty string returns empty string."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 20))
        (should (equal (chime--truncate-title "")
                      "")))
    (test-chime--truncate-title-teardown)))

;;; Error Cases

(ert-deftest test-chime--truncate-title-error-nil-title-returns-empty ()
  "Test that nil title returns empty string."
  (test-chime--truncate-title-setup)
  (unwind-protect
      (let ((chime-max-title-length 20))
        (should (equal (chime--truncate-title nil)
                      "")))
    (test-chime--truncate-title-teardown)))

(provide 'test-chime--truncate-title)
;;; test-chime--truncate-title.el ends here