From 86e808abfbe9010e6cd5e242a2f9b0cc926d602d Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 23 Jan 2023 18:15:23 -0300 Subject: [PATCH] Test get-current-text helpers for Find Similar feature in khoj.el --- src/interface/emacs/tests/khoj-tests.el | 96 +++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/src/interface/emacs/tests/khoj-tests.el b/src/interface/emacs/tests/khoj-tests.el index 75cfad7c..9325a61c 100644 --- a/src/interface/emacs/tests/khoj-tests.el +++ b/src/interface/emacs/tests/khoj-tests.el @@ -150,6 +150,102 @@ Rule everything\n\ \n\ ")))) + + +;; ------------------------------------- +;; Test Helpers for Find Similar Feature +;; ------------------------------------- + +(ert-deftest khoj-tests--get-current-outline-entry-text () + "Test get current outline-mode entry text'." + (with-temp-buffer + (insert "\ +* Become God\n\ +** Upgrade\n\ +\n\ +Penance to Immortality\n\ +** Act\n\ +\n\ +Rule everything\\n") + (goto-char (point-min)) + + ;; Test getting current entry text from cursor at start of outline heading + (outline-next-visible-heading 1) + (should + (equal + (khoj--get-current-outline-entry-text) + "\ +** Upgrade\n\ +\n\ +Penance to Immortality")) + + ;; Test getting current entry text from cursor within outline entry + (forward-line) + (should + (equal + (khoj--get-current-outline-entry-text) + "\ +** Upgrade\n\ +\n\ +Penance to Immortality")) + )) + + +(ert-deftest khoj-tests--get-current-paragraph-text () + "Test get current paragraph text'." + (with-temp-buffer + (insert "\ +* Become God\n\ +** Upgrade\n\ +\n\ +Penance to Immortality\n\ +** Act\n\ +\n\ +Rule everything\n") + ;; Test getting current paragraph text from cursor at start of buffer + (goto-char (point-min)) + (should + (equal + (khoj--get-current-paragraph-text) + "* Become God\n\ +** Upgrade")) + + ;; Test getting current paragraph text from cursor within paragraph + (goto-char (point-min)) + (forward-line 1) + (should + (equal + (khoj--get-current-paragraph-text) + "* Become God\n\ +** Upgrade")) + + ;; Test getting current paragraph text from cursor at paragraph end + (goto-char (point-min)) + (forward-line 2) + (should + (equal + (khoj--get-current-paragraph-text) + "* Become God\n\ +** Upgrade")) + + ;; Test getting current paragraph text from cursor at start of middle paragraph + (goto-char (point-min)) + (forward-line 3) + (should + (equal + (khoj--get-current-paragraph-text) + "Penance to Immortality\n\ +** Act")) + + ;; Test getting current paragraph text from cursor at end of buffer + (goto-char (point-max)) + (should + (equal + (khoj--get-current-paragraph-text) + "Rule everything")) + )) + + (provide 'khoj-tests) ;;; khoj-tests.el ends here