diff --git a/src/interface/emacs/tests/khoj-tests.el b/src/interface/emacs/tests/khoj-tests.el new file mode 100644 index 00000000..75cfad7c --- /dev/null +++ b/src/interface/emacs/tests/khoj-tests.el @@ -0,0 +1,155 @@ +;;; khoj-tests.el --- Test suite for khoj.el -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Debanjum Singh Solanky + +;; Author: Debanjum Singh Solanky +;; Version: 0.0.0 +;; Package-Requires: ((emacs "27.1") (transient "0.3.0")) +;; URL: https://github.com/debanjum/khoj/tree/master/src/interface/emacs + +;;; License: + +;; 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: + +;; This file contains the test suite for khoj.el. + +;;; Code: + +(require 'ert) +(require 'khoj) + + + +;; ---------------------------------------------------- +;; Test Extract and Render Entries of each Content Type +;; ---------------------------------------------------- + +(ert-deftest khoj-tests--extract-entries-as-markdown () + "Test `json-response', `query' from API formatted as markdown." + (let ((user-query "Become God") + (json-response-from-khoj-backend + (json-read-from-string + "[\ +{\ + \"entry\": \"## Upgrade\\n\\n Penance to Immortality\\n\",\ + \"score\": \"0.376\",\ + \"additional\": {\ + \"file\": \"/home/ravan/upgrade.md\",\ + \"compiled\": \"## Upgrade Penance to Immortality\"\ + }\ +},\ +{\ + \"entry\": \"## Act\\n\\n Rule everything\\n\",\ + \"score\": \"0.153\",\ + \"additional\": {\ + \"file\": \"/home/ravan/act.md\",\ + \"compiled\": \"## Act Rule everything\"\ + }\ +}]\ +"))) + (should + (equal + (khoj--extract-entries-as-markdown json-response-from-khoj-backend user-query) + "\ +# Become God\n\ +## Upgrade\n\ +\n\ +Penance to Immortality\n\ +## Act\n\ +\n\ +Rule everything\n")))) + + +(ert-deftest khoj-tests--extract-entries-as-org () + "Test `json-response', `query' from API formatted as org." + (let ((user-query "Become God") + (json-response-from-khoj-backend + (json-read-from-string + "[\ +{\ + \"entry\": \"** Upgrade\\n\\n Penance to Immortality\\n\",\ + \"score\": \"0.42\",\ + \"additional\": {\ + \"file\": \"/home/ravan/upgrade.md\",\ + \"compiled\": \"** Upgrade Penance to Immortality\"\ + }\ +},\ +{\ + \"entry\": \"** Act\\n\\n Rule everything\\n\",\ + \"score\": \"0.42\",\ + \"additional\": {\ + \"file\": \"/home/ravan/act.md\",\ + \"compiled\": \"** Act Rule everything\"\ + }\ +}]\ +"))) + (should + (equal + (khoj--extract-entries-as-org json-response-from-khoj-backend user-query) + "\ +* Become God\n\ +** Upgrade\n\ +\n\ +Penance to Immortality\n\ +** Act\n\ +\n\ +Rule everything\n\ +\n\ +#+STARTUP: showall hidestars inlineimages")))) + + +(ert-deftest khoj-tests--extract-entries-as-ledger () + "Test `json-response', `query' from API formatted as beancount ledger." + (let ((user-query "Become God") + (json-response-from-khoj-backend + (json-read-from-string + "[\ +{\ + \"entry\": \"4242-04-01 * \\\"Penance Center\\\" \\\"Book Stay for 10,000 Years\\\"\\n Expenses:Health:Mental 15 GOLD\\n Assets:Commodities:Gold\",\ + \"score\": \"0.42\",\ + \"additional\": {\ + \"file\": \"/home/ravan/ledger.beancount\",\ + \"compiled\": \"4242-04-01 * \\\"Penance Center\\\" \\\"Book Stay for 10,000 Years\\\" Expenses:Health:Mental 15 GOLD Assets:Commodities:Gold\"\ + }\ +},\ +{\ + \"entry\": \"14242-04-01 * \\\"Brahma\\\" \\\"Boon for Invincibility from Higher Beings\\\"\\n Income:Health -1,00,00,000 LIFE\\n Assets:Commodities:Life\",\ + \"score\": \"0.42\",\ + \"additional\": {\ + \"file\": \"/home/ravan/ledger.beancount\",\ + \"compiled\": \"4242-04-01 * \\\"Brahma\\\" \\\"Boon for Invincibility from Higher Beings\\\" Income:Health -1,00,00,000 LIFE Assets:Commodities:Life\"\ + }\ +}]\ +"))) + (should + (equal + (khoj--extract-entries-as-ledger json-response-from-khoj-backend user-query) + ";; Become God\n\ +\n\ +4242-04-01 * \"Penance Center\" \"Book Stay for 10,000 Years\"\n\ + Expenses:Health:Mental 15 GOLD\n\ + Assets:Commodities:Gold\n\ +\n\ +14242-04-01 * \"Brahma\" \"Boon for Invincibility from Higher Beings\"\n\ + Income:Health -1,00,00,000 LIFE\n\ + Assets:Commodities:Life\n\ +\n\ +\n\ +")))) + +(provide 'khoj-tests) + +;;; khoj-tests.el ends here