test-org-pcomplete.el 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <http://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/link ()
  65. "Test link completion"
  66. (should
  67. (equal "[[org:"
  68. (org-test-with-temp-text "[[o<point>"
  69. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  70. (pcomplete))
  71. (buffer-string))))
  72. (should-not
  73. (equal "[org:"
  74. (org-test-with-temp-text "[[o<point>"
  75. (let ((org-link-abbrev-alist '(("org" . "https://orgmode.org/"))))
  76. (pcomplete))
  77. (buffer-string)))))
  78. (ert-deftest test-org-pcomplete/prop ()
  79. "Test property completion."
  80. (should
  81. (equal
  82. "
  83. * a
  84. :PROPERTIES:
  85. :pname:\s
  86. :END:
  87. * b
  88. :PROPERTIES:
  89. :pname: pvalue
  90. :END:
  91. "
  92. (org-test-with-temp-text "
  93. * a
  94. :PROPERTIES:
  95. :pna<point>
  96. :END:
  97. * b
  98. :PROPERTIES:
  99. :pname: pvalue
  100. :END:
  101. "
  102. (pcomplete)
  103. (buffer-string)))))
  104. (ert-deftest test-org-pcomplete/search-heading ()
  105. "Test search heading completion."
  106. (should
  107. (equal "* Foo\n[[*Foo"
  108. (org-test-with-temp-text "* Foo\n[[*<point>"
  109. (pcomplete)
  110. (buffer-string)))))
  111. (ert-deftest test-org-pcomplete/tag ()
  112. "Test tag completion."
  113. ;; Complete at end of line, according to `org-current-tag-alist'.
  114. (should
  115. (equal "* H :foo:"
  116. (org-test-with-temp-text "* H :<point>"
  117. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  118. (buffer-string))))
  119. (should
  120. (equal "* H :foo:bar:"
  121. (org-test-with-temp-text "* H :foo:b<point>"
  122. (let ((org-current-tag-alist '(("bar")))) (pcomplete))
  123. (buffer-string))))
  124. ;; If `org-current-tag-alist' is non-nil, complete against tags in
  125. ;; buffer.
  126. (should
  127. (equal "* H1 :bar:\n* H2 :bar:"
  128. (org-test-with-temp-text "* H1 :bar:\n* H2 :<point>"
  129. (let ((org-current-tag-alist nil)) (pcomplete))
  130. (buffer-string))))
  131. ;; Do not complete in the middle of a line.
  132. (should
  133. (equal "* H :notag: :real:tags:"
  134. (org-test-with-temp-text "* H :notag:<point> :real:tags:"
  135. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  136. (buffer-string))))
  137. ;; Complete even when there's a match on the line.
  138. (should
  139. (equal "* foo: :foo:"
  140. (org-test-with-temp-text "* foo: :<point>"
  141. (let ((org-current-tag-alist '(("foo")))) (pcomplete))
  142. (buffer-string)))))
  143. (ert-deftest test-org-pcomplete/todo ()
  144. "Test TODO completion."
  145. (should
  146. (equal "* TODO"
  147. (org-test-with-temp-text "* T<point>"
  148. (pcomplete)
  149. (buffer-string)))))
  150. (provide 'test-org-pcomplete)
  151. ;;; test-org-pcomplete.el ends here