Compare commits

...

2 Commits

Author SHA1 Message Date
57fadf54a6 test: add tests for link replacement optimization
Added integration tests for the roam link replacement functionality
to validate the performance optimization that limits the scope of
link replacement by searching specifically for "[[roam:" instead
of any org link bracket pattern. The tests ensure:

1. Special regex characters in buffer content don't break the
   search functionality when using search-forward
2. Only roam: links are processed, not other link types like
   file: or https:

These tests validate the optimization maintains correctness while
improving performance by avoiding unnecessary replacement attempts
on non-roam links.

Ref: fc8638759b
Ref: 89dfaef38b
2025-07-01 22:41:27 -07:00
54a6eeaf1d test: fix org-roam-demote-entire-buffer leaving git dirty
The test was modifying tests/roam-files/demoteable.org directly,
causing the file to be left in a modified state after test runs.
This left git in a dirty state and caused subsequent test failures
when the database expected the original file contents.

Changed the test to use a temporary copy of the file instead,
ensuring the original test data remains unmodified.
2025-07-01 21:35:16 -07:00
2 changed files with 65 additions and 7 deletions

View 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

View File

@ -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