aboutsummaryrefslogtreecommitdiff
path: root/tests/test-gloss-drill--export-all-tags-untagged.el
blob: bf8cf64d0adb046b410547d7adca38b68e8864d5 (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
;;; test-gloss-drill--export-all-tags-untagged.el --- Tests for gloss-drill-export-all on untagged entries -*- lexical-binding: t -*-

;; SPDX-License-Identifier: GPL-3.0-or-later

;;; Commentary:
;; Tests for `gloss-drill-export-all' covering the Normal happy-path
;; (untagged entries gain the tag and property) and the Boundary case of
;; an empty glossary file.  The entry walking uses real `org-element' /
;; `org-map-entries'; only the `org-drill' feature flag is mocked.

;;; Code:

(require 'ert)
(require 'gloss-drill)
(require 'testutil-gloss)
(require 'testutil-gloss-drill)

(defun gloss-test--drill-tagged-count ()
  "Return the number of top-level entries in `gloss-file' tagged :drill:.
Reads the file fresh from disk."
  (with-current-buffer (find-file-noselect gloss-file)
    (revert-buffer t t t)
    (let ((count 0))
      (org-map-entries
       (lambda ()
         (when (and (= 1 (org-current-level))
                    (member "drill" (org-get-tags nil t)))
           (setq count (1+ count)))))
      count)))

(defun gloss-test--drill-card-type-count ()
  "Return the number of top-level entries with :DRILL_CARD_TYPE: twosided'.
Reads the file fresh from disk."
  (with-current-buffer (find-file-noselect gloss-file)
    (revert-buffer t t t)
    (let ((count 0))
      (org-map-entries
       (lambda ()
         (when (and (= 1 (org-current-level))
                    (equal (org-entry-get nil "DRILL_CARD_TYPE") "twosided"))
           (setq count (1+ count)))))
      count)))

(ert-deftest test-gloss-drill-export-all-adds-drill-tag-to-every-entry ()
  "Normal: every untagged entry gains :drill: after export-all."
  (gloss-test--with-temp-glossary gloss-test--sample-content
    (gloss-test--with-org-drill-feature
      (gloss-drill-export-all)
      (should (= (gloss-test--drill-tagged-count) 2)))))

(ert-deftest test-gloss-drill-export-all-sets-drill-card-type-property ()
  "Normal: every entry gains :DRILL_CARD_TYPE: twosided after export-all."
  (gloss-test--with-temp-glossary gloss-test--sample-content
    (gloss-test--with-org-drill-feature
      (gloss-drill-export-all)
      (should (= (gloss-test--drill-card-type-count) 2)))))

(ert-deftest test-gloss-drill-export-all-empty-file-no-op ()
  "Boundary: export-all on an empty glossary file is a no-op, no error."
  (gloss-test--with-temp-glossary "#+TITLE: Glossary\n#+STARTUP: showall\n"
    (gloss-test--with-org-drill-feature
      (gloss-drill-export-all)
      (should (= (gloss-test--drill-tagged-count) 0)))))

(provide 'test-gloss-drill--export-all-tags-untagged)
;;; test-gloss-drill--export-all-tags-untagged.el ends here