test-org-pcomplete.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. ;;; test-org-pcomplete.el --- test pcomplete integration -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015-2016, 2019 Alexey Lebedeff
  3. ;; Authors: Alexey Lebedeff
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. ;;; Comments:
  16. ;;; Code:
  17. (require 'org)
  18. (ert-deftest test-org-pcomplete/clocktable ()
  19. "Test completion of clock table parameters."
  20. (should
  21. (equal "#+begin: clocktable :scope"
  22. (org-test-with-temp-text "#+begin: clocktable :sco<point>"
  23. (pcomplete)
  24. (buffer-string)))))
  25. (ert-deftest test-org-pcomplete/drawer ()
  26. "Test drawer completion."
  27. (should
  28. (equal "* Foo\n:PROPERTIES:"
  29. (org-test-with-temp-text "* Foo\n:<point>"
  30. (pcomplete)
  31. (buffer-string))))
  32. (should
  33. (equal ":DRAWER:\nContents\n:END:\n* Foo\n:DRAWER:"
  34. (org-test-with-temp-text ":DRAWER:\nContents\n:END:\n* Foo\n:D<point>"
  35. (pcomplete)
  36. (buffer-string)))))
  37. (ert-deftest test-org-pcomplete/entity ()
  38. "Test entity completion."
  39. (should
  40. (equal "\\alpha"
  41. (org-test-with-temp-text "\\alp<point>"
  42. (pcomplete)
  43. (buffer-string))))
  44. (should
  45. (equal "\\frac12"
  46. (org-test-with-temp-text "\\frac1<point>"
  47. (pcomplete)
  48. (buffer-string)))))
  49. (ert-deftest test-org-pcomplete/keyword ()
  50. "Test keyword and block completion."
  51. (should
  52. (string-prefix-p
  53. "#+startup: "
  54. (org-test-with-temp-text "#+start<point>"
  55. (pcomplete)
  56. (buffer-string))
  57. t))
  58. (should
  59. (string-prefix-p
  60. "#+begin_center"
  61. (org-test-with-temp-text "#+begin_ce<point>"
  62. (pcomplete)
  63. (buffer-string))
  64. t)))
  65. (ert-deftest test-org-pcomplete/src-block ()
  66. "Test Babel source block header arguments completion."
  67. (should
  68. (string-prefix-p
  69. "#+begin_src emacs-lisp"
  70. (org-test-with-temp-text "#+begin_src emac<point>"
  71. (pcomplete)
  72. (buffer-string))))
  73. (should
  74. (string-prefix-p
  75. "#+begin_src emacs-lisp :session"
  76. (org-test-with-temp-text "#+begin_src emacs-lisp :sess<point>"
  77. (pcomplete)
  78. (buffer-string)))))
  79. (ert-deftest test-org-pcomplete/link ()
  80. "Test link completion"
  81. (should
  82. (equal "[[org:"
  83. (org-test-with-temp-text "[[o<point>"
  84. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  85. (pcomplete))
  86. (buffer-string))))
  87. (should-not
  88. (equal "[org:"
  89. (org-test-with-temp-text "[[o<point>"
  90. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  91. (pcomplete))
  92. (buffer-string)))))
  93. (ert-deftest test-org-pcomplete/prop ()
  94. "Test property completion."
  95. (should
  96. (equal
  97. "
  98. * a
  99. :PROPERTIES:
  100. :pname:\s
  101. :END:
  102. * b
  103. :PROPERTIES:
  104. :pname: pvalue
  105. :END:
  106. "
  107. (org-test-with-temp-text "
  108. * a
  109. :PROPERTIES:
  110. :pna<point>
  111. :END:
  112. * b
  113. :PROPERTIES:
  114. :pname: pvalue
  115. :END:
  116. "
  117. (pcomplete)
  118. (buffer-string)))))
  119. (ert-deftest test-org-pcomplete/search-heading ()
  120. "Test search heading completion."
  121. (should
  122. (equal "* Foo\n[[*Foo"
  123. (org-test-with-temp-text "* Foo\n[[*<point>"
  124. (pcomplete)
  125. (buffer-string)))))
  126. (ert-deftest test-org-pcomplete/tag ()
  127. "Test tag completion."
  128. ;; Complete at end of line, according to `org-current-tag-alist'.
  129. (should
  130. (equal "* H :foo:"
  131. (org-test-with-temp-text "* H :<point>"
  132. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  133. (buffer-string))))
  134. (should
  135. (equal "* H :foo:bar:"
  136. (org-test-with-temp-text "* H :foo:b<point>"
  137. (let ((org-current-tag-alist '(("bar")))) (pcomplete))
  138. (buffer-string))))
  139. ;; If `org-current-tag-alist' is non-nil, complete against tags in
  140. ;; buffer.
  141. (should
  142. (equal "* H1 :bar:\n* H2 :bar:"
  143. (org-test-with-temp-text "* H1 :bar:\n* H2 :<point>"
  144. (let ((org-current-tag-alist nil)) (pcomplete))
  145. (buffer-string))))
  146. ;; Do not complete in the middle of a line.
  147. (should
  148. (equal "* H :notag: :real:tags:"
  149. (org-test-with-temp-text "* H :notag:<point> :real:tags:"
  150. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  151. (buffer-string))))
  152. ;; Complete even when there's a match on the line.
  153. (should
  154. (equal "* foo: :foo:"
  155. (org-test-with-temp-text "* foo: :<point>"
  156. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  157. (buffer-string)))))
  158. (ert-deftest test-org-pcomplete/todo ()
  159. "Test TODO completion."
  160. (should
  161. (equal "* TODO"
  162. (org-test-with-temp-text "* T<point>"
  163. (pcomplete)
  164. (buffer-string)))))
  165. (provide 'test-org-pcomplete)
  166. ;;; test-org-pcomplete.el ends here