test-ob-lob.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ;;; test-ob-lob.el
  2. ;; Copyright (c) 2010-2012 Eric Schulte
  3. ;; Authors: Eric Schulte
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments:
  7. ;;; Tests
  8. (org-babel-lob-ingest
  9. (expand-file-name
  10. "library-of-babel.org"
  11. (expand-file-name
  12. "babel"
  13. (expand-file-name
  14. "contrib"
  15. (expand-file-name
  16. ".."
  17. (expand-file-name
  18. ".."
  19. (file-name-directory
  20. (or load-file-name buffer-file-name))))))))
  21. (ert-deftest test-ob-lob/ingest ()
  22. "Test the ingestion of an org-mode file."
  23. (should (< 0 (org-babel-lob-ingest
  24. (expand-file-name "babel.org" org-test-example-dir)))))
  25. (ert-deftest test-ob-lob/call-with-header-arguments ()
  26. "Test the evaluation of a library of babel #+call: line."
  27. (org-test-at-id "fab7e291-fde6-45fc-bf6e-a485b8bca2f0"
  28. (move-beginning-of-line 1)
  29. (forward-line 6)
  30. (message (buffer-substring (point-at-bol) (point-at-eol)))
  31. (should (string= "testing" (org-babel-lob-execute
  32. (org-babel-lob-get-info))))
  33. (forward-line 1)
  34. (should (string= "testing" (caar (org-babel-lob-execute
  35. (org-babel-lob-get-info)))))
  36. (forward-line 1)
  37. (should (string= "testing" (org-babel-lob-execute
  38. (org-babel-lob-get-info))))
  39. (forward-line 1)
  40. (should (string= "testing" (caar (org-babel-lob-execute
  41. (org-babel-lob-get-info)))))
  42. (forward-line 1)
  43. (should (string= "testing" (org-babel-lob-execute
  44. (org-babel-lob-get-info))))
  45. (forward-line 1)
  46. (should (string= "testing" (caar (org-babel-lob-execute
  47. (org-babel-lob-get-info)))))
  48. (forward-line 1) (beginning-of-line) (forward-char 27)
  49. (should (string= "testing" (org-babel-lob-execute
  50. (org-babel-lob-get-info))))
  51. (forward-line 1) (beginning-of-line) (forward-char 27)
  52. (should (string= "testing" (caar (org-babel-lob-execute
  53. (org-babel-lob-get-info)))))
  54. (forward-line 1) (beginning-of-line)
  55. (should (= 4 (org-babel-lob-execute (org-babel-lob-get-info))))
  56. (forward-line 1)
  57. (should (string= "testing" (org-babel-lob-execute
  58. (org-babel-lob-get-info))))
  59. (forward-line 1)
  60. (should (string= "123" (org-babel-lob-execute (org-babel-lob-get-info))))))
  61. (ert-deftest test-ob-lob/export-lob-lines ()
  62. "Test the export of a variety of library babel call lines."
  63. (org-test-at-id "72ddeed3-2d17-4c7f-8192-a575d535d3fc"
  64. (org-narrow-to-subtree)
  65. (let ((html (org-export-as-html nil nil nil 'string 'body-only)))
  66. ;; check the location of each exported number
  67. (with-temp-buffer
  68. (insert html) (goto-char (point-min))
  69. ;; 0 should be on a line by itself
  70. (should (re-search-forward "0" nil t))
  71. (should (string= "0" (buffer-substring (point-at-bol) (point-at-eol))))
  72. ;; 2 should be in <code> tags
  73. (should (re-search-forward "2" nil t))
  74. (should (re-search-forward (regexp-quote "</code>") (point-at-eol) t))
  75. (should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))
  76. ;; 4 should not be exported
  77. (should (not (re-search-forward "4" nil t)))
  78. ;; 6 should also be inline
  79. (should (re-search-forward "6" nil t))
  80. (should (re-search-forward (regexp-quote "</code>") (point-at-eol) t))
  81. (should (re-search-backward (regexp-quote "<code>") (point-at-bol) t))
  82. ;; 8 should not be quoted
  83. (should (re-search-forward "8" nil t))
  84. (should (not (= ?= (char-after (point)))))
  85. (should (not (= ?= (char-before (- (point) 1)))))
  86. ;; 10 should export
  87. (should (re-search-forward "10" nil t))))))
  88. (ert-deftest test-ob-lob/do-not-eval-lob-lines-in-example-blocks-on-export ()
  89. (org-test-with-temp-text-in-file "
  90. for export
  91. #+begin_example
  92. #+call: rubbish()
  93. #+end_example"
  94. (org-export-as-html nil)))
  95. (provide 'test-ob-lob)
  96. ;;; test-ob-lob.el ends here