test-org-macs.el 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. (ert-deftest test-org/split-string ()
  16. "Test `org-split-string' specifications."
  17. ;; Regular test.
  18. (should (equal '("a" "b") (org-split-string "a b" " ")))
  19. ;; Empty parts are not removed.
  20. (should (equal '("a" "" "b") (org-split-string "a||b" "|")))
  21. ;; However, empty parts at beginning or end of string are removed.
  22. (should (equal '("a" "b") (org-split-string "|a|b|" "|")))
  23. ;; Pathological case: call on an empty string. Since empty parts
  24. ;; are not removed, it shouldn't return nil.
  25. (should (equal '("") (org-split-string "")))
  26. ;; SEPARATORS, when non-nil, is a regexp. In particular, do not
  27. ;; match more than specified.
  28. (should-not (equal '("a" "b") (org-split-string "a b" " ")))
  29. ;; When nil, SEPARATORS matches any number of blank characters.
  30. (should (equal '("a" "b") (org-split-string "a \t\nb"))))
  31. (ert-deftest test-org/string-display ()
  32. "Test `org-string-display' specifications."
  33. (should (equal "a" (org-string-display "a")))
  34. (should (equal "" (org-string-display "")))
  35. ;; Ignore invisible characters.
  36. (should (equal "" (org-string-display #("a" 0 1 (invisible t)))))
  37. (should (equal "b" (org-string-display #("ab" 0 1 (invisible t)))))
  38. (should (equal "a" (org-string-display #("ab" 1 2 (invisible t)))))
  39. (should (equal "ace" (org-string-display
  40. #("abcde" 1 2 (invisible t) 3 4 (invisible t)))))
  41. ;; Check if `invisible' value really means invisibility.
  42. (should (equal "" (let ((buffer-invisibility-spec t))
  43. (org-string-display #("a" 0 1 (invisible foo))))))
  44. (should (equal "" (let ((buffer-invisibility-spec '(foo)))
  45. (org-string-display #("a" 0 1 (invisible foo))))))
  46. (should (equal "" (let ((buffer-invisibility-spec '((foo . t))))
  47. (org-string-display #("a" 0 1 (invisible foo))))))
  48. (should (equal "a" (let ((buffer-invisibility-spec '(bar)))
  49. (org-string-display #("a" 0 1 (invisible foo))))))
  50. ;; Check `display' property.
  51. (should (equal "abc" (org-string-display #("a" 0 1 (display "abc")))))
  52. (should (equal "1abc3" (org-string-display #("1a3" 1 2 (display "abc")))))
  53. ;; `display' string can also contain invisible characters.
  54. (should (equal "1ac3" (org-string-display
  55. #("123" 1 2 (display #("abc" 1 2 (invisible t)))))))
  56. ;; Preserve other text properties when replacing with a display
  57. ;; string.
  58. (should
  59. (eq 'foo
  60. (get-text-property 1 'face
  61. (org-string-display
  62. #("123" 1 2 (display "abc" face foo))))))
  63. ;; Also preserve `display' property in original string.
  64. (should
  65. (equal "abc"
  66. (let ((s #("123" 1 2 (display "abc" face foo))))
  67. (org-string-display s)
  68. (get-text-property 1 'display s)))))
  69. (provide 'test-org-macs)
  70. ;;; test-org-macs.el ends here