test-org-macro.el 2.6 KB

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