test-org-pcomplete.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. ;;; test-org-pcomplete.el --- test pcomplete integration
  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. (ert-deftest test-org-pcomplete/clocktable ()
  18. "Test completion of clock table parameters."
  19. (should
  20. (equal "#+begin: clocktable :scope"
  21. (org-test-with-temp-text "#+begin: clocktable :sco<point>"
  22. (pcomplete)
  23. (buffer-string)))))
  24. (ert-deftest test-org-pcomplete/drawer ()
  25. "Test drawer completion."
  26. (should
  27. (equal "* Foo\n:PROPERTIES:"
  28. (org-test-with-temp-text "* Foo\n:<point>"
  29. (pcomplete)
  30. (buffer-string))))
  31. (should
  32. (equal ":DRAWER:\nContents\n:END:\n* Foo\n:DRAWER:"
  33. (org-test-with-temp-text ":DRAWER:\nContents\n:END:\n* Foo\n:D<point>"
  34. (pcomplete)
  35. (buffer-string)))))
  36. (ert-deftest test-org-pcomplete/entity ()
  37. "Test entity completion."
  38. (should
  39. (equal "\\alpha"
  40. (org-test-with-temp-text "\\alp<point>"
  41. (pcomplete)
  42. (buffer-string))))
  43. (should
  44. (equal "\\frac12"
  45. (org-test-with-temp-text "\\frac1<point>"
  46. (pcomplete)
  47. (buffer-string)))))
  48. (ert-deftest test-org-pcomplete/keyword ()
  49. "Test keyword and block completion."
  50. (should
  51. (string-prefix-p
  52. "#+startup: "
  53. (org-test-with-temp-text "#+start<point>"
  54. (pcomplete)
  55. (buffer-string))
  56. t))
  57. (should
  58. (string-prefix-p
  59. "#+begin_center"
  60. (org-test-with-temp-text "#+begin_ce<point>"
  61. (pcomplete)
  62. (buffer-string))
  63. t)))
  64. (ert-deftest test-org-pcomplete/src-block ()
  65. "Test Babel source block header arguments completion."
  66. (should
  67. (string-prefix-p
  68. "#+begin_src emacs-lisp"
  69. (org-test-with-temp-text "#+begin_src emac<point>"
  70. (pcomplete)
  71. (buffer-string))))
  72. (should
  73. (string-prefix-p
  74. "#+begin_src emacs-lisp :session"
  75. (org-test-with-temp-text "#+begin_src emacs-lisp :sess<point>"
  76. (pcomplete)
  77. (buffer-string)))))
  78. (ert-deftest test-org-pcomplete/link ()
  79. "Test link completion"
  80. (should
  81. (equal "[[org:"
  82. (org-test-with-temp-text "[[o<point>"
  83. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  84. (pcomplete))
  85. (buffer-string))))
  86. (should-not
  87. (equal "[org:"
  88. (org-test-with-temp-text "[[o<point>"
  89. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  90. (pcomplete))
  91. (buffer-string)))))
  92. (ert-deftest test-org-pcomplete/prop ()
  93. "Test property completion."
  94. (should
  95. (equal
  96. "
  97. * a
  98. :PROPERTIES:
  99. :pname:\s
  100. :END:
  101. * b
  102. :PROPERTIES:
  103. :pname: pvalue
  104. :END:
  105. "
  106. (org-test-with-temp-text "
  107. * a
  108. :PROPERTIES:
  109. :pna<point>
  110. :END:
  111. * b
  112. :PROPERTIES:
  113. :pname: pvalue
  114. :END:
  115. "
  116. (pcomplete)
  117. (buffer-string)))))
  118. (ert-deftest test-org-pcomplete/search-heading ()
  119. "Test search heading completion."
  120. (should
  121. (equal "* Foo\n[[*Foo"
  122. (org-test-with-temp-text "* Foo\n[[*<point>"
  123. (pcomplete)
  124. (buffer-string)))))
  125. (ert-deftest test-org-pcomplete/tag ()
  126. "Test tag completion."
  127. ;; Complete at end of line, according to `org-current-tag-alist'.
  128. (should
  129. (equal "* H :foo:"
  130. (org-test-with-temp-text "* H :<point>"
  131. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  132. (buffer-string))))
  133. (should
  134. (equal "* H :foo:bar:"
  135. (org-test-with-temp-text "* H :foo:b<point>"
  136. (let ((org-current-tag-alist '(("bar")))) (pcomplete))
  137. (buffer-string))))
  138. ;; If `org-current-tag-alist' is non-nil, complete against tags in
  139. ;; buffer.
  140. (should
  141. (equal "* H1 :bar:\n* H2 :bar:"
  142. (org-test-with-temp-text "* H1 :bar:\n* H2 :<point>"
  143. (let ((org-current-tag-alist nil)) (pcomplete))
  144. (buffer-string))))
  145. ;; Do not complete in the middle of a line.
  146. (should
  147. (equal "* H :notag: :real:tags:"
  148. (org-test-with-temp-text "* H :notag:<point> :real:tags:"
  149. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  150. (buffer-string))))
  151. ;; Complete even when there's a match on the line.
  152. (should
  153. (equal "* foo: :foo:"
  154. (org-test-with-temp-text "* foo: :<point>"
  155. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  156. (buffer-string)))))
  157. (ert-deftest test-org-pcomplete/todo ()
  158. "Test TODO completion."
  159. (should
  160. (equal "* TODO"
  161. (org-test-with-temp-text "* T<point>"
  162. (pcomplete)
  163. (buffer-string)))))
  164. (provide 'test-org-pcomplete)
  165. ;;; test-org-pcomplete.el ends here