test-org-macs.el 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. ;;; test-org-macs.el --- Tests for Org Macs library -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2017 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
  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. ;;; String manipulation
  16. (ert-deftest test-org/split-string ()
  17. "Test `org-split-string' specifications."
  18. ;; Regular test.
  19. (should (equal '("a" "b") (org-split-string "a b" " ")))
  20. ;; Empty parts are not removed.
  21. (should (equal '("a" "" "b") (org-split-string "a||b" "|")))
  22. ;; However, empty parts at beginning or end of string are removed.
  23. (should (equal '("a" "b") (org-split-string "|a|b|" "|")))
  24. ;; Pathological case: call on an empty string. Since empty parts
  25. ;; are not removed, it shouldn't return nil.
  26. (should (equal '("") (org-split-string "")))
  27. ;; SEPARATORS, when non-nil, is a regexp. In particular, do not
  28. ;; match more than specified.
  29. (should-not (equal '("a" "b") (org-split-string "a b" " ")))
  30. ;; When nil, SEPARATORS matches any number of blank characters.
  31. (should (equal '("a" "b") (org-split-string "a \t\nb"))))
  32. (ert-deftest test-org/string-display ()
  33. "Test `org-string-display' specifications."
  34. (should (equal "a" (org-string-display "a")))
  35. (should (equal "" (org-string-display "")))
  36. ;; Ignore invisible characters.
  37. (should (equal "" (org-string-display #("a" 0 1 (invisible t)))))
  38. (should (equal "b" (org-string-display #("ab" 0 1 (invisible t)))))
  39. (should (equal "a" (org-string-display #("ab" 1 2 (invisible t)))))
  40. (should (equal "ace" (org-string-display
  41. #("abcde" 1 2 (invisible t) 3 4 (invisible t)))))
  42. ;; Check if `invisible' value really means invisibility.
  43. (should (equal "" (let ((buffer-invisibility-spec t))
  44. (org-string-display #("a" 0 1 (invisible foo))))))
  45. (should (equal "" (let ((buffer-invisibility-spec '(foo)))
  46. (org-string-display #("a" 0 1 (invisible foo))))))
  47. (should (equal "" (let ((buffer-invisibility-spec '((foo . t))))
  48. (org-string-display #("a" 0 1 (invisible foo))))))
  49. (should (equal "a" (let ((buffer-invisibility-spec '(bar)))
  50. (org-string-display #("a" 0 1 (invisible foo))))))
  51. ;; Check `display' property.
  52. (should (equal "abc" (org-string-display #("a" 0 1 (display "abc")))))
  53. (should (equal "1abc3" (org-string-display #("1a3" 1 2 (display "abc")))))
  54. ;; `display' string can also contain invisible characters.
  55. (should (equal "1ac3" (org-string-display
  56. #("123" 1 2 (display #("abc" 1 2 (invisible t)))))))
  57. ;; Preserve other text properties when replacing with a display
  58. ;; string.
  59. (should
  60. (eq 'foo
  61. (get-text-property 1 'face
  62. (org-string-display
  63. #("123" 1 2 (display "abc" face foo))))))
  64. ;; Also preserve `display' property in original string.
  65. (should
  66. (equal "abc"
  67. (let ((s #("123" 1 2 (display "abc" face foo))))
  68. (org-string-display s)
  69. (get-text-property 1 'display s)))))
  70. ;;; Regexp
  71. (ert-deftest test-org/in-regexp ()
  72. "Test `org-in-regexp' specifications."
  73. ;; Standard tests.
  74. (should
  75. (org-test-with-temp-text "xx ab<point>c xx"
  76. (org-in-regexp "abc")))
  77. (should-not
  78. (org-test-with-temp-text "xx abc <point>xx"
  79. (org-in-regexp "abc")))
  80. ;; Return non-nil even with multiple matching regexps in the same
  81. ;; line.
  82. (should
  83. (org-test-with-temp-text "abc xx ab<point>c xx"
  84. (org-in-regexp "abc")))
  85. ;; With optional argument NLINES, check extra lines around point.
  86. (should-not
  87. (org-test-with-temp-text "A\nB<point>\nC"
  88. (org-in-regexp "A\nB\nC")))
  89. (should
  90. (org-test-with-temp-text "A\nB<point>\nC"
  91. (org-in-regexp "A\nB\nC" 1)))
  92. (should-not
  93. (org-test-with-temp-text "A\nB\nC<point>"
  94. (org-in-regexp "A\nB\nC" 1)))
  95. ;; When optional argument VISUALLY is non-nil, return nil if at
  96. ;; regexp boundaries.
  97. (should
  98. (org-test-with-temp-text "xx abc<point> xx"
  99. (org-in-regexp "abc")))
  100. (should-not
  101. (org-test-with-temp-text "xx abc<point> xx"
  102. (org-in-regexp "abc" nil t))))
  103. (provide 'test-org-macs)
  104. ;;; test-org-macs.el ends here