Call function when a predefined prompt has one
Also test if the variable with predefined prompts is used properly by kagi-fastgpt-prompt.
This commit is contained in:
parent
554a19285b
commit
9b58724986
15
kagi-test.el
15
kagi-test.el
|
@ -77,6 +77,7 @@ The EXPECT-ARGS correspond to the arguments passed to the `expect' macro."
|
|||
(spy-on #'kagi--call-api :and-return-value (kagi-test--dummy-output dummy-output)))
|
||||
(describe "FastGPT"
|
||||
(describe "kagi-fastgpt-prompt"
|
||||
:var ((kagi-fastgpt-prompts))
|
||||
(before-each
|
||||
(spy-on #'message)
|
||||
(spy-on #'kagi--fastgpt-display-result))
|
||||
|
@ -177,7 +178,19 @@ https://www.example.com"
|
|||
(spy-on #'kagi--get-text-for-prompt)
|
||||
(call-interactively #'kagi-fastgpt-prompt)
|
||||
(kagi-test--expect-arg #'kagi--fastgpt 0 :to-equal "foo%bar")
|
||||
(expect #'kagi--get-text-for-prompt :not :to-have-been-called)))
|
||||
(expect #'kagi--get-text-for-prompt :not :to-have-been-called))
|
||||
(it "uses the cdr when the user enters a predefined prompt name"
|
||||
(setq kagi-fastgpt-prompts '(("foo" . "bar")))
|
||||
(spy-on #'kagi--fastgpt)
|
||||
(spy-on #'completing-read :and-return-value "foo")
|
||||
(call-interactively #'kagi-fastgpt-prompt)
|
||||
(kagi-test--expect-arg #'kagi--fastgpt 0 :to-equal "bar"))
|
||||
(it "calls the function when a predefined prompt has one"
|
||||
(setq kagi-fastgpt-prompts '(("function" . (lambda () "result"))))
|
||||
(spy-on #'kagi--fastgpt)
|
||||
(spy-on #'completing-read :and-return-value "function")
|
||||
(call-interactively #'kagi-fastgpt-prompt)
|
||||
(kagi-test--expect-arg #'kagi--fastgpt 0 :to-equal "result")))
|
||||
(describe "kagi-translate"
|
||||
(before-each
|
||||
(spy-on #'kagi-fastgpt-prompt))
|
||||
|
|
3
kagi.el
3
kagi.el
|
@ -424,7 +424,8 @@ interactively obtained from the user (the region, buffer content
|
|||
or text input)."
|
||||
(let* ((user-text)
|
||||
(prompt-name (completing-read "fastgpt> " kagi-fastgpt-prompts))
|
||||
(prompt-template (alist-get prompt-name kagi-fastgpt-prompts prompt-name nil #'string=)))
|
||||
(prompt-cdr (alist-get prompt-name kagi-fastgpt-prompts prompt-name nil #'string=))
|
||||
(prompt-template (if (functionp prompt-cdr) (funcall prompt-cdr) prompt-cdr)))
|
||||
(replace-regexp-in-string (rx (seq "%" anychar))
|
||||
(lambda (match)
|
||||
(pcase match
|
||||
|
|
Loading…
Reference in a new issue