1 ;;; test-org-macs.el --- Tests for Org Macs library -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017 Nicolas Goaziou
5 ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 (ert-deftest test-org
/split-string
()
24 "Test `org-split-string' specifications."
26 (should (equal '("a" "b") (org-split-string "a b" " ")))
27 ;; Empty parts are not removed.
28 (should (equal '("a" "" "b") (org-split-string "a||b" "|")))
29 ;; However, empty parts at beginning or end of string are removed.
30 (should (equal '("a" "b") (org-split-string "|a|b|" "|")))
31 ;; Pathological case: call on an empty string. Since empty parts
32 ;; are not removed, it shouldn't return nil.
33 (should (equal '("") (org-split-string "")))
34 ;; SEPARATORS, when non-nil, is a regexp. In particular, do not
35 ;; match more than specified.
36 (should-not (equal '("a" "b") (org-split-string "a b" " ")))
37 ;; When nil, SEPARATORS matches any number of blank characters.
38 (should (equal '("a" "b") (org-split-string "a \t\nb"))))
40 (ert-deftest test-org
/string-display
()
41 "Test `org-string-display' specifications."
42 (should (equal "a" (org-string-display "a")))
43 (should (equal "" (org-string-display "")))
44 ;; Ignore invisible characters.
45 (should (equal "" (org-string-display #("a" 0 1 (invisible t
)))))
46 (should (equal "b" (org-string-display #("ab" 0 1 (invisible t
)))))
47 (should (equal "a" (org-string-display #("ab" 1 2 (invisible t
)))))
48 (should (equal "ace" (org-string-display
49 #("abcde" 1 2 (invisible t
) 3 4 (invisible t
)))))
50 ;; Check if `invisible' value really means invisibility.
51 (should (equal "" (let ((buffer-invisibility-spec t
))
52 (org-string-display #("a" 0 1 (invisible foo
))))))
53 (should (equal "" (let ((buffer-invisibility-spec '(foo)))
54 (org-string-display #("a" 0 1 (invisible foo
))))))
55 (should (equal "" (let ((buffer-invisibility-spec '((foo . t
))))
56 (org-string-display #("a" 0 1 (invisible foo
))))))
57 (should (equal "a" (let ((buffer-invisibility-spec '(bar)))
58 (org-string-display #("a" 0 1 (invisible foo
))))))
59 ;; Check `display' property.
60 (should (equal "abc" (org-string-display #("a" 0 1 (display "abc")))))
61 (should (equal "1abc3" (org-string-display #("1a3" 1 2 (display "abc")))))
62 ;; `display' string can also contain invisible characters.
63 (should (equal "1ac3" (org-string-display
64 #("123" 1 2 (display #("abc" 1 2 (invisible t
)))))))
65 ;; Preserve other text properties when replacing with a display
69 (get-text-property 1 'face
71 #("123" 1 2 (display "abc" face foo
))))))
72 ;; Also preserve `display' property in original string.
75 (let ((s #("123" 1 2 (display "abc" face foo
))))
76 (org-string-display s
)
77 (get-text-property 1 'display s
)))))
80 (provide 'test-org-macs
)
81 ;;; test-org-macs.el ends here