diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-28 14:21:18 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-28 14:21:18 -0500 |
| commit | 4cd1e8e63d885d8de2728dc76d4f35f0eb597037 (patch) | |
| tree | b427f0516c3fa3d5d9767ad80f36108bcd3a3d9a /tests/test-gloss-core--save.el | |
| parent | 71ccfdd0e6216356ec6cac90bc627fe02dbfdeb1 (diff) | |
| download | gloss-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--save.el')
| -rw-r--r-- | tests/test-gloss-core--save.el | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test-gloss-core--save.el b/tests/test-gloss-core--save.el new file mode 100644 index 0000000..c9e77d1 --- /dev/null +++ b/tests/test-gloss-core--save.el @@ -0,0 +1,82 @@ +;;; test-gloss-core--save.el --- Tests for gloss-core-save -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; Tests for `gloss-core-save' covering Normal/Boundary/Error cases. + +;;; Code: + +(require 'ert) +(require 'gloss-core) +(require 'testutil-gloss) + +(ert-deftest test-gloss-core-save-new-term-returns-entry-plist () + "Normal: save new term returns the entry plist with all fields." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (let ((entry (gloss-core-save "anaphora" "Reference to..." 'wiktionary))) + (should entry) + (should (equal (plist-get entry :term) "anaphora")) + (should (equal (plist-get entry :body) "Reference to...")) + (should (eq (plist-get entry :source) 'wiktionary)) + (should (stringp (plist-get entry :added)))))) + +(ert-deftest test-gloss-core-save-then-lookup-roundtrip () + "Normal: save then lookup returns the matching entry." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "anaphora" "Reference to something earlier." 'wiktionary) + (let ((entry (gloss-core-lookup "anaphora"))) + (should entry) + (should (equal (plist-get entry :body) + "Reference to something earlier."))))) + +(ert-deftest test-gloss-core-save-multi-line-body-preserved () + "Boundary: save preserves a multi-line body." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (let ((body "First paragraph.\n\nSecond paragraph.")) + (gloss-core-save "term" body 'manual) + (let ((entry (gloss-core-lookup "term"))) + (should (equal (plist-get entry :body) body)))))) + +(ert-deftest test-gloss-core-save-empty-body-raises-error () + "Error: empty body raises a user-error." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (should-error (gloss-core-save "anaphora" "" 'wiktionary) + :type 'user-error))) + +(ert-deftest test-gloss-core-save-empty-term-raises-error () + "Error: empty term raises a user-error." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (should-error (gloss-core-save "" "Some body" 'wiktionary) + :type 'user-error))) + +(ert-deftest test-gloss-core-save-collision-replace-overwrites () + "Error: collision with action \\='replace overwrites the body and source." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "anaphora" "First definition." 'wiktionary) + (gloss-core-save "anaphora" "Second definition." 'manual 'replace) + (let ((entry (gloss-core-lookup "anaphora"))) + (should (equal (plist-get entry :body) "Second definition.")) + (should (eq (plist-get entry :source) 'manual))))) + +(ert-deftest test-gloss-core-save-collision-append-joins-bodies () + "Error: collision with action \\='append concatenates the bodies." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "anaphora" "First definition." 'wiktionary) + (gloss-core-save "anaphora" "Second definition." 'manual 'append) + (let ((entry (gloss-core-lookup "anaphora"))) + (should (string-match-p "First definition" (plist-get entry :body))) + (should (string-match-p "Second definition" (plist-get entry :body)))))) + +(ert-deftest test-gloss-core-save-collision-cancel-leaves-original () + "Error: collision with action \\='cancel leaves the original entry." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "anaphora" "First definition." 'wiktionary) + (let ((result (gloss-core-save "anaphora" "Second definition." + 'manual 'cancel))) + (should-not result)) + (let ((entry (gloss-core-lookup "anaphora"))) + (should (equal (plist-get entry :body) "First definition."))))) + +(provide 'test-gloss-core--save) +;;; test-gloss-core--save.el ends here |
