diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-30 01:07:44 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-30 01:07:44 -0500 |
| commit | d313c37f14511564849c70c564c14ca51bd4ae7c (patch) | |
| tree | 315a0bf268c937f406e3060f07325dae9378152c /tests/test-gloss--add-finish-internal.el | |
| parent | eefd55510cf6b180a7dcc9be40fde894d9adf3ac (diff) | |
| download | gloss-d313c37f14511564849c70c564c14ca51bd4ae7c.tar.gz gloss-d313c37f14511564849c70c564c14ca51bd4ae7c.zip | |
test: add gloss secondary commands test suite (red phase)
Six test files for the remaining stub commands. All 14 tests fail at
this commit because the implementations are stubs.
`gloss--add-finish-internal' (the pure save side of `gloss-add') gets
N/B/E coverage on validation and the persistence side effect.
`gloss--stats-text' (the pure stats string formatter) covers empty,
populated, and missing-file cases. The interactive commands
(`gloss-edit', `gloss-list-terms', `gloss-reload', `gloss-drill-export')
get smoke tests only — the design treats them as mode-glue with 70%
coverage targets, since prompts and `switch-to-buffer' are framework
behaviour Emacs already tests.
Two error-path tests assert the message contains a specific substring,
not just that `user-error' was raised. The stubs raise `user-error' too,
so a bare `should-error' would pass for the wrong reason. The substring
check anchors red against the real error path.
Diffstat (limited to 'tests/test-gloss--add-finish-internal.el')
| -rw-r--r-- | tests/test-gloss--add-finish-internal.el | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test-gloss--add-finish-internal.el b/tests/test-gloss--add-finish-internal.el new file mode 100644 index 0000000..688d6f2 --- /dev/null +++ b/tests/test-gloss--add-finish-internal.el @@ -0,0 +1,61 @@ +;;; 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-and-shows () + "Normal: a fresh term + body is saved with source `manual' and shown." + (gloss-test--with-missing-glossary + (let (shown) + (cl-letf (((symbol-function 'gloss-display-show-entry) + (lambda (term body) (setq shown (list term body))))) + (gloss--add-finish-internal "newterm" "A new definition.") + (let ((saved (gloss-core-lookup "newterm"))) + (should saved) + (should (equal (plist-get saved :body) "A new definition.")) + (should (eq (plist-get saved :source) 'manual))) + (should (equal shown '("newterm" "A new definition."))))))) + +(ert-deftest test-gloss-add-finish-internal-empty-term-raises () + "Error: empty TERM raises `user-error'." + (gloss-test--with-missing-glossary + (cl-letf (((symbol-function 'gloss-display-show-entry) + (lambda (_ _) nil))) + (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 + (cl-letf (((symbol-function 'gloss-display-show-entry) + (lambda (_ _) nil))) + (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 + (cl-letf (((symbol-function 'gloss-display-show-entry) + (lambda (_ _) nil))) + (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 |
