mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
57fadf54a6 | |||
54a6eeaf1d |
56
tests/test-org-roam-link-replace.el
Normal file
56
tests/test-org-roam-link-replace.el
Normal file
@ -0,0 +1,56 @@
|
||||
;;; test-org-roam-link-replace.el --- Tests for Org-roam link replacement -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2025
|
||||
|
||||
;; Package-Requires: ((buttercup))
|
||||
|
||||
;; 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/>.
|
||||
|
||||
;;; Commentary:
|
||||
;; Tests for commits fc86387 and 89dfaef - link replacement optimization
|
||||
;;; Code:
|
||||
|
||||
(require 'buttercup)
|
||||
(require 'org-roam)
|
||||
(require 'org-roam-node)
|
||||
|
||||
(describe "org-roam-link-replace-all optimization"
|
||||
(before-all
|
||||
(setq org-roam-directory (expand-file-name "tests/roam-files")
|
||||
org-roam-db-location (expand-file-name "org-roam.db" temporary-file-directory))
|
||||
(org-roam-db-sync))
|
||||
|
||||
(after-all
|
||||
(org-roam-db--close)
|
||||
(delete-file org-roam-db-location))
|
||||
|
||||
(it "only processes roam: links, not other bracket links"
|
||||
(with-temp-buffer
|
||||
(org-mode)
|
||||
(insert "[[file:test.org][File]]\n[[roam:Foo]]\n[[https://example.com][Web]]")
|
||||
(let ((replace-count 0)
|
||||
(original-fn (symbol-function 'org-roam-link-replace-at-point)))
|
||||
;; Wrap the original function to count calls
|
||||
(cl-letf (((symbol-function 'org-roam-link-replace-at-point)
|
||||
(lambda ()
|
||||
(cl-incf replace-count)
|
||||
(funcall original-fn))))
|
||||
(org-roam-link-replace-all)
|
||||
;; Should only be called once, for the roam: link
|
||||
(expect replace-count :to-equal 1)
|
||||
(expect (buffer-string) :to-match "\\[\\[id:.*\\]\\[Foo\\]\\]"))))))
|
||||
|
||||
(provide 'test-org-roam-link-replace)
|
||||
|
||||
;;; test-org-roam-link-replace.el ends here
|
@ -73,14 +73,16 @@
|
||||
(expect (org-roam-node-title node) :to-equal "Bruce Wayne"))))
|
||||
|
||||
(describe "org-roam-demote-entire-buffer"
|
||||
(after-each
|
||||
(cd root-directory))
|
||||
|
||||
(it "demotes an entire org buffer"
|
||||
(find-file "tests/roam-files/demoteable.org" nil)
|
||||
(org-roam-demote-entire-buffer)
|
||||
(expect (buffer-substring-no-properties (point) (point-max))
|
||||
:to-equal "* Demoteable\n:PROPERTIES:\n:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734\n:END:\n\n** Demoteable h1\n\n*** Demoteable child\n")))
|
||||
;; Use a temporary copy to avoid interfering with other tests
|
||||
(let ((temp-file (make-temp-file "test-demoteable-" nil ".org")))
|
||||
(copy-file "tests/roam-files/demoteable.org" temp-file t)
|
||||
(find-file temp-file)
|
||||
(org-roam-demote-entire-buffer)
|
||||
(expect (buffer-substring-no-properties (point) (point-max))
|
||||
:to-equal "* Demoteable\n:PROPERTIES:\n:ID: 97bf31cf-dfee-45d8-87a5-2ae0dabc4734\n:END:\n\n** Demoteable h1\n\n*** Demoteable child\n")
|
||||
(kill-buffer)
|
||||
(delete-file temp-file))))
|
||||
|
||||
(describe "org-roam--h1-count"
|
||||
(after-each
|
||||
|
Reference in New Issue
Block a user