aboutsummaryrefslogtreecommitdiff
path: root/tests/testutil-gloss.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-28 14:21:18 -0500
committerCraig Jennings <c@cjennings.net>2026-04-28 14:21:18 -0500
commit4cd1e8e63d885d8de2728dc76d4f35f0eb597037 (patch)
treeb427f0516c3fa3d5d9767ad80f36108bcd3a3d9a /tests/testutil-gloss.el
parent71ccfdd0e6216356ec6cac90bc627fe02dbfdeb1 (diff)
downloadgloss-4cd1e8e63d885d8de2728dc76d4f35f0eb597037.tar.gz
gloss-4cd1e8e63d885d8de2728dc76d4f35f0eb597037.zip
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.
Diffstat (limited to 'tests/testutil-gloss.el')
-rw-r--r--tests/testutil-gloss.el62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/testutil-gloss.el b/tests/testutil-gloss.el
new file mode 100644
index 0000000..b70b0ea
--- /dev/null
+++ b/tests/testutil-gloss.el
@@ -0,0 +1,62 @@
+;;; testutil-gloss.el --- Shared test fixtures for gloss -*- lexical-binding: t -*-
+
+;; SPDX-License-Identifier: GPL-3.0-or-later
+
+;;; Commentary:
+
+;; Fixtures used across gloss test files. Provides:
+;; - `gloss-test--with-temp-glossary' macro (binds `gloss-file', cleans up).
+;; - `gloss-test--sample-content' two-entry org content.
+;; - `gloss-test--make-temp-glossary-file' for cases that need direct paths.
+
+;;; Code:
+
+(require 'gloss-core)
+
+(defconst gloss-test--sample-content
+ "#+TITLE: Glossary
+#+STARTUP: showall
+
+* anaphora
+:PROPERTIES:
+:SOURCE: wiktionary
+:ADDED: 2026-04-28
+:END:
+Reference to something earlier in the discourse.
+
+* SBIR
+:PROPERTIES:
+:SOURCE: wiktionary
+:ADDED: 2026-04-27
+:END:
+Initialism of Small Business Innovation Research.
+"
+ "Two-entry sample content for tests that need a populated glossary.")
+
+(defun gloss-test--make-temp-glossary-file (&optional initial-content)
+ "Create a temp file with INITIAL-CONTENT (or empty) and return its path.
+The caller is responsible for cleanup."
+ (let ((path (make-temp-file "gloss-test-" nil ".org")))
+ (when initial-content
+ (with-temp-file path (insert initial-content)))
+ path))
+
+(defmacro gloss-test--with-temp-glossary (initial-content &rest body)
+ "Bind `gloss-file' to a fresh temp file containing INITIAL-CONTENT.
+Reset the in-memory cache before BODY and after. Clean up file and any
+visiting buffer."
+ (declare (indent 1) (debug t))
+ `(let ((gloss-file (gloss-test--make-temp-glossary-file ,initial-content)))
+ (unwind-protect
+ (progn
+ (gloss-core--cache-reset)
+ ,@body)
+ (gloss-core--cache-reset)
+ (when-let ((buf (find-buffer-visiting gloss-file)))
+ (with-current-buffer buf (set-buffer-modified-p nil))
+ (kill-buffer buf))
+ (when (file-exists-p gloss-file)
+ (delete-file gloss-file)))))
+
+(provide 'testutil-gloss)
+;;; testutil-gloss.el ends here