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--lookup.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--lookup.el')
| -rw-r--r-- | tests/test-gloss-core--lookup.el | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/test-gloss-core--lookup.el b/tests/test-gloss-core--lookup.el new file mode 100644 index 0000000..a1986a7 --- /dev/null +++ b/tests/test-gloss-core--lookup.el @@ -0,0 +1,73 @@ +;;; test-gloss-core--lookup.el --- Tests for gloss-core-lookup -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; Tests for `gloss-core-lookup' covering Normal/Boundary/Error cases. + +;;; Code: + +(require 'ert) +(require 'gloss-core) +(require 'testutil-gloss) + +(ert-deftest test-gloss-core-lookup-existing-term-returns-entry () + "Normal: lookup of saved term returns entry plist with all fields." + (gloss-test--with-temp-glossary gloss-test--sample-content + (let ((entry (gloss-core-lookup "anaphora"))) + (should entry) + (should (equal (plist-get entry :term) "anaphora")) + (should (string-match-p "Reference to something earlier" + (plist-get entry :body))) + (should (eq (plist-get entry :source) 'wiktionary)) + (should (equal (plist-get entry :added) "2026-04-28"))))) + +(ert-deftest test-gloss-core-lookup-includes-marker () + "Normal: lookup result includes a :marker field at the heading." + (gloss-test--with-temp-glossary gloss-test--sample-content + (let* ((entry (gloss-core-lookup "anaphora")) + (marker (plist-get entry :marker))) + (should (markerp marker)) + (with-current-buffer (marker-buffer marker) + (goto-char marker) + (should (looking-at-p "^\\* anaphora")))))) + +(ert-deftest test-gloss-core-lookup-missing-term-returns-nil () + "Normal: lookup of unsaved term returns nil." + (gloss-test--with-temp-glossary gloss-test--sample-content + (should-not (gloss-core-lookup "nonexistent-term")))) + +(ert-deftest test-gloss-core-lookup-empty-string-returns-nil () + "Boundary: lookup of empty string returns nil, not an error." + (gloss-test--with-temp-glossary gloss-test--sample-content + (should-not (gloss-core-lookup "")))) + +(ert-deftest test-gloss-core-lookup-nil-returns-nil () + "Boundary: lookup of nil returns nil, not an error." + (gloss-test--with-temp-glossary gloss-test--sample-content + (should-not (gloss-core-lookup nil)))) + +(ert-deftest test-gloss-core-lookup-case-sensitive () + "Boundary: lookup is case-sensitive — \"Anaphora\" misses \"anaphora\"." + (gloss-test--with-temp-glossary gloss-test--sample-content + (should-not (gloss-core-lookup "Anaphora")))) + +(ert-deftest test-gloss-core-lookup-empty-glossary-file-returns-nil () + "Error: lookup against empty file returns nil." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (should-not (gloss-core-lookup "anything")))) + +(ert-deftest test-gloss-core-lookup-missing-file-returns-nil () + "Error: lookup before any save returns nil (file does not exist)." + (let ((gloss-file (concat temporary-file-directory "gloss-nonexistent-" + (number-to-string (random 100000)) ".org"))) + (unwind-protect + (progn + (gloss-core--cache-reset) + (should-not (file-exists-p gloss-file)) + (should-not (gloss-core-lookup "anything"))) + (gloss-core--cache-reset) + (when (file-exists-p gloss-file) (delete-file gloss-file))))) + +(provide 'test-gloss-core--lookup) +;;; test-gloss-core--lookup.el ends here |
