emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob c32d891a2b77db6a8e701006729a05ee586595b7 5766 bytes (raw)
name: testing/lisp/test-org-macs.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
 
;;; test-org-macs.el --- Tests for Org Macs library  -*- lexical-binding: t; -*-

;; Copyright (C) 2017, 2019  Nicolas Goaziou

;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Code:

\f
;;; String manipulation

(ert-deftest test-org/split-string ()
  "Test `org-split-string' specifications."
  ;; Regular test.
  (should (equal '("a" "b") (org-split-string "a b" " ")))
  ;; Empty parts are not removed.
  (should (equal '("a" "" "b") (org-split-string "a||b" "|")))
  ;; However, empty parts at beginning or end of string are removed.
  (should (equal '("a" "b") (org-split-string "|a|b|" "|")))
  ;; Pathological case: call on an empty string.  Since empty parts
  ;; are not removed, it shouldn't return nil.
  (should (equal '("") (org-split-string "")))
  ;; SEPARATORS, when non-nil, is a regexp.  In particular, do not
  ;; match more than specified.
  (should-not (equal '("a" "b") (org-split-string "a    b" " ")))
  ;; When nil, SEPARATORS matches any number of blank characters.
  (should (equal '("a" "b") (org-split-string "a \t\nb"))))

(ert-deftest test-org/string-width ()
  "Test `org-string-width' specifications."
  (should (= 1 (org-string-width "a")))
  (should (= 0 (org-string-width "")))
  ;; Ignore invisible characters.
  (should (= 0 (org-string-width #("a" 0 1 (invisible t)))))
  (should (= 1 (org-string-width #("ab" 0 1 (invisible t)))))
  (should (= 1 (org-string-width #("ab" 1 2 (invisible t)))))
  (should (= 3 (org-string-width
		#("abcde" 1 2 (invisible t) 3 4 (invisible t)))))
  ;; Check if `invisible' value really means invisibility.
  (should (= 0 (let ((buffer-invisibility-spec t))
                 (org-string-width #("a" 0 1 (invisible foo))))))
  (should (= 0 (let ((buffer-invisibility-spec '(foo)))
                 (org-string-width #("a" 0 1 (invisible foo))))))
  (should (= 0 (let ((buffer-invisibility-spec '((foo . t))))
                 (org-string-width #("a" 0 1 (invisible foo))))))
  (should (= 1 (let ((buffer-invisibility-spec '(bar)))
                 (org-string-width #("a" 0 1 (invisible foo))))))
  ;; Check `display' property.
  (should (= 3 (org-string-width #("a" 0 1 (display "abc")))))
  (should (= 5 (org-string-width #("1a3" 1 2 (display "abc")))))
  ;; `display' string can also contain invisible characters.
  (should (= 4 (org-string-width
		#("123" 1 2 (display #("abc" 1 2 (invisible t)))))))
  ;; Test `space' property in `display'.
  (should (= 2 (org-string-width #(" " 0 1 (display (space :width 2)))))))

\f
;;; Regexp

(ert-deftest test-org/in-regexp ()
  "Test `org-in-regexp' specifications."
  ;; Standard tests.
  (should
   (org-test-with-temp-text "xx ab<point>c xx"
     (org-in-regexp "abc")))
  (should-not
   (org-test-with-temp-text "xx abc <point>xx"
     (org-in-regexp "abc")))
  ;; Return non-nil even with multiple matching regexps in the same
  ;; line.
  (should
   (org-test-with-temp-text "abc xx ab<point>c xx"
     (org-in-regexp "abc")))
  ;; With optional argument NLINES, check extra lines around point.
  (should-not
   (org-test-with-temp-text "A\nB<point>\nC"
     (org-in-regexp "A\nB\nC")))
  (should
   (org-test-with-temp-text "A\nB<point>\nC"
     (org-in-regexp "A\nB\nC" 1)))
  (should-not
   (org-test-with-temp-text "A\nB\nC<point>"
     (org-in-regexp "A\nB\nC" 1)))
  ;; When optional argument VISUALLY is non-nil, return nil if at
  ;; regexp boundaries.
  (should
   (org-test-with-temp-text "xx abc<point> xx"
     (org-in-regexp "abc")))
  (should-not
   (org-test-with-temp-text "xx abc<point> xx"
     (org-in-regexp "abc" nil t))))
\f
;;; Template

(ert-deftest test-org/fill-template ()
  "Test `org-fill-template'"
  (should
   (string= "working"
            (org-fill-template "%var-long"
                               '(("var" . "broken")
                                 ("var-long" . "working"))))))
\f
;;; Time

(ert-deftest test-org-matcher-time ()
  "Test `org-matcher-time'."
  (let ((system-time-locale "en_US"))
    (org-test-at-time "<2021-01-11 Mon 13:00>"
      (should (equal (list 0 0 13 11 1 2021)
                     (butlast (decode-time (org-matcher-time "<now>"))
                              3)))
      (should (equal (list 0 0 0 14 1 2021)
                     (butlast (decode-time (org-matcher-time "<+3d>"))
                              3)))
      (should (equal (list 0 0 0 9 1 2021)
                     (butlast (decode-time (org-matcher-time "<-2d>"))
                              3)))
      (should (equal (list 0 0 0 18 1 2021)
                     (butlast (decode-time (org-matcher-time "<+1w>"))
                              3)))
      (should (equal (list 0 0 17 11 1 2021)
                     (butlast (decode-time (org-matcher-time "<+4h>"))
                              3)))
      (should (equal (list 0 0 11 11 1 2021)
                     (butlast (decode-time (org-matcher-time "<-2h>"))
                              3)))
      (should (equal (list 0 0 3 12 1 2021)
                     (butlast (decode-time (org-matcher-time "<+14h>"))
                              3))))))

(provide 'test-org-macs)
;;; test-org-macs.el ends here

debug log:

solving c32d891a2 ...
found c32d891a2 in https://list.orgmode.org/orgmode/b098cbaf-e9fe-81f6-18ec-796b410ca2a6@ooblick.com/
found 6a7ccea3c in https://git.savannah.gnu.org/cgit/emacs/org-mode.git
preparing index
index prepared:
100644 6a7ccea3c133df7f81d4cee8807302d1708961c3	testing/lisp/test-org-macs.el

applying [1/1] https://list.orgmode.org/orgmode/b098cbaf-e9fe-81f6-18ec-796b410ca2a6@ooblick.com/
diff --git a/testing/lisp/test-org-macs.el b/testing/lisp/test-org-macs.el
index 6a7ccea3c..c32d891a2 100644

Checking patch testing/lisp/test-org-macs.el...
Applied patch testing/lisp/test-org-macs.el cleanly.

index at:
100644 c32d891a2b77db6a8e701006729a05ee586595b7	testing/lisp/test-org-macs.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).