blob: bb7e4ee7d8d8a09f9c6379d564683bb7ba3b2f28 (
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-gloss--add-finish-internal.el --- Tests for gloss--add-finish-internal -*- lexical-binding: t -*-
;; SPDX-License-Identifier: GPL-3.0-or-later
;;; Commentary:
;; Tests for the pure save-side helper `gloss--add-finish-internal'.
;; The interactive temp-buffer UI is exercised separately at the smoke
;; level; this file covers the term/body validation and the persistence
;; side effect via a real temp glossary.
;;; Code:
(require 'ert)
(require 'cl-lib)
(require 'gloss)
(require 'testutil-gloss)
(ert-deftest test-gloss-add-finish-internal-saves-with-manual-source ()
"Normal: a fresh term + body is saved with source `manual'.
Display is the caller's responsibility, not this function's."
(gloss-test--with-missing-glossary
(let ((saved (gloss--add-finish-internal "newterm" "A new definition.")))
(should saved)
(should (equal (plist-get saved :body) "A new definition."))
(should (eq (plist-get saved :source) 'manual))
(should (equal (gloss-core-lookup "newterm") saved)))))
(ert-deftest test-gloss-add-finish-internal-empty-term-raises ()
"Error: empty TERM raises `user-error'."
(gloss-test--with-missing-glossary
(should-error (gloss--add-finish-internal "" "Body.")
:type 'user-error)
(should-error (gloss--add-finish-internal " " "Body.")
:type 'user-error)))
(ert-deftest test-gloss-add-finish-internal-empty-body-raises ()
"Error: empty BODY raises `user-error'."
(gloss-test--with-missing-glossary
(should-error (gloss--add-finish-internal "term" "")
:type 'user-error)
(should-error (gloss--add-finish-internal "term" " \n ")
:type 'user-error)))
(ert-deftest test-gloss-add-finish-internal-trims-body-whitespace ()
"Boundary: leading/trailing whitespace in BODY is trimmed before save."
(gloss-test--with-missing-glossary
(gloss--add-finish-internal "term" " Body content.\n\n")
(let ((saved (gloss-core-lookup "term")))
(should (equal (plist-get saved :body) "Body content.")))))
(provide 'test-gloss--add-finish-internal)
;;; test-gloss--add-finish-internal.el ends here
|