aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-core--first-call-creates-file.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/test-gloss-core--first-call-creates-file.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/test-gloss-core--first-call-creates-file.el')
-rw-r--r--tests/test-gloss-core--first-call-creates-file.el56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-gloss-core--first-call-creates-file.el b/tests/test-gloss-core--first-call-creates-file.el
new file mode 100644
index 0000000..e168435
--- /dev/null
+++ b/tests/test-gloss-core--first-call-creates-file.el
@@ -0,0 +1,56 @@
+;;; test-gloss-core--first-call-creates-file.el --- Tests for first-save creates file -*- lexical-binding: t -*-
+
+;; SPDX-License-Identifier: GPL-3.0-or-later
+
+;;; Commentary:
+;; Tests that `gloss-core-save' creates `gloss-file' (and any missing
+;; parent directory) on first call.
+
+;;; Code:
+
+(require 'ert)
+(require 'gloss-core)
+(require 'testutil-gloss)
+
+(ert-deftest test-gloss-core-save-creates-file-when-missing ()
+ "Normal: first save creates the file with a TITLE header."
+ (let ((gloss-file (concat temporary-file-directory "gloss-create-"
+ (number-to-string (random 100000)) ".org")))
+ (unwind-protect
+ (progn
+ (gloss-core--cache-reset)
+ (should-not (file-exists-p gloss-file))
+ (gloss-core-save "anaphora" "Reference earlier." 'manual)
+ (should (file-exists-p gloss-file))
+ (let ((content (with-temp-buffer
+ (insert-file-contents gloss-file)
+ (buffer-string))))
+ (should (string-match-p "#\\+TITLE:" content))
+ (should (string-match-p "^\\* anaphora" content))))
+ (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)))))
+
+(ert-deftest test-gloss-core-save-creates-parent-directory ()
+ "Boundary: first save creates missing parent directory."
+ (let* ((parent (concat temporary-file-directory "gloss-newdir-"
+ (number-to-string (random 100000))))
+ (gloss-file (concat parent "/gloss.org")))
+ (unwind-protect
+ (progn
+ (gloss-core--cache-reset)
+ (should-not (file-exists-p parent))
+ (gloss-core-save "anaphora" "Reference earlier." 'manual)
+ (should (file-exists-p parent))
+ (should (file-exists-p gloss-file)))
+ (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))
+ (when (file-directory-p parent) (delete-directory parent)))))
+
+(provide 'test-gloss-core--first-call-creates-file)
+;;; test-gloss-core--first-call-creates-file.el ends here