test-org.el 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ;;; test-org.el
  2. ;; Copyright (c) ߚ David Maus
  3. ;; Authors: David Maus
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments:
  7. ;; Template test file for Org-mode tests
  8. ;;; Code:
  9. (ert-deftest test-org/org-link-escape-ascii-character ()
  10. "Escape an ascii character."
  11. (should
  12. (string=
  13. "%5B"
  14. (org-link-escape "["))))
  15. (ert-deftest test-org/org-link-escape-ascii-ctrl-character ()
  16. "Escape an ascii control character."
  17. (should
  18. (string=
  19. "%09"
  20. (org-link-escape "\t"))))
  21. (ert-deftest test-org/org-link-escape-multibyte-character ()
  22. "Escape an unicode multibyte character."
  23. (should
  24. (string=
  25. "%E2%82%AC"
  26. (org-link-escape "€"))))
  27. (ert-deftest test-org/org-link-escape-custom-table ()
  28. "Escape string with custom character table."
  29. (should
  30. (string=
  31. "Foo%3A%42ar%0A"
  32. (org-link-escape "Foo:Bar\n" '(?\: ?\B)))))
  33. (ert-deftest test-org/org-link-escape-custom-table-merge ()
  34. "Escape string with custom table merged with default table."
  35. (should
  36. (string=
  37. "%5BF%6F%6F%3A%42ar%0A%5D"
  38. (org-link-escape "[Foo:Bar\n]" '(?\: ?\B ?\o) t))))
  39. (ert-deftest test-org/org-link-unescape-ascii-character ()
  40. "Unescape an ascii character."
  41. (should
  42. (string=
  43. "["
  44. (org-link-unescape "%5B"))))
  45. (ert-deftest test-org/org-link-unescape-ascii-ctrl-character ()
  46. "Unescpae an ascii control character."
  47. (should
  48. (string=
  49. "\n"
  50. (org-link-unescape "%0A"))))
  51. (ert-deftest test-org/org-link-unescape-multibyte-character ()
  52. "Unescape unicode multibyte character."
  53. (should
  54. (string=
  55. "€"
  56. (org-link-unescape "%E2%82%AC"))))
  57. (ert-deftest test-org/org-link-unescape-ascii-extended-char ()
  58. "Unescape old style percent escaped character."
  59. (should
  60. (string=
  61. "àâçèéêîôùû"
  62. (decode-coding-string (org-link-unescape "%E0%E2%E7%E8%E9%EA%EE%F4%F9%FB") 'latin-1))))
  63. (ert-deftest test-org/org-link-escape-url-with-escaped-char ()
  64. "Escape and unscape a URL that includes an escaped char.
  65. http://article.gmane.org/gmane.emacs.orgmode/21459/"
  66. (should
  67. (string=
  68. "http://some.host.com/form?&id=blah%2Bblah25"
  69. (org-link-unescape (org-link-escape "http://some.host.com/form?&id=blah%2Bblah25")))))
  70. (ert-deftest test-org/accumulated-properties-in-drawers ()
  71. "Ensure properties accumulate in subtree drawers."
  72. (org-test-at-id "75282ba2-f77a-4309-a970-e87c149fe125"
  73. (org-babel-next-src-block)
  74. (should (equal '(2 1) (org-babel-execute-src-block)))))
  75. ;;; Links
  76. ;;;; Fuzzy links
  77. ;; Fuzzy links [[text]] encompass links to a target (<<text>>), to
  78. ;; a target keyword (aka an invisible target: #+TARGET: text), to
  79. ;; a named element (#+name: text) and to headlines (* Text).
  80. (ert-deftest test-org-export/fuzzy-links ()
  81. "Test fuzzy links specifications."
  82. ;; 1. Fuzzy link goes in priority to a matching target.
  83. (org-test-with-temp-text
  84. "#+TARGET: Test\n#+NAME: Test\n|a|b|\n<<Test>>\n* Test\n[[Test]]"
  85. (goto-line 6)
  86. (org-open-at-point)
  87. (should (looking-at "<<Test>>")))
  88. ;; 2. Fuzzy link should then go to a matching target keyword.
  89. (org-test-with-temp-text
  90. "#+NAME: Test\n|a|b|\n#+TARGET: Test\n* Test\n[[Test]]"
  91. (goto-line 5)
  92. (org-open-at-point)
  93. (should (looking-at "#\\+TARGET: Test")))
  94. ;; 3. Then fuzzy link points to an element with a given name.
  95. (org-test-with-temp-text "Test\n#+NAME: Test\n|a|b|\n* Test\n[[Test]]"
  96. (goto-line 5)
  97. (org-open-at-point)
  98. (should (looking-at "#\\+NAME: Test")))
  99. ;; 4. A target still lead to a matching headline otherwise.
  100. (org-test-with-temp-text "* Head1\n* Head2\n*Head3\n[[Head2]]"
  101. (goto-line 4)
  102. (org-open-at-point)
  103. (should (looking-at "\\* Head2")))
  104. ;; 5. With a leading star in link, enforce heading match.
  105. (org-test-with-temp-text "#+TARGET: Test\n* Test\n<<Test>>\n[[*Test]]"
  106. (goto-line 4)
  107. (org-open-at-point)
  108. (should (looking-at "\\* Test"))))
  109. (provide 'test-org)
  110. ;;; test-org.el ends here