-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
ekg-llm-test.el
77 lines (66 loc) · 3.01 KB
/
ekg-llm-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; ekg-llm-test.el --- Tests for ekg-llm -*- lexical-binding: t; -*-
;; Copyright (c) 2023 Andrew Hyatt <[email protected]>
;; 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 2 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; These tests should be run and pass before every commit to ekg-llm.
;;; Code:
(require 'ekg)
(require 'ekg-llm)
(defun ekg-llm-test-replace-text (markers text)
"Replace text between MARKERS."
(let ((beg (car markers))
(end (cdr markers)))
(goto-char beg)
(delete-region beg end)
(insert text)))
(ert-deftest ekg-llm-test-create-output-holder ()
(with-temp-buffer
(let ((markers (ekg-llm-create-output-holder "BEGIN" "END")))
(should (equal "BEGIN\n\nEND\n"
(substring-no-properties (buffer-string))))
(ekg-llm-test-replace-text markers "text 1")
(should (equal "BEGIN\ntext 1\nEND\n"
(substring-no-properties (buffer-string))))
(ekg-llm-test-replace-text markers "very different text")
(should (equal "BEGIN\nvery different text\nEND\n"
(substring-no-properties (buffer-string)))))))
(ert-deftest ekg-llm-test-note-to-text ()
(let* ((time (current-time))
(time-str (format-time-string "%Y-%m-%dT%H:%M:%S" time))
(json-encoding-pretty-print t))
(cl-letf (((symbol-function 'ekg-inline-command-const-inline)
(lambda (&rest _) "inline")))
(should (equal
(json-encode
(sort
`(("tags" . ["tag1" "tag2"])
("created" . ,time-str)
("modified" . ,time-str)
("title" . ["Title"])
("text" . "Contentinline\n")
("id" . "http://example.com/1"))
(lambda (a b) (string< (car a) (car b)))))
(ekg-llm-note-to-text
(make-ekg-note :id "http://example.com/1"
:properties '(:titled/title ("Title"))
:text "Content"
:creation-time time
:modified-time time
:tags '("tag1" "tag2")
:inlines
(list (make-ekg-inline :pos 7
:command '(const-inline)
:type 'command)))))))))
(provide 'ekg-llm-test)
;;; ekg-llm-test.el ends here