test-org-macs.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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-width ()
  33. "Test `org-string-width' specifications."
  34. (should (= 1 (org-string-width "a")))
  35. (should (= 0 (org-string-width "")))
  36. ;; Ignore invisible characters.
  37. (should (= 0 (org-string-width #("a" 0 1 (invisible t)))))
  38. (should (= 1 (org-string-width #("ab" 0 1 (invisible t)))))
  39. (should (= 1 (org-string-width #("ab" 1 2 (invisible t)))))
  40. (should (= 3 (org-string-width
  41. #("abcde" 1 2 (invisible t) 3 4 (invisible t)))))
  42. ;; Check if `invisible' value really means invisibility.
  43. (should (= 0 (let ((buffer-invisibility-spec t))
  44. (org-string-width #("a" 0 1 (invisible foo))))))
  45. (should (= 0 (let ((buffer-invisibility-spec '(foo)))
  46. (org-string-width #("a" 0 1 (invisible foo))))))
  47. (should (= 0 (let ((buffer-invisibility-spec '((foo . t))))
  48. (org-string-width #("a" 0 1 (invisible foo))))))
  49. (should (= 1 (let ((buffer-invisibility-spec '(bar)))
  50. (org-string-width #("a" 0 1 (invisible foo))))))
  51. ;; Check `display' property.
  52. (should (= 3 (org-string-width #("a" 0 1 (display "abc")))))
  53. (should (= 5 (org-string-width #("1a3" 1 2 (display "abc")))))
  54. ;; `display' string can also contain invisible characters.
  55. (should (= 4 (org-string-width
  56. #("123" 1 2 (display #("abc" 1 2 (invisible t)))))))
  57. ;; Test `space' property in `display'.
  58. (should (= 2 (org-string-width #(" " 0 1 (display (space :width 2)))))))
  59. ;;; Regexp
  60. (ert-deftest test-org/in-regexp ()
  61. "Test `org-in-regexp' specifications."
  62. ;; Standard tests.
  63. (should
  64. (org-test-with-temp-text "xx ab<point>c xx"
  65. (org-in-regexp "abc")))
  66. (should-not
  67. (org-test-with-temp-text "xx abc <point>xx"
  68. (org-in-regexp "abc")))
  69. ;; Return non-nil even with multiple matching regexps in the same
  70. ;; line.
  71. (should
  72. (org-test-with-temp-text "abc xx ab<point>c xx"
  73. (org-in-regexp "abc")))
  74. ;; With optional argument NLINES, check extra lines around point.
  75. (should-not
  76. (org-test-with-temp-text "A\nB<point>\nC"
  77. (org-in-regexp "A\nB\nC")))
  78. (should
  79. (org-test-with-temp-text "A\nB<point>\nC"
  80. (org-in-regexp "A\nB\nC" 1)))
  81. (should-not
  82. (org-test-with-temp-text "A\nB\nC<point>"
  83. (org-in-regexp "A\nB\nC" 1)))
  84. ;; When optional argument VISUALLY is non-nil, return nil if at
  85. ;; regexp boundaries.
  86. (should
  87. (org-test-with-temp-text "xx abc<point> xx"
  88. (org-in-regexp "abc")))
  89. (should-not
  90. (org-test-with-temp-text "xx abc<point> xx"
  91. (org-in-regexp "abc" nil t))))
  92. (provide 'test-org-macs)
  93. ;;; test-org-macs.el ends here