123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- ;;; test-org-colview.el --- Tests for org-colview.el -*- lexical-binding: t; -*-
- ;; Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
- ;;; Code:
- ;;; Column view
- (ert-deftest test-org-colview/columns-scope ()
- "Test `org-columns' scope."
- ;; Before the first headline, view all document.
- (should
- (equal
- '("H1" "H2" "H3")
- (org-test-with-temp-text "Top\n* H1\n** H2\n* H3"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-map-entries
- (lambda () (get-char-property (point) 'org-columns-value))))))
- ;; When :COLUMNS: is set up in the hierarchy, view tree starting
- ;; there.
- (should
- (equal
- '(nil "H2" "H3" nil)
- (org-test-with-temp-text
- "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-map-entries
- (lambda () (get-char-property (point) 'org-columns-value))))))
- ;; Otherwise, view tree starting at the current headline.
- (should
- (equal
- '(nil "H2" "H3" nil)
- (org-test-with-temp-text "Top\n* H1\n** <point>H2\n*** H3\n* H4"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-map-entries
- (lambda () (get-char-property (point) 'org-columns-value))))))
- ;; With a non-nil prefix argument, always view all document.
- (should
- (equal
- '("H1" "H2" "H3" "H4")
- (org-test-with-temp-text
- "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
- (let ((org-columns-default-format "%ITEM")) (org-columns t))
- (org-map-entries
- (lambda () (get-char-property (point) 'org-columns-value))))))
- (should
- (equal
- '("H1" "H2" "H3" "H4")
- (org-test-with-temp-text "Top\n* H1\n** <point>H2\n*** H3\n* H4"
- (let ((org-columns-default-format "%ITEM")) (org-columns t))
- (org-map-entries
- (lambda () (get-char-property (point) 'org-columns-value)))))))
- (ert-deftest test-org-colview/columns-width ()
- "Test `org-columns' column widths."
- ;; When a width is specified in the format, use it.
- (should
- (= 9
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%9ITEM")) (org-columns))
- (cdar org-columns-current-maxwidths))))
- ;; Otherwise, use the width of the largest value in the column.
- (should
- (= 2
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:P: X\n:END:\n** H2\n:PROPERTIES:\n:P: XX\n:END:"
- (let ((org-columns-default-format "%P")) (org-columns))
- (cdar org-columns-current-maxwidths))))
- ;; If the title is wider than the widest value, use title width
- ;; instead.
- (should
- (= 4
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (cdar org-columns-current-maxwidths))))
- ;; Special case: stars do count for ITEM.
- (should
- (= 6
- (org-test-with-temp-text "* Head"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (cdar org-columns-current-maxwidths))))
- ;; Special case: width takes into account link narrowing in ITEM.
- (should
- (equal
- '("* [123]" . 7)
- (org-test-with-temp-text "* [[http://orgmode.org][123]]"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (cons (get-char-property (point) 'org-columns-value-modified)
- (cdar org-columns-current-maxwidths)))))
- ;; When a value is too wide for the current column, add ellipses.
- ;; Take into consideration length of `org-columns-ellipses'.
- (should
- (equal "123.. |"
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
- (let ((org-columns-default-format "%5P")
- (org-columns-ellipses ".."))
- (org-columns))
- (org-trim (get-char-property (point) 'display)))))
- (should
- (equal "1234… |"
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
- (let ((org-columns-default-format "%5P")
- (org-columns-ellipses "…"))
- (org-columns))
- (org-trim (get-char-property (point) 'display))))))
- ;;; Dynamic block
- (ert-deftest test-org-colview/dblock ()
- "Test the column view table."
- (should
- (equal
- "#+BEGIN: columnview
- | ITEM |
- |------|
- | H |
- #+END:"
- (org-test-with-temp-text
- "* H\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- (should
- (equal
- "#+BEGIN: columnview
- | ITEM | A |
- |------+---|
- | H | 1 |
- #+END:"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; Properties are case insensitive.
- (should
- (equal
- "#+BEGIN: columnview
- | a |
- |---|
- | 1 |
- #+END:"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%a")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; Test titles given to columns.
- (should
- (equal
- "#+BEGIN: columnview
- | Name | Prop |
- |------+------|
- | H | 1 |
- #+END:"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%ITEM(Name) %A(Prop)"))
- (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; Test `:id' parameter
- (should
- (equal
- "#+BEGIN: columnview :id local
- | ITEM |
- |------|
- | H1 |
- | H1.1 |
- #+END:
- "
- (org-test-with-temp-text
- "* H1\n<point>#+BEGIN: columnview :id local\n#+END:\n** H1.1\n* H2"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- (should
- (equal
- "#+BEGIN: columnview :id global
- | ITEM |
- |------|
- | H1 |
- | H1.1 |
- | H2 |
- #+END:
- "
- (org-test-with-temp-text
- "\n* H1\n<point>#+BEGIN: columnview :id global\n#+END:\n** H1.1\n* H2"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- ;; Test `:hlines' parameter.
- (should
- (equal
- "#+BEGIN: columnview :hlines t :id global
- | ITEM |
- |------|
- | H |
- |------|
- | H2 |
- |------|
- | H2.1 |
- #+END:\n"
- (org-test-with-temp-text
- "
- * H
- <point>#+BEGIN: columnview :hlines t :id global
- #+END:
- * H2
- ** H2.1"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- (should
- (equal
- "#+BEGIN: columnview :hlines 1 :id global
- | ITEM |
- |------|
- | H |
- |------|
- | H2 |
- | H2.1 |
- #+END:\n"
- (org-test-with-temp-text
- "
- * H
- <point>#+BEGIN: columnview :hlines 1 :id global
- #+END:
- * H2
- ** H2.1"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- ;; Test `:indent' parameter.
- (should
- (equal
- "#+BEGIN: columnview :indent t
- | ITEM |
- |----------|
- | H1 |
- | \\_ H1.1 |
- #+END:
- "
- (org-test-with-temp-text
- "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- (should
- (equal
- "#+BEGIN: columnview :indent t
- | Prop | Name |
- |------+----------|
- | | H1 |
- | | \\_ H1.1 |
- #+END:
- "
- (org-test-with-temp-text
- "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
- (let ((org-columns-default-format "%A(Prop) %ITEM(Name)"))
- (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- ;; Test `:vlines' parameter.
- (should
- (equal
- "#+BEGIN: columnview :vlines t
- | | ITEM | A |
- |---+------+----|
- | | H | 1 |
- | / | <> | <> |
- #+END:"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview :vlines t\n#+END:"
- (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; Test `:skip-empty-rows' parameter.
- (should
- (equal
- "#+BEGIN: columnview :skip-empty-rows t
- | ITEM | A |
- |------+---|
- | H1.1 | 1 |
- #+END:
- "
- (org-test-with-temp-text
- "
- * H1
- <point>#+BEGIN: columnview :skip-empty-rows t
- #+END:
- ** H1.1
- :PROPERTIES:
- :A: 1
- :END:"
- (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
- (buffer-substring-no-properties (point) (outline-next-heading)))))
- ;; Test `:format' parameter.
- (should
- (equal
- "#+BEGIN: columnview :format \"%ITEM(Name)\"
- | Name |
- |------|
- | H |
- #+END:"
- (org-test-with-temp-text
- "* H\n<point>#+BEGIN: columnview :format \"%ITEM(Name)\"\n#+END:"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; Test `:width' parameter
- (should
- (equal
- "#+BEGIN: columnview :width t
- | ITEM | A |
- |------------+---|
- | H | |
- | <10> | |
- #+END:"
- (org-test-with-temp-text
- "* H\n<point>#+BEGIN: columnview :width t\n#+END:"
- (let ((org-columns-default-format "%10ITEM %A")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- ;; When inserting ITEM values, make sure to clean sensitive
- ;; contents, like unique targets or forbidden inline src-blocks.
- (should
- (equal
- "#+BEGIN: columnview
- | ITEM |
- |------|
- | H 1 |
- #+END:"
- (org-test-with-temp-text
- "* H <<target>> 1\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max)))))
- (should
- (equal
- "#+BEGIN: columnview
- | ITEM |
- |------|
- | H 1 |
- #+END:"
- (org-test-with-temp-text
- "* H src_emacs-lisp{(+ 1 1)} 1\n<point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max))))))
- (provide 'test-org-colview)
- ;;; test-org-colview.el ends here
|