From 57fadf54a63e162fd797b0ad06a8198d8cb20365 Mon Sep 17 00:00:00 2001 From: Dustin Farris Date: Tue, 1 Jul 2025 21:38:13 -0700 Subject: [PATCH] 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: fc8638759b9d Ref: 89dfaef38b6c --- tests/test-org-roam-link-replace.el | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/test-org-roam-link-replace.el diff --git a/tests/test-org-roam-link-replace.el b/tests/test-org-roam-link-replace.el new file mode 100644 index 0000000..6149bd1 --- /dev/null +++ b/tests/test-org-roam-link-replace.el @@ -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 . + +;;; 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