aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-display--render-entry.el
blob: 5656660d394e59f1d64db7681094172d0f1a42f6 (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
;;; test-gloss-display--render-entry.el --- Tests for gloss-display--render-entry -*- lexical-binding: t -*-

;; SPDX-License-Identifier: GPL-3.0-or-later

;;; Commentary:
;; Tests for the pure helper `gloss-display--render-entry' covering
;; Normal/Boundary/Error cases.  The helper takes a TERM and BODY and
;; returns the formatted string that `gloss-display-show-entry' inserts
;; into the side buffer.

;;; Code:

(require 'ert)
(require 'gloss-display)

(ert-deftest test-gloss-display-render-entry-normal-term-and-body ()
  "Normal: render produces the term, an underline, a blank, and the body."
  (let ((result (gloss-display--render-entry
                 "anaphora"
                 "Reference to something earlier in the discourse.")))
    (should (string-match-p "^anaphora\n" result))
    (should (string-match-p "^=+\n" (substring result (length "anaphora\n"))))
    (should (string-match-p "Reference to something earlier" result))))

(ert-deftest test-gloss-display-render-entry-normal-underline-matches-term-length ()
  "Normal: the underline length matches the term length."
  (let* ((term "abc")
         (result (gloss-display--render-entry term "Body."))
         (lines (split-string result "\n")))
    (should (equal (nth 0 lines) term))
    (should (= (length (nth 1 lines)) (length term)))
    (should (string-match-p "^=+$" (nth 1 lines)))))

(ert-deftest test-gloss-display-render-entry-boundary-multi-line-body ()
  "Boundary: a multi-line body is preserved verbatim."
  (let ((result (gloss-display--render-entry
                 "term"
                 "First paragraph.\n\nSecond paragraph.")))
    (should (string-match-p "First paragraph\\." result))
    (should (string-match-p "Second paragraph\\." result))
    (should (string-match-p "First paragraph\\.\n\nSecond paragraph\\." result))))

(ert-deftest test-gloss-display-render-entry-boundary-empty-body ()
  "Boundary: an empty body still renders the term and underline."
  (let ((result (gloss-display--render-entry "lonely" "")))
    (should (string-match-p "^lonely\n=+\n" result))))

(ert-deftest test-gloss-display-render-entry-boundary-unicode-term ()
  "Boundary: unicode characters in the term are preserved."
  (let* ((term "café")
         (result (gloss-display--render-entry term "A coffeehouse.")))
    (should (string-match-p (regexp-quote term) result))
    (should (string-match-p "A coffeehouse\\." result))))

(ert-deftest test-gloss-display-render-entry-boundary-very-long-term ()
  "Boundary: a long term gets a matching long underline."
  (let* ((term (make-string 60 ?z))
         (result (gloss-display--render-entry term "Body."))
         (lines (split-string result "\n")))
    (should (equal (nth 0 lines) term))
    (should (= (length (nth 1 lines)) 60))))

(provide 'test-gloss-display--render-entry)
;;; test-gloss-display--render-entry.el ends here