1 ;;; reftex-tests.el --- Test suite for reftex. -*- lexical-binding: t -*-
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; Author: RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
7 ;; Human-Keywords: internal
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
32 (require 'reftex-parse
)
34 (ert-deftest reftex-locate-bibliography-files
()
35 "Test `reftex-locate-bibliography-files'."
36 (let ((temp-dir (make-temp-file "reftex-bib" 'dir
))
37 (files '("ref1.bib" "ref2.bib"))
38 (test '(("\\addbibresource{ref1.bib}\n" .
("ref1.bib"))
39 ("\\\\addbibresource[label=x]{ref2.bib}\\n" .
("ref2.bib"))
40 ("\\begin{document}\n\\bibliographystyle{plain}\n
41 \\bibliography{ref1,ref2}\n\\end{document}" .
("ref1.bib" "ref2.bib"))))
42 (reftex-bibliography-commands
43 ;; Default value: See reftex-vars.el `reftex-bibliography-commands'
44 '("bibliography" "nobibliography" "setupbibtex\\[.*?database="
50 (write-region (point-min) (point-max) (expand-file-name file
57 (let ((res (mapcar #'file-name-nondirectory
58 (reftex-locate-bibliography-files temp-dir
))))
59 (should (equal res
(cdr data
))))))
61 (delete-directory temp-dir
'recursive
)))
63 (ert-deftest reftex-what-environment-test
()
64 "Test `reftex-what-environment'."
66 (insert "\\begin{equation}\n x=y^2\n")
69 (insert "\\end{equation}\n")
72 (should (equal (reftex-what-environment 1) '("equation" .
1)))
73 (should (equal (reftex-what-environment t
) '(("equation" .
1))))
75 (insert "\\begin{something}\nxxx")
77 (insert "\\end{something}")
79 (should (equal (reftex-what-environment 1) `("something" .
,pt
)))
80 (should (equal (reftex-what-environment t
) `(("something" .
,pt
)
82 (should (equal (reftex-what-environment t pt
) `(("something" .
,pt
))))
83 (should (equal (reftex-what-environment '("equation"))
84 '("equation" .
1))))))
86 (ert-deftest reftex-roman-number-test
()
87 "Test `reftex-roman-number'."
88 (let ((hindu-arabic '(1 2 4 9 14 1050))
89 (roman '("I" "II" "IV" "IX" "XIV" "ML")))
90 (while (and hindu-arabic roman
)
91 (should (string= (reftex-roman-number (car hindu-arabic
))
96 (ert-deftest reftex-parse-from-file-test
()
97 "Test `reftex-parse-from-file'."
98 (let* ((temp-dir (make-temp-file "reftex-parse" 'dir
))
99 (tex-file (expand-file-name "test.tex" temp-dir
))
100 (bib-file (expand-file-name "ref.bib" temp-dir
)))
104 \\section{test}\\label{sec:test}
105 \\subsection{subtest}
107 \\begin{align*}\\label{eq:foo}
111 \\bibliographystyle{plain}
114 (write-region (point-min) (point-max) tex-file
))
117 (write-region (point-min) (point-max) bib-file
))
118 (reftex-ensure-compiled-variables)
119 (let ((parsed (reftex-parse-from-file tex-file nil temp-dir
)))
120 (should (equal (car parsed
) `(eof ,tex-file
)))
123 (let ((entry (pop parsed
)))
125 ((eq (car entry
) 'bib
)
126 (should (string= (cadr entry
) bib-file
)))
127 ((eq (car entry
) 'toc
)) ;; ...
128 ((string= (car entry
) "eq:foo"))
129 ((string= (car entry
) "sec:test"))
130 ((eq (car entry
) 'bof
)
131 (should (string= (cadr entry
) tex-file
))
132 (should (null parsed
)))
133 (t (should-not t
)))))
134 (delete-directory temp-dir
'recursive
))))
137 (require 'reftex-cite
)
139 (ert-deftest reftex-parse-bibtex-entry-test
()
140 "Test `reftex-parse-bibtex-entry'."
141 (let ((entry "@Book{Stallman12,
142 author = {Richard Stallman\net al.},
143 title = {The Emacs Editor},
144 publisher = {GNU Press},
147 note = {Updated for Emacs Version 24.2}
151 (should (string= (reftex-get-bib-field "&key" parsed
)
153 (should (string= (reftex-get-bib-field "&type" parsed
)
155 (should (string= (reftex-get-bib-field "author" parsed
)
156 "Richard Stallman et al."))
157 (should (string= (reftex-get-bib-field "title" parsed
)
159 (should (string= (reftex-get-bib-field "publisher" parsed
)
161 (should (string= (reftex-get-bib-field "year" parsed
)
163 (should (string= (reftex-get-bib-field "edition" parsed
)
165 (should (string= (reftex-get-bib-field "note" parsed
)
166 "Updated for Emacs Version 24.2"))))))
167 (funcall check
(reftex-parse-bibtex-entry entry
))
170 (funcall check
(reftex-parse-bibtex-entry nil
(point-min)
173 (ert-deftest reftex-get-bib-names-test
()
174 "Test `reftex-get-bib-names'."
175 (let ((entry (reftex-parse-bibtex-entry "@article{Foo123,
176 author = {Jane Roe and\tJohn Doe and W. Public},
178 (should (equal (reftex-get-bib-names "author" entry
)
179 '("Jane Roe" "John Doe" "Public"))))
180 (let ((entry (reftex-parse-bibtex-entry "@article{Foo123,
181 editor = {Jane Roe and\tJohn Doe and W. Public},
183 (should (equal (reftex-get-bib-names "author" entry
)
184 '("Jane Roe" "John Doe" "Public")))))
186 (ert-deftest reftex-format-citation-test
()
187 "Test `reftex-format-citation'."
188 (let ((entry (reftex-parse-bibtex-entry
190 author = {Jane Roe and John Doe and Jane Q. Taxpayer},
191 title = {Some Article},
192 journal = {Some Journal},
196 (should (string= (reftex-format-citation entry nil
) "\\cite{Foo13}"))
197 (should (string= (reftex-format-citation entry
"%l:%A:%y:%t %j %P %a")
198 "Foo13:Jane Roe:2013:Some Article Some Journal 1 Jane Roe, John Doe \\& Jane Taxpayer"))))
200 (provide 'reftex-tests
)
201 ;;; reftex-tests.el ends here.