From d313c37f14511564849c70c564c14ca51bd4ae7c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 30 Apr 2026 01:07:44 -0500 Subject: test: add gloss secondary commands test suite (red phase) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/test-gloss--add-finish-internal.el | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/test-gloss--add-finish-internal.el (limited to 'tests/test-gloss--add-finish-internal.el') 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 -- cgit v1.2.3