1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546 |
- ;;; test-org-colview.el --- Tests for org-colview.el -*- lexical-binding: t; -*-
- ;; Copyright (C) 2016, 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:
- ;;; Column view
- (require 'cl-lib)
- (require 'org-colview)
- (require 'org-duration)
- (require 'org-inlinetask)
- (ert-deftest test-org-colview/get-format ()
- "Test `org-columns-get-format' specifications."
- ;; Without any clue, use `org-columns-default-format'.
- (should
- (equal "%A"
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format)))))
- ;; If COLUMNS keyword is set, use it.
- (should
- (equal "%B"
- (org-test-with-temp-text "#+COLUMNS: %B\n* H"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format)))))
- (should
- (equal "%B"
- (org-test-with-temp-text "#+columns: %B\n* H"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format)))))
- (should
- (equal "%B"
- (org-test-with-temp-text "* H\n#+COLUMNS: %B"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format)))))
- ;; When :COLUMNS: property is set somewhere in the tree, use it over
- ;; the previous ways.
- (should
- (equal
- "%C"
- (org-test-with-temp-text
- "#+COLUMNS: %B\n* H\n:PROPERTIES:\n:COLUMNS: %C\n:END:\n** S\n<point>"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format)))))
- ;; When optional argument is provided, prefer it.
- (should
- (equal
- "%D"
- (org-test-with-temp-text
- "#+COLUMNS: %B\n* H\n:PROPERTIES:\n:COLUMNS: %C\n:END:\n** S\n<point>"
- (let ((org-columns-default-format "%A"))
- (org-columns-get-format "%D"))))))
- (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
- '("1" "1")
- (org-test-with-temp-text
- "Top\n* H1\n** <point>H2\n:PROPERTIES:\n:A: 1\n:END:"
- (let ((org-columns-default-format "%A{+}")) (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))
- (aref org-columns-current-maxwidths 0))))
- ;; 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))
- (aref org-columns-current-maxwidths 0))))
- ;; 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))
- (aref org-columns-current-maxwidths 0))))
- ;; Special case: stars do count for ITEM.
- (should
- (= 6
- (org-test-with-temp-text "* Head"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (aref org-columns-current-maxwidths 0))))
- ;; Special case: width takes into account link narrowing in ITEM.
- (should
- (equal
- '("* 123" . 5)
- (org-test-with-temp-text "* [[https://orgmode.org][123]]"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (cons (get-char-property (point) 'org-columns-value-modified)
- (aref org-columns-current-maxwidths 0)))))
- ;; 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))))))
- (ert-deftest test-org-colview/columns-summary ()
- "Test `org-columns' summary types."
- ;; {+} and {+;format} add numbers.
- (should
- (equal
- "3"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%A{+}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "3.0"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%A{+;%.1f}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {$} is a shortcut for {+;%.2f}.
- (should
- (equal
- "3.60"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1.50
- :END:
- ** S1
- :PROPERTIES:
- :A: 2.10
- :END:"
- (let ((org-columns-default-format "%A{$}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; Obey to format string even in leaf values.
- (should
- (equal
- "1.0"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:"
- (let ((org-columns-default-format "%A{+;%.1f}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {:} sums times. Plain numbers are minutes.
- (should
- (equal
- "4:10"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1:30
- :END:
- ** S1
- :PROPERTIES:
- :A: 2:40
- :END:"
- (let ((org-columns-default-format "%A{:}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "1:32"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1:30
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%A{:}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {X}, {X/} and {X%} indicate checkbox status.
- (should
- (equal
- "[ ]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:"
- (let ((org-columns-default-format "%A{X}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[-]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[X]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[1/2]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X/}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[50%]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X%}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {X/} handles recursive summaries.
- (should
- (equal
- "[1/2]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S2
- *** S21
- :PROPERTIES:
- :A: [X]
- :END:
- *** S22
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X/}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[1/2]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:
- ** S2
- *** S21
- :PROPERTIES:
- :A: [ ]
- :END:
- *** S22
- :PROPERTIES:
- :A: [ ]
- :END:"
- (let ((org-columns-default-format "%A{X/}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {X%} handles recursive summaries.
- (should
- (equal
- "[50%]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [ ]
- :END:
- ** S2
- *** S21
- :PROPERTIES:
- :A: [X]
- :END:
- *** S22
- :PROPERTIES:
- :A: [X]
- :END:"
- (let ((org-columns-default-format "%A{X%}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "[50%]"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: [X]
- :END:
- ** S2
- *** S21
- :PROPERTIES:
- :A: [ ]
- :END:
- *** S22
- :PROPERTIES:
- :A: [ ]
- :END:"
- (let ((org-columns-default-format "%A{X%}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {min} is the smallest number in column, {max} the largest one.
- ;; {mean} is the arithmetic mean of numbers in column.
- (should
- (equal
- "42"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 99
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A{min}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "99"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 99
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A{max}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "51.0"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 60
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A{mean}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {:min}, {:max} and {:mean} apply to time values.
- (should
- (equal
- "1:20"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 4:40
- :END:
- ** S1
- :PROPERTIES:
- :A: 1:20
- :END:"
- (let ((org-columns-default-format "%A{:min}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "4:40"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 4:40
- :END:
- ** S1
- :PROPERTIES:
- :A: 1:20
- :END:"
- (let ((org-columns-default-format "%A{:max}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "3:00"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 4:40
- :END:
- ** S1
- :PROPERTIES:
- :A: 1:20
- :END:"
- (let ((org-columns-default-format "%A{:mean}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {@min}, {@max} and {@mean} apply to ages.
- (should
- (equal
- "0min"
- (org-test-at-time "<2014-03-04 Tue>"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: <2012-03-29 Thu>
- :END:
- ** S1
- :PROPERTIES:
- :A: <2014-03-04 Tue>
- :END:"
- (let ((org-columns-default-format "%A{@min}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified)))))
- (should
- (equal
- "2d"
- (org-test-at-time "<2014-03-04 Tue>"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: <2014-03-03 Mon>
- :END:
- ** S1
- :PROPERTIES:
- :A: <2014-03-02 Sun>
- :END:"
- (let ((org-columns-default-format "%A{@max}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified)))))
- (should
- (equal
- "1d 12h"
- (org-test-at-time "<2014-03-04 Tue>"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: <2014-03-03 Mon>
- :END:
- ** S1
- :PROPERTIES:
- :A: <2014-03-02 Sun>
- :END:"
- (let ((org-columns-default-format "%A{@mean}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified)))))
- ;; If a time value is expressed as a duration, return a duration.
- ;; If any of them follows H:MM:SS pattern, use it too. Also handle
- ;; combinations of duration and H:MM:SS patterns.
- (should
- (equal
- "3d 4:20"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 3d 3h
- :END:
- ** S1
- :PROPERTIES:
- :A: 1:20
- :END:"
- (let ((org-columns-default-format "%A{:}")
- (org-duration-units '(("d" . 1440) ("h" . 60)))
- (org-duration-format '(("d" . nil) (special . h:mm))))
- (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "6:00:10"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 4:40:10
- :END:
- ** S1
- :PROPERTIES:
- :A: 1:20
- :END:"
- (let ((org-columns-default-format "%A{:}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- (should
- (equal
- "3d 4:20"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 3d 3h
- :END:
- ** S1
- :PROPERTIES:
- :A: 0d 1:20
- :END:"
- (let ((org-columns-default-format "%A{:}")
- (org-duration-units '(("d" . 1440) ("h" . 60)))
- (org-duration-format '(("d" . nil) (special . h:mm))))
- (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; @min, @max and @mean also accept regular duration.
- (should
- (equal
- "1d 10h"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1d 10h 0min
- :END:
- ** S1
- :PROPERTIES:
- :A: 5d 3h
- :END:"
- (let ((org-columns-default-format "%A{@min}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; {est+} gives a low-high estimate using mean and standard
- ;; deviation.
- (should
- (equal
- "3-17"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 0-10
- :END:
- ** S1
- :PROPERTIES:
- :A: 0-10
- :END:"
- (let ((org-columns-default-format "%A{est+}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; When using {est+} summary, a single number is understood as
- ;; a degenerate range.
- (should
- (equal
- "4-4"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 4
- :END:
- "
- (let ((org-columns-default-format "%A{est+}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; Allow custom summary types.
- (should
- (equal
- "1|2"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-summary-types
- '(("custom" . (lambda (s _) (mapconcat #'identity s "|")))))
- (org-columns-default-format "%A{custom}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; Allow custom _collect_ for summary types.
- (should
- (equal
- "2"
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :A-OK: 1
- :END:"
- (let ((org-columns-summary-types
- '(("custom" org-columns--summary-sum
- (lambda (p)
- (if (equal "1" (org-entry-get nil (format "%s-OK" p)))
- (org-entry-get nil p)
- "")))))
- (org-columns-default-format "%A{custom}")) (org-columns))
- (get-char-property (point) 'org-columns-value-modified))))
- ;; Allow custom collect function to be used for different columns
- (should
- (equal
- '("2" "1")
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :B: 1
- :B-OK: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :B: 2
- :A-OK: 1
- :END:"
- (let ((org-columns-summary-types
- '(("custom" org-columns--summary-sum
- (lambda (p)
- (if (equal "1" (org-entry-get nil (format "%s-OK" p)))
- (org-entry-get nil p)
- "")))))
- (org-columns-default-format "%A{custom} %B{custom}")) (org-columns))
- (list (get-char-property (point) 'org-columns-value-modified)
- (get-char-property (1+ (point)) 'org-columns-value-modified)))))
- ;; Allow multiple summary types applied to the same property.
- (should
- (equal
- '("42" "99")
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 99
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A{min} %A{max}")) (org-columns))
- (list (get-char-property (point) 'org-columns-value-modified)
- (get-char-property (1+ (point)) 'org-columns-value-modified)))))
- ;; Allow mixing both summarized and non-summarized columns for
- ;; a property. However, the first column takes precedence and
- ;; updates the value.
- (should
- (equal
- '("1000" "42")
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1000
- :END:
- ** S1
- :PROPERTIES:
- :A: 99
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A %A{min}")) (org-columns))
- (list (get-char-property (point) 'org-columns-value-modified)
- (get-char-property (1+ (point)) 'org-columns-value-modified)))))
- (should
- (equal
- '("42" "42")
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1000
- :END:
- ** S1
- :PROPERTIES:
- :A: 99
- :END:
- ** S1
- :PROPERTIES:
- :A: 42
- :END:"
- (let ((org-columns-default-format "%A{min} %A")) (org-columns))
- (list (get-char-property (point) 'org-columns-value-modified)
- (get-char-property (1+ (point)) 'org-columns-value-modified))))))
- (ert-deftest test-org-colview/columns-new ()
- "Test `org-columns-new' specifications."
- ;; Insert new column at the left of the current one.
- (should
- (equal '("FOO" "ITEM")
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (list (get-char-property (point) 'org-columns-key)
- (get-char-property (1+ (point)) 'org-columns-key)))))
- (should
- (equal '("ITEM" "FOO" "BAR")
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
- (forward-char)
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (list (get-char-property (1- (point)) 'org-columns-key)
- (get-char-property (point) 'org-columns-key)
- (get-char-property (1+ (point)) 'org-columns-key)))))
- ;; Update #+COLUMNS keyword if needed.
- (should
- (equal "#+COLUMNS: %FOO %ITEM"
- (org-test-with-temp-text "#+COLUMNS: %ITEM\n<point>* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position)))))
- (should
- (equal "#+COLUMNS: %ITEM %FOO %BAR"
- (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
- (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
- (forward-char)
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position)))))
- ;; Mind case when updating #+COLUMNS.
- (should
- (equal "#+COLUMNS: %ITEM %Foo %BAR"
- (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
- (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
- (forward-char)
- (org-columns-new nil "Foo" "Foo" nil nil nil)
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position)))))
- (should
- (equal "#+columns: %ITEM %Foo %BAR"
- (org-test-with-temp-text "#+columns: %ITEM %BAR\n<point>* H"
- (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
- (forward-char)
- (org-columns-new nil "Foo" "Foo" nil nil nil)
- (goto-char (point-min))
- (buffer-substring-no-properties (point) (line-end-position)))))
- ;; Also update :COLUMNS: properties.
- (should
- (equal "%FOO %ITEM"
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (org-entry-get nil "COLUMNS"))))
- ;; If no keyword nor any property is available, insert one.
- (should
- (string-match-p (regexp-quote "#+COLUMNS: %FOO %ITEM")
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-new nil "FOO" "FOO" nil nil nil)
- (buffer-string)))))
- (ert-deftest test-org-colview/columns-update ()
- "Test `org-columns-update' specifications."
- ;; Update display.
- (should
- (equal
- "12 |"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- "
- (let ((org-columns-default-format "%5A")) (org-columns))
- (search-forward "1")
- (insert "2")
- (org-columns-update "A")
- (get-char-property (point-min) 'display))))
- ;; Update is case-insensitive.
- (should
- (equal
- "12 |"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- "
- (let ((org-columns-default-format "%5A")) (org-columns))
- (search-forward "1")
- (insert "2")
- (org-columns-update "a")
- (get-char-property (point-min) 'display))))
- ;; Update stored values.
- (should
- (equal
- '("12" "12")
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- "
- (let ((org-columns-default-format "%5A")) (org-columns))
- (search-forward "1")
- (insert "2")
- (org-columns-update "A")
- (list (get-char-property (point-min) 'org-columns-value)
- (get-char-property (point-min) 'org-columns-value-modified)))))
- ;; When multiple columns are using the same property, value is
- ;; updated according to the specifications of the first one.
- (should
- (equal
- "2"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- ** S
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%A{min} %A")) (org-columns))
- (org-columns-update "A")
- (org-entry-get nil "A"))))
- (should
- (equal
- "1"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- ** S
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%A %A{min}")) (org-columns))
- (org-columns-update "A")
- (org-entry-get nil "A"))))
- ;; Ensure modifications propagate in upper levels even when multiple
- ;; summary types apply to the same property.
- (should
- (equal
- '("1" "22")
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S2
- :PROPERTIES:
- :A: <point>2
- :END:"
- (save-excursion
- (goto-char (point-min))
- (let ((org-columns-default-format "%A{min} %A{max}")) (org-columns)))
- (insert "2")
- (org-columns-update "A")
- (list (get-char-property 1 'org-columns-value)
- (get-char-property 2 'org-columns-value-modified)))))
- ;; Ensure additional processing is done (e.g., ellipses, special
- ;; keywords fontification...).
- (should
- (equal
- "ve.. |"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: text
- :END:
- "
- (let ((org-columns-default-format "%4A")
- (org-columns-ellipses ".."))
- (org-columns))
- (search-forward ":A: ")
- (insert "very long ")
- (org-columns-update "A")
- (get-char-property (point-min) 'display))))
- ;; Values obtained from inline tasks are at the same level as those
- ;; obtained from children of the current node.
- (when (featurep 'org-inlinetask)
- (should
- (equal
- "2"
- (org-test-with-temp-text
- "* H
- *************** Inline task
- :PROPERTIES:
- :A: 2
- :END:
- *************** END
- ** Children
- :PROPERTIES:
- :A: 3
- :END:
- "
- (let ((org-columns-default-format "%A{min}")
- (org-columns-ellipses "..")
- (org-inlinetask-min-level 15))
- (org-element-update-syntax)
- (org-columns))
- (get-char-property (point-min) 'org-columns-value)))))
- ;; Handle `org-columns-modify-value-for-display-function', even with
- ;; multiple titles for the same property.
- (should
- (equal '("foo" "bar")
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM %ITEM(Name)")
- (org-columns-modify-value-for-display-function
- (lambda (title _value)
- (pcase title ("ITEM" "foo") ("Name" "bar") (_ "baz")))))
- (org-columns))
- (list (get-char-property 1 'org-columns-value-modified)
- (get-char-property 2 'org-columns-value-modified))))))
- (ert-deftest test-org-colview/columns-move-left ()
- "Test `org-columns-move-left' specifications."
- ;; Error when trying to move the left-most column.
- (should-error
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-move-left)))
- ;; Otherwise, move column to left and update display.
- (should
- (equal '("2" "1")
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
- (let ((org-columns-default-format "%A %B")) (org-columns))
- (forward-char)
- (org-columns-move-left)
- (list (get-char-property (point) 'org-columns-value)
- (get-char-property (1+ (point)) 'org-columns-value)))))
- ;; Handle multiple columns with the same property.
- (should
- (equal '("2" "1")
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%ITEM %A{min} %A{max}"))
- (org-columns))
- (forward-char 2)
- (org-columns-move-left)
- (list (get-char-property (point) 'org-columns-value)
- (get-char-property (1+ (point)) 'org-columns-value)))))
- ;; Special case: do not update values even if move entails changing
- ;; them.
- (should
- (equal "1"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 99
- :END:"
- (let ((org-columns-default-format "%A %A{max}"))
- (org-columns))
- (forward-char)
- (org-columns-move-left)
- ;; Since the first column matching a given property
- ;; determines how a value is computed, the following
- ;; should return "99" instead. However, this behavior is
- ;; in practice surprising so we just ignore the value
- ;; change. It can be computed later.
- (org-entry-get (point) "A")))))
- (ert-deftest test-org-colview/columns-move-right ()
- "Test `org-columns-move-right' specifications."
- ;; Error when trying to move the right-most column.
- (should-error
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-move-right)))
- ;; Otherwise, move column to left and update display.
- (should
- (equal '("2" "1")
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
- (let ((org-columns-default-format "%A %B")) (org-columns))
- (org-columns-move-right)
- (list (get-char-property (1- (point)) 'org-columns-value)
- (get-char-property (point) 'org-columns-value)))))
- ;; Handle multiple columns with the same property.
- (should
- (equal '("2" "1")
- (org-test-with-temp-text
- "* H
- ** S1
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 2
- :END:"
- (let ((org-columns-default-format "%ITEM %A{min} %A{max}"))
- (org-columns))
- (forward-char)
- (org-columns-move-right)
- (list (get-char-property (1- (point)) 'org-columns-value)
- (get-char-property (point) 'org-columns-value)))))
- ;; Special case: do not update values even if move entails changing
- ;; them.
- (should
- (equal "1"
- (org-test-with-temp-text
- "* H
- :PROPERTIES:
- :A: 1
- :END:
- ** S1
- :PROPERTIES:
- :A: 99
- :END:"
- (let ((org-columns-default-format "%A %A{max}"))
- (org-columns))
- (org-columns-move-right)
- ;; See `test-org-colview/columns-move-left' for an
- ;; explanation.
- (org-entry-get (point) "A")))))
- (ert-deftest test-org-colview/columns-next-allowed-value ()
- "Test `org-columns-next-allowed-value' specifications."
- ;; Cannot shift "ITEM" property.
- (should-error
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM")) (org-columns))
- (org-columns-next-allowed-value)))
- ;; Throw an error when allowed values are not defined.
- (should-error
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value)))
- ;; Throw an error when there's only one value to select.
- (should-error
- (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value)))
- ;; By default select the next allowed value. Where there is no more
- ;; value, start again from first possible one.
- (should
- (equal "2"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value)
- (org-entry-get (point) "A"))))
- (should
- (equal "3"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value)
- (org-entry-get (point) "A"))))
- (should
- (equal "1"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 3\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value)
- (org-entry-get (point) "A"))))
- ;; PREVIOUS argument moves backward.
- (should
- (equal "1"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value 'previous)
- (org-entry-get (point) "A"))))
- (should
- (equal "2"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 3\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value 'previous)
- (org-entry-get (point) "A"))))
- (should
- (equal "3"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value 'previous)
- (org-entry-get (point) "A"))))
- ;; Select Nth element with optional argument NTH.
- (should
- (equal "1"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value nil 1)
- (org-entry-get (point) "A"))))
- ;; If NTH is negative, go backwards, 0 being the last one and -1 the
- ;; penultimate.
- (should
- (equal "3"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value nil 0)
- (org-entry-get (point) "A"))))
- (should
- (equal "2"
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value nil -1)
- (org-entry-get (point) "A"))))
- ;; Throw an error if NTH is greater than the number of allowed
- ;; values.
- (should-error
- (org-test-with-temp-text
- "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
- (let ((org-columns-default-format "%A")) (org-columns))
- (org-columns-next-allowed-value nil 4)
- (org-entry-get (point) "A")))
- ;; Pathological case: when shifting the value alters the current
- ;; heading, make sure all columns are still at their correct
- ;; location.
- (should
- (equal '("H" "" "" "" "TODO")
- (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
- (org-test-with-temp-text "* H"
- (let ((org-columns-default-format "%ITEM %A %B %C %TODO"))
- (org-columns)
- (forward-char 4)
- (org-columns-next-allowed-value)
- (list (get-char-property (- (point) 4) 'org-columns-value)
- (get-char-property (- (point) 3) 'org-columns-value)
- (get-char-property (- (point) 2) 'org-columns-value)
- (get-char-property (- (point) 1) 'org-columns-value)
- (get-char-property (point) 'org-columns-value)))))))
- (should
- (equal '("H" "VERYLONGTODO")
- (let ((org-todo-keywords '((sequence "TODO" "VERYLONGTODO"))))
- (org-test-with-temp-text "* TODO H"
- (let ((org-columns-default-format "%ITEM %TODO"))
- (org-columns)
- (forward-char)
- (org-columns-next-allowed-value)
- (list (get-char-property (- (point) 1) 'org-columns-value)
- (get-char-property (point) 'org-columns-value))))))))
- ;;; 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)))))
- (should
- (equal
- "#+BEGIN: columnview :hlines 1 :id \"id\"
- | ITEM |
- |------|
- | H2 |
- | H2.1 |
- #+END:
- "
- (org-test-with-temp-text
- "
- * H
- <point>#+BEGIN: columnview :hlines 1 :id \"id\"
- #+END:
- * H2
- :PROPERTIES:
- :ID: id
- :END:
- ** 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 id
- | ITEM |
- |------|
- | H2 |
- | H2.1 |
- #+END:
- "
- (org-test-with-temp-text
- "
- * H
- <point>#+BEGIN: columnview :hlines 1 :id id
- #+END:
- * H2
- :PROPERTIES:
- :ID: id
- :END:
- ** 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 `:exclude-tags' parameter.
- (should
- (equal
- "#+BEGIN: columnview :exclude-tags (\"excludeme\")
- | ITEM | A |
- |------+---|
- | H1 | |
- #+END:
- "
- (org-test-with-temp-text
- "
- * H1
- <point>#+BEGIN: columnview :exclude-tags (\"excludeme\")
- #+END:
- ** H1.1 :excludeme:
- :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)))))
- ;; 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)))))
- ;; Active time stamps are displayed as inactive.
- (should
- (equal
- "#+BEGIN: columnview
- | ITEM | d | s | t |
- |------+------------------+------------------+------------------|
- | H | [2020-05-14 Thu] | [2020-05-11 Mon] | [2020-06-10 Wed] |
- #+END:"
- (org-test-with-temp-text
- "* H
- SCHEDULED: <2020-05-11 Mon> DEADLINE: <2020-05-14 Thu>
- <2020-06-10 Wed>
- <point>#+BEGIN: columnview\n#+END:"
- (let ((org-columns-default-format
- "%ITEM %DEADLINE(d) %SCHEDULED(s) %TIMESTAMP(t)"))
- (org-update-dblock))
- (buffer-substring-no-properties (point) (point-max))))))
- (provide 'test-org-colview)
- ;;; test-org-colview.el ends here
|