test-org-list.el 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ;;; test-org-list.el --- Tests for org-list.el
  2. ;; Copyright (C) 2012 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Code:
  15. (ert-deftest test-org-list/list-ending ()
  16. "Test if lists end at the right place."
  17. ;; With two blank lines.
  18. (org-test-with-temp-text "- item\n\n\n Text"
  19. (goto-line 4)
  20. (should-not (org-in-item-p)))
  21. ;; With text less indented than top items.
  22. (org-test-with-temp-text "- item\nText"
  23. (goto-line 2)
  24. (should-not (org-in-item-p)))
  25. ;; Though, blank lines and text indentation is ignored in blocks.
  26. (org-test-with-temp-text
  27. "- item\n #+begin_quote\n\n\nText at column 0\n #+end_quote\n Text"
  28. (goto-line 7)
  29. (should (org-in-item-p))))
  30. (ert-deftest test-org-list/list-navigation ()
  31. "Test list navigation specifications."
  32. (org-test-with-temp-text "
  33. - item A
  34. - item B
  35. - item 1
  36. - item 1.1
  37. - item 1.2
  38. - item 1.3
  39. - item 2
  40. - item X
  41. - item Y"
  42. (let ((org-list-use-circular-motion nil))
  43. ;; 1. Test `org-next-item'.
  44. ;;
  45. ;; 1.1. Should return an error if at last item in
  46. ;; a list/sub-list, unless `org-list-use-circular-motion'
  47. ;; is non-nil.
  48. (goto-line 9)
  49. (should-error (org-next-item))
  50. (let ((org-list-use-circular-motion t))
  51. (should (progn (org-next-item) t)))
  52. (goto-line 14)
  53. (should-error (org-next-item))
  54. (let ((org-list-use-circular-motion t))
  55. (should (progn (org-next-item) t)))
  56. ;; 1.2. Should jump over sub-lists.
  57. (goto-line 6)
  58. (org-next-item)
  59. (should (looking-at "- item 2"))
  60. ;; 1.3. Shouldn't move to another list.
  61. (goto-line 3)
  62. (should-error (org-next-item))
  63. (should-not (looking-at "- item 1"))
  64. ;; 1.4. Should move to the list/sub-list first item when
  65. ;; `org-list-use-circular-motion' is non-nil.
  66. (let ((org-list-use-circular-motion t))
  67. (goto-line 10)
  68. (org-next-item)
  69. (should (looking-at "- item 1"))
  70. (goto-line 9)
  71. (org-next-item)
  72. (should (looking-at " - item 1.1")))
  73. ;; 2. Test `org-previous-item'.
  74. ;;
  75. ;; 2.1. Should return an error if at first item in
  76. ;; a list/sub-list, unless `org-list-use-circular-motion is
  77. ;; non-nil.
  78. (goto-line 7)
  79. (should-error (org-previous-item))
  80. (let ((org-list-use-circular-motion t))
  81. (should (progn (org-previous-item) t)))
  82. (goto-line 13)
  83. (should-error (org-previous-item))
  84. (let ((org-list-use-circular-motion t))
  85. (should (progn (org-previous-item) t)))
  86. ;; 2.2. Should ignore sub-lists.
  87. (goto-line 10)
  88. (org-previous-item)
  89. (should (looking-at "- item 1"))
  90. ;; 2.3. Shouldn't move to another list.
  91. (goto-line 6)
  92. (should-error (org-previous-item))
  93. (should-not (looking-at "- item B"))
  94. ;; 2.4. Should move to the list/sub-list last item when
  95. ;; `org-list-use-circular-motion' is non-nil.
  96. (let ((org-list-use-circular-motion t))
  97. (goto-line 6)
  98. (org-previous-item)
  99. (should (looking-at "- item 2"))
  100. (goto-line 7)
  101. (org-previous-item)
  102. (should (looking-at " - item 1.3"))))))
  103. (provide 'test-org-list)
  104. ;;; test-org-list.el ends here