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--alphabetical-insert.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--alphabetical-insert.el')
| -rw-r--r-- | tests/test-gloss-core--alphabetical-insert.el | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test-gloss-core--alphabetical-insert.el b/tests/test-gloss-core--alphabetical-insert.el new file mode 100644 index 0000000..69c6c95 --- /dev/null +++ b/tests/test-gloss-core--alphabetical-insert.el @@ -0,0 +1,42 @@ +;;; test-gloss-core--alphabetical-insert.el --- Tests for alphabetical insert -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-3.0-or-later + +;;; Commentary: +;; Tests that `gloss-core-save' inserts new entries at the correct +;; alphabetical position (case-insensitive ordering). + +;;; Code: + +(require 'ert) +(require 'gloss-core) +(require 'testutil-gloss) + +(ert-deftest test-gloss-core-alphabetical-insert-correct-position () + "Normal: terms saved out of order land in alphabetical order." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "Charlie" "Third." 'manual) + (gloss-core-save "Alpha" "First." 'manual) + (gloss-core-save "Bravo" "Second." 'manual) + (should (equal (gloss-core-list) '("Alpha" "Bravo" "Charlie"))))) + +(ert-deftest test-gloss-core-alphabetical-insert-case-insensitive-ordering () + "Boundary: ordering uses a case-insensitive compare." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "banana" "Fruit." 'manual) + (gloss-core-save "Apple" "Also fruit." 'manual) + (should (equal (gloss-core-list) '("Apple" "banana"))))) + +(ert-deftest test-gloss-core-alphabetical-insert-on-disk-matches-list () + "Boundary: the on-disk file order matches the list order." + (gloss-test--with-temp-glossary "#+TITLE: Glossary\n" + (gloss-core-save "zebra" "Last." 'manual) + (gloss-core-save "alpha" "First." 'manual) + (let ((file-content (with-temp-buffer + (insert-file-contents gloss-file) + (buffer-string)))) + (should (< (string-match "^\\* alpha" file-content) + (string-match "^\\* zebra" file-content)))))) + +(provide 'test-gloss-core--alphabetical-insert) +;;; test-gloss-core--alphabetical-insert.el ends here |
