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