Clean up tests with a fixture macro

This commit is contained in:
Correl Roush 2022-06-12 18:01:39 -04:00
parent 8ad5456526
commit 841202288a

View file

@ -36,10 +36,9 @@
(should (equal '("id:d12a1ce4-3199-42f4-b39b-b68c03458669") (should (equal '("id:d12a1ce4-3199-42f4-b39b-b68c03458669")
(mapcar #'org-roam-export-backlink-link (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t))))) (mapcar #'org-roam-export-backlink-link (org-roam-backlinks-get (org-roam-node-from-id "e6c17c1a-6b05-40d2-a01f-b147633c51b1") :unique t)))))
(ert-deftest excerpt-tests () (defmacro with-test-document (&rest body)
`(with-temp-buffer
(with-temp-buffer (org-mode)
(org-mode)
(insert ":PROPERTIES: (insert ":PROPERTIES:
:ID: e44c8b00-f90d-4fcc-b8a1-742b659ff252 :ID: e44c8b00-f90d-4fcc-b8a1-742b659ff252
:END :END
@ -60,24 +59,38 @@ Opening paragraph.
Heading two paragraph. Heading two paragraph.
") ")
;; Elements ,@body))
(goto-line 6)
(should (equal "Opening paragraph.\n" (org-roam-export--excerpt))) (ert-deftest excerpt-opening-paragraph-test ()
(goto-line 10) (with-test-document
(should (equal " Heading one paragraph.\n" (org-roam-export--excerpt))) (goto-line 6)
(should (equal "Opening paragraph.\n" (org-roam-export--excerpt)))))
(ert-deftest excerpt-heading-paragraph-test ()
(with-test-document
(goto-line 10)
(should (equal " Heading one paragraph.\n" (org-roam-export--excerpt)))))
(ert-deftest excerpt-list-test ()
(with-test-document
(goto-line 14) (goto-line 14)
(should (equal " - List item 1\n - List item 2\n" (org-roam-export--excerpt))) (should (equal " - List item 1\n - List item 2\n" (org-roam-export--excerpt)))))
;; Headings
(goto-line 8) (ert-deftest excerpt-heading-with-subheadings-test ()
(with-test-document
(goto-line 8)
(should (equal " Heading one paragraph. (should (equal " Heading one paragraph.
** Subheading One A ** Subheading One A
- List item 1 - List item 1
- List item 2 - List item 2
" (org-roam-export--excerpt))) " (org-roam-export--excerpt)))))
(goto-line 17)
(should (equal " Heading two paragraph.\n" (org-roam-export--excerpt))))) (ert-deftest excerpt-simple-heading-test ()
(with-test-document
(goto-line 17)
(should (equal " Heading two paragraph.\n" (org-roam-export--excerpt)))))
(ert-deftest lorem-backlink-excerpt () (ert-deftest lorem-backlink-excerpt ()
(should (equal '("Aliquam [[id:d12a1ce4-3199-42f4-b39b-b68c03458669][lorem]] ante, suscipit a lorem molestie, aliquet elementum eros. Proin (should (equal '("Aliquam [[id:d12a1ce4-3199-42f4-b39b-b68c03458669][lorem]] ante, suscipit a lorem molestie, aliquet elementum eros. Proin