ox-latex: Remove unused function
[org-mode.git] / testing / lisp / test-org-macro.el
blobce8d630079ff68d3f78a5b80c2eb29b332405c90
1 ;;; test-org-macro.el --- Tests for org-macro.el
3 ;; Copyright (C) 2013 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <n.goaziou@gmail.com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Code:
23 ;;; Macros
25 (ert-deftest test-org/macro-replace-all ()
26 "Test `org-macro-replace-all' specifications."
27 ;; Standard test.
28 (should
29 (equal
30 "#+MACRO: A B\n1 B 3"
31 (org-test-with-temp-text "#+MACRO: A B\n1 {{{A}}} 3"
32 (progn (org-macro-initialize-templates)
33 (org-macro-replace-all org-macro-templates)
34 (buffer-string)))))
35 ;; Macro with arguments.
36 (should
37 (equal
38 "#+MACRO: macro $1 $2\nsome text"
39 (org-test-with-temp-text "#+MACRO: macro $1 $2\n{{{macro(some,text)}}}"
40 (progn (org-macro-initialize-templates)
41 (org-macro-replace-all org-macro-templates)
42 (buffer-string)))))
43 ;; Macro with "eval".
44 (should
45 (equal
46 "#+MACRO: add (eval (+ $1 $2))\n3"
47 (org-test-with-temp-text "#+MACRO: add (eval (+ $1 $2))\n{{{add(1,2)}}}"
48 (progn (org-macro-initialize-templates)
49 (org-macro-replace-all org-macro-templates)
50 (buffer-string)))))
51 ;; Nested macros.
52 (should
53 (equal
54 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\ninner outer"
55 (org-test-with-temp-text
56 "#+MACRO: in inner\n#+MACRO: out {{{in}}} outer\n{{{out}}}"
57 (progn (org-macro-initialize-templates)
58 (org-macro-replace-all org-macro-templates)
59 (buffer-string)))))
60 ;; Error out when macro expansion is circular.
61 (should-error
62 (org-test-with-temp-text
63 "#+MACRO: mac1 {{{mac2}}}\n#+MACRO: mac2 {{{mac1}}}\n{{{mac1}}}"
64 (org-macro-initialize-templates)
65 (org-macro-replace-all org-macro-templates)))
66 ;; Macros in setup file.
67 (should
68 (string-match
69 "success success\\'"
70 (org-test-with-temp-text
71 (format "#+MACRO: other-macro success
72 #+SETUPFILE: \"%sexamples/macro-templates.org\"
73 {{{included-macro}}} {{{other-macro}}}"
74 org-test-dir)
75 (org-macro-initialize-templates)
76 (org-macro-replace-all org-macro-templates)
77 (buffer-string)))))
80 (provide 'test-org-macro)
81 ;;; test-org-macro.el ends here