lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / testing / lisp / test-org-macs.el
blob7db17cc37619ae616592c53d868ab27f2fb68a95
1 ;;; test-org-macs.el --- Tests for Org Macs library -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2017, 2019 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-width ()
43 "Test `org-string-width' specifications."
44 (should (= 1 (org-string-width "a")))
45 (should (= 0 (org-string-width "")))
46 ;; Ignore invisible characters.
47 (should (= 0 (org-string-width #("a" 0 1 (invisible t)))))
48 (should (= 1 (org-string-width #("ab" 0 1 (invisible t)))))
49 (should (= 1 (org-string-width #("ab" 1 2 (invisible t)))))
50 (should (= 3 (org-string-width
51 #("abcde" 1 2 (invisible t) 3 4 (invisible t)))))
52 ;; Check if `invisible' value really means invisibility.
53 (should (= 0 (let ((buffer-invisibility-spec t))
54 (org-string-width #("a" 0 1 (invisible foo))))))
55 (should (= 0 (let ((buffer-invisibility-spec '(foo)))
56 (org-string-width #("a" 0 1 (invisible foo))))))
57 (should (= 0 (let ((buffer-invisibility-spec '((foo . t))))
58 (org-string-width #("a" 0 1 (invisible foo))))))
59 (should (= 1 (let ((buffer-invisibility-spec '(bar)))
60 (org-string-width #("a" 0 1 (invisible foo))))))
61 ;; Check `display' property.
62 (should (= 3 (org-string-width #("a" 0 1 (display "abc")))))
63 (should (= 5 (org-string-width #("1a3" 1 2 (display "abc")))))
64 ;; `display' string can also contain invisible characters.
65 (should (= 4 (org-string-width
66 #("123" 1 2 (display #("abc" 1 2 (invisible t)))))))
67 ;; Test `space' property in `display'.
68 (should (= 2 (org-string-width #(" " 0 1 (display (space :width 2)))))))
71 ;;; Regexp
73 (ert-deftest test-org/in-regexp ()
74 "Test `org-in-regexp' specifications."
75 ;; Standard tests.
76 (should
77 (org-test-with-temp-text "xx ab<point>c xx"
78 (org-in-regexp "abc")))
79 (should-not
80 (org-test-with-temp-text "xx abc <point>xx"
81 (org-in-regexp "abc")))
82 ;; Return non-nil even with multiple matching regexps in the same
83 ;; line.
84 (should
85 (org-test-with-temp-text "abc xx ab<point>c xx"
86 (org-in-regexp "abc")))
87 ;; With optional argument NLINES, check extra lines around point.
88 (should-not
89 (org-test-with-temp-text "A\nB<point>\nC"
90 (org-in-regexp "A\nB\nC")))
91 (should
92 (org-test-with-temp-text "A\nB<point>\nC"
93 (org-in-regexp "A\nB\nC" 1)))
94 (should-not
95 (org-test-with-temp-text "A\nB\nC<point>"
96 (org-in-regexp "A\nB\nC" 1)))
97 ;; When optional argument VISUALLY is non-nil, return nil if at
98 ;; regexp boundaries.
99 (should
100 (org-test-with-temp-text "xx abc<point> xx"
101 (org-in-regexp "abc")))
102 (should-not
103 (org-test-with-temp-text "xx abc<point> xx"
104 (org-in-regexp "abc" nil t))))
106 (provide 'test-org-macs)
107 ;;; test-org-macs.el ends here