From 4cd1e8e63d885d8de2728dc76d4f35f0eb597037 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Tue, 28 Apr 2026 14:21:18 -0500 Subject: test: add gloss-core test suite (red phase) The commit lands eight per-function test files and a shared testutil. 32 tests across Normal/Boundary/Error categories cover the public API (lookup, save, list, find-buffer-position) and the internals that need observable behavior tests (mtime invalidation, corrupt-file resilience, alphabetical insert, first-call file creation). All 32 fail with void-function on the gloss-core symbols. That is the intended red-phase signal. The next commit lands the implementation that turns them green. testutil-gloss provides a with-temp-glossary macro. It binds gloss-file to a temp file, resets the cache before and after, and cleans up the visiting buffer. --- tests/test-gloss-core--find-buffer-position.el | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/test-gloss-core--find-buffer-position.el (limited to 'tests/test-gloss-core--find-buffer-position.el') diff --git a/tests/test-gloss-core--find-buffer-position.el b/tests/test-gloss-core--find-buffer-position.el new file mode 100644 index 0000000..1e63309 --- /dev/null +++ b/tests/test-gloss-core--find-buffer-position.el @@ -0,0 +1,49 @@ +;;; test-gloss-core--find-buffer-position.el --- Tests for gloss-core-find-buffer-position -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; Tests for `gloss-core-find-buffer-position' covering N/B/E cases. + +;;; Code: + +(require 'ert) +(require 'gloss-core) +(require 'testutil-gloss) + +(ert-deftest test-gloss-core-find-buffer-position-existing-term-returns-marker () + "Normal: returns a marker pointing at the term's heading." + (gloss-test--with-temp-glossary gloss-test--sample-content + (let ((marker (gloss-core-find-buffer-position "anaphora"))) + (should (markerp marker)) + (with-current-buffer (marker-buffer marker) + (goto-char marker) + (should (looking-at-p "^\\* anaphora")))))) + +(ert-deftest test-gloss-core-find-buffer-position-second-term-returns-marker () + "Normal: marker for second term points at its heading, not the first." + (gloss-test--with-temp-glossary gloss-test--sample-content + (let ((marker (gloss-core-find-buffer-position "SBIR"))) + (should (markerp marker)) + (with-current-buffer (marker-buffer marker) + (goto-char marker) + (should (looking-at-p "^\\* SBIR")))))) + +(ert-deftest test-gloss-core-find-buffer-position-missing-term-returns-nil () + "Boundary: returns nil for a term not in the glossary." + (gloss-test--with-temp-glossary gloss-test--sample-content + (should-not (gloss-core-find-buffer-position "nonexistent")))) + +(ert-deftest test-gloss-core-find-buffer-position-missing-file-returns-nil () + "Error: returns nil when the file does not exist." + (let ((gloss-file (concat temporary-file-directory "gloss-pos-nonexistent-" + (number-to-string (random 100000)) ".org"))) + (unwind-protect + (progn + (gloss-core--cache-reset) + (should-not (gloss-core-find-buffer-position "any"))) + (gloss-core--cache-reset) + (when (file-exists-p gloss-file) (delete-file gloss-file))))) + +(provide 'test-gloss-core--find-buffer-position) +;;; test-gloss-core--find-buffer-position.el ends here -- cgit v1.2.3