File: test-oc-basic.el

package info (click to toggle)
org-mode 9.7.36%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,760 kB
  • sloc: lisp: 160,254; xml: 1,377; perl: 229; makefile: 197; sh: 5
file content (179 lines) | stat: -rw-r--r-- 7,466 bytes parent folder | download | duplicates (2)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
;;; test-oc-basic.el --- Tests for Org Cite basic processor        -*- lexical-binding: t; -*-

;; Copyright (C) 2024  Ihor Radchenko

;; Author: Ihor Radchenko <yantar92 at posteo dot net>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Unit tests for Org cite basic processor.

;;; Code:

(require 'oc-basic)

(ert-deftest test-org-cite-basic/parse-bibliography ()
  "Test `org-cite-basic--parse-bibliography'."
  ;; Bibtex bibliography.
  (org-test-with-temp-text
      (format "#+bibliography: %s"
              (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((data (org-cite-basic--parse-bibliography)))
      (should (= 1 (length data)))
      (should (equal (expand-file-name "examples/Basic.bib" org-test-dir)
                     (caar data)))
      (dolist (k (hash-table-keys (cdar data)))
        (when (equal k "friends")
          (should (equal (gethash k (cdar data))
                         '((type . "book")
                           (id . "friends")
                           (title . "{{LaTeX}} and Friends")
                           (author . "van Dongen, M.R.C.")
                           (date . "2012")
                           (location . "Berlin")
                           (publisher . "Springer")
                           (doi . "10.1007/978-3-642-23816-1")
                           (isbn . "9783642238161")))))))))

(ert-deftest test-org-cite-basic/export-citation ()
  "Test `org-cite-basic-export-citation'."
  ;; Default "nil" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Default: [cite:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (search-forward "Default: (Citing van Dongen, M.R.C., 2012, and van Dongen, M.R.C., 2012
also is duplication.)" nil t)))))
  ;; "author" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Author: [cite/a:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           (search-forward "Author: Citing van Dongen, M.R.C., and van Dongen, M.R.C. also is
duplication." nil t))))))
  ;; "note" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Note: [cite/ft:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           (search-forward "[1] Citing van Dongen, M.R.C. (2012), and van Dongen, M.R.C. (2012) also
is duplication." nil t))))))
  ;; "nocite" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Nocite (should be blank): [cite/n:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should (search-forward "Nocite (should be blank):\n" nil t))
          (goto-char (point-min))
          (should-not (search-forward "2012" nil t))
          (goto-char (point-min))
          (should-not (search-forward "Dongen" nil t))))))
  ;; "noauthor" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Noauthor: [cite/na:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           (search-forward "Noauthor: (Citing 2012, and 2012 also is duplication.)" nil t))))))
  ;; "numeric" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Numeric (should \"use global affixes and ignore local ones\"): [cite/nb:Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           (search-forward "Numeric (should \"use global affixes and ignore local ones\"): (Citing 1,
1 is duplication.)" nil t))))))
  ;; "text" citation style.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Text: [cite/t: Citing ; @friends; and @friends also; is duplication.]"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           (search-forward "Text: Citing van Dongen, M.R.C. (2012), and van Dongen, M.R.C. (2012)
also is duplication." nil t)))))))

(ert-deftest test-org-cite-basic/export-bibliography ()
  "Test `org-cite-basic-export-bibliography'."
  ;; Drop {...} Bibtex brackets and render entities.
  (org-test-with-temp-text
      (format
       "#+bibliography: %s
#+cite_export: basic
Foo [cite/plain:@Geyer2011]
#+print_bibliography:"
       (expand-file-name "examples/Basic.bib" org-test-dir))
    (let ((export-buffer "*Test ASCII Export*")
          (org-export-show-temporary-export-buffer nil))
      (org-export-to-buffer 'ascii export-buffer)
      (with-current-buffer export-buffer
        (let ((case-fold-search t))
          (should
           ;; Rendered from {Introduction to Markov\plus Chain Monte Carlo}
           (search-forward "Introduction to Markov+ Chain Monte Carlo" nil t)))))))

(provide 'test-oc-basic)
;;; test-oc-basic.el ends here