test-org-macs.el 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ;;; Regexp
  58. (ert-deftest test-org/in-regexp ()
  59. "Test `org-in-regexp' specifications."
  60. ;; Standard tests.
  61. (should
  62. (org-test-with-temp-text "xx ab<point>c xx"
  63. (org-in-regexp "abc")))
  64. (should-not
  65. (org-test-with-temp-text "xx abc <point>xx"
  66. (org-in-regexp "abc")))
  67. ;; Return non-nil even with multiple matching regexps in the same
  68. ;; line.
  69. (should
  70. (org-test-with-temp-text "abc xx ab<point>c xx"
  71. (org-in-regexp "abc")))
  72. ;; With optional argument NLINES, check extra lines around point.
  73. (should-not
  74. (org-test-with-temp-text "A\nB<point>\nC"
  75. (org-in-regexp "A\nB\nC")))
  76. (should
  77. (org-test-with-temp-text "A\nB<point>\nC"
  78. (org-in-regexp "A\nB\nC" 1)))
  79. (should-not
  80. (org-test-with-temp-text "A\nB\nC<point>"
  81. (org-in-regexp "A\nB\nC" 1)))
  82. ;; When optional argument VISUALLY is non-nil, return nil if at
  83. ;; regexp boundaries.
  84. (should
  85. (org-test-with-temp-text "xx abc<point> xx"
  86. (org-in-regexp "abc")))
  87. (should-not
  88. (org-test-with-temp-text "xx abc<point> xx"
  89. (org-in-regexp "abc" nil t))))
  90. (provide 'test-org-macs)
  91. ;;; test-org-macs.el ends here