Skip to content

Commit

Permalink
Fix: Don't use org-element-at-point for Org stable based tests
Browse files Browse the repository at this point in the history
Note: As of today, the Org stable or bugfix version's (9.5.2)
`org-element-at-point' returns the Org element at point *but* without
any of the inherited properties!!

So `org-element-map' is used where property inheritance needs to be
tested (because that does do the prop inheritance as expected!). This
issue doesn't exist in the `main' branch version of
`org-element-at-point'.
  • Loading branch information
kaushalmodi committed Mar 17, 2022
1 parent 87fe8c6 commit 3299cfa
Showing 1 changed file with 60 additions and 48 deletions.
108 changes: 60 additions & 48 deletions test/ert/tslug.el
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@
(should
(equal nil
(org-test-with-parsed-data
"* <point>"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
"* <point>"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))

;; Heading with EXPORT_FILE_NAME.
(should
(equal nil
(org-test-with-parsed-data
"* Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
"* Some Heading<point>"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))

(ert-deftest test-slug/title ()
"Test slug when EXPORT_HUGO_SLUG is set."
;; EXPORT_FILE_NAME + EXPORT_HUGO_SLUG
(should
(string= "posts/slug"
(org-test-with-parsed-data
"* Some Heading<point>
"* Some Heading<point>
:PROPERTIES:
:EXPORT_FILE_NAME: file
:EXPORT_HUGO_SLUG: slug
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))

;; EXPORT_FILE_NAME + EXPORT_HUGO_SLUG + EXPORT_HUGO_SECTION
(should
(string= "section/slug"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -69,8 +69,8 @@
:EXPORT_FILE_NAME: file
:EXPORT_HUGO_SLUG: slug
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (nth 1 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info))))))

(ert-deftest test-slug/export-file-name ()
"Test derivation of the slug from EXPORT_FILE_NAME."
Expand All @@ -79,47 +79,48 @@
(should
(string= "posts/file"
(org-test-with-parsed-data
"* Some Heading<point>
"* Some Heading<point>
:PROPERTIES:
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))

;; EXPORT_FILE_NAME + EXPORT_HUGO_SECTION
(should
(string= "section/file"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:EXPORT_OPTIONS: toc:t
:END:
** Some Heading<point>
:PROPERTIES:
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (nth 1 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info))))))

;; Leaf bundles
(ert-deftest test-slug/leaf-bundles ()
"Test derivation of the slug leaf bundles."
(should
(string= "posts/leaf"
(org-test-with-parsed-data
"* Some Heading<point>
"* Some Heading<point>
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: leaf
:EXPORT_FILE_NAME: index
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))

;; Leaf bundle in a section
(should
(string= "section/leaf"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -128,57 +129,57 @@
:EXPORT_HUGO_BUNDLE: leaf
:EXPORT_FILE_NAME: index
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (nth 1 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info))))))

;; Branch bundles
(ert-deftest test-slug/branch-bundles ()
(should
(string= "posts/branch"
(org-test-with-parsed-data
"* Some Heading<point>
"* Some Heading<point>
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: branch
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))

;; Inherit :EXPORT_HUGO_BUNDLE
(should
(string= "posts/branch"
(org-test-with-parsed-data
"* Branch bundle
"* Branch bundle
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: branch
:END:
** Landing page<point>
:PROPERTIES:
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (nth 1 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info)))))

;; Page in branch bundle, inheritance
(should
(string= "posts/branch/branch-page"
(org-test-with-parsed-data
"* Branch bundle
"* Branch bundle
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: branch
:END:
** Branch page<point>
:PROPERTIES:
:EXPORT_FILE_NAME: branch-page
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (nth 1 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info)))))

;; Branch bundle in a section
(should
(string= "section/branch"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -190,14 +191,14 @@
:PROPERTIES:
:EXPORT_FILE_NAME: _index
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (nth 2 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info)))))

;; Branch page in a branch bundle in a section
(should
(string= "section/branch/branch-page"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -209,8 +210,8 @@
:PROPERTIES:
:EXPORT_FILE_NAME: branch-page
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (nth 2 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info))))))

;; Section
(ert-deftest test-slug/section ()
Expand All @@ -219,21 +220,21 @@
(should
(string= "section/file"
(org-test-with-parsed-data
"#+hugo_section: section
"#+hugo_section: section
* Some Heading<point>
:PROPERTIES:
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))

;; Section fragments
(ert-deftest test-slug/section-fragments ()

(should
(string= "section/sec2/sec3/file"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -249,14 +250,14 @@
:PROPERTIES:
:EXPORT_FILE_NAME: file
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info)))))
(let ((el (nth 3 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info)))))

;; Branch page in a branch bundle in section fragments.
(should
(string= "section/sec2/sec3/branch/branch-page"
(org-test-with-parsed-data
"* Section
"* Section
:PROPERTIES:
:EXPORT_HUGO_SECTION: section
:END:
Expand All @@ -277,8 +278,19 @@
:PROPERTIES:
:EXPORT_FILE_NAME: branch-page
:END:"
(let ((el (org-element-at-point)))
(org-hugo--heading-get-slug el info))))))
(let ((el (nth 4 (org-element-map tree 'headline #'identity info))))
(org-hugo--heading-get-slug el info))))))


(provide 'tslug)

;; Note: As of 2022-03-17, Org stable or bugfix version's (9.5.2)
;; `org-element-at-point' returns the Org element at point *but*
;; without any of the inherited properties. So `org-element-map' is
;; used where property inheritance needs to be tested (because that
;; does do the prop inheritance as expected!). This issue doesn't
;; exist in the `main' branch version of `org-element-at-point'.
;;
;; To get the 1st heading element: (nth 0 (org-element-map tree 'headline #'identity info))
;; To get the 2nd heading element: (nth 1 (org-element-map tree 'headline #'identity info))
;; ..

0 comments on commit 3299cfa

Please sign in to comment.