aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-config-tag-alignment.el
blob: e999f26131569cddd482a6a2c342b771c364cf30 (plain)
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
;;; test-org-config-tag-alignment.el --- Right-aligned org tags -*- lexical-binding: t; -*-

;;; Commentary:
;; cj/org-tag-line-re and cj/org--tag-align-spec drive the display-property
;; right-alignment of org headline tags (org-config.el).  The regexp isolates
;; the gap before the tags (group 1) and the tag string (group 2); the spec
;; helper turns a tag string into the (space :align-to (- right WIDTH)) display
;; spec that pins the tags to the window's right edge.  These exercise the pure
;; logic directly, without driving font-lock.

;;; Code:

(require 'ert)
(require 'org-config)

(ert-deftest test-org-config-tag-align-spec-single-tag ()
  "Normal: the spec pins a tag to the right edge less its width plus margin."
  (should (equal (cj/org--tag-align-spec ":work:")
                 `(space :align-to (- right ,(+ 6 cj/org-tag-right-margin))))))

(ert-deftest test-org-config-tag-align-spec-widths ()
  "Boundary: shortest and multi-tag strings carry their width plus the margin."
  (should (equal (cj/org--tag-align-spec ":a:")
                 `(space :align-to (- right ,(+ 3 cj/org-tag-right-margin)))))
  (should (equal (cj/org--tag-align-spec ":a:b:")
                 `(space :align-to (- right ,(+ 5 cj/org-tag-right-margin))))))

(ert-deftest test-org-config-tag-line-re-matches-tagged-heading ()
  "Normal: a tagged headline matches with the gap and tags captured."
  (let ((line "** TODO Something :work:"))
    (should (string-match cj/org-tag-line-re line))
    (should (equal (match-string 1 line) " "))
    (should (equal (match-string 2 line) ":work:"))))

(ert-deftest test-org-config-tag-line-re-captures-last-gap-with-padding ()
  "Boundary: with baked padding, group 1 is the single space before the tags."
  (let ((line "*** TODO [#C] Foo      :a:b:"))
    (should (string-match cj/org-tag-line-re line))
    (should (equal (match-string 1 line) " "))
    (should (equal (match-string 2 line) ":a:b:"))))

(ert-deftest test-org-config-tag-line-re-rejects-untagged-and-non-heading ()
  "Error: an untagged heading and a non-heading line do not match."
  (should-not (string-match cj/org-tag-line-re "** TODO Foo"))
  (should-not (string-match cj/org-tag-line-re "not a heading :work:")))

(provide 'test-org-config-tag-alignment)
;;; test-org-config-tag-alignment.el ends here