blob: 0e044cabe3a1701f765d9a1b881a2efa4e880ff2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
;;; 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)."
(gloss-test--with-missing-glossary
(should-not (file-exists-p gloss-file))
(should-not (gloss-core-lookup "anything"))))
(provide 'test-gloss-core--lookup)
;;; test-gloss-core--lookup.el ends here
|