1
0
Fork 0

Add tests to check formatting is done by markdown-mode

This commit is contained in:
Bram Schoenmakers 2024-07-23 22:07:34 +02:00
parent ea77e31713
commit 91876a5f9d
Signed by: bram
GPG key ID: 0CCD19DFDC63258F

View file

@ -85,7 +85,9 @@ The EXPECT-ARGS correspond to the arguments passed to the `expect' macro."
:var ((kagi--fastgpt-prompts)) :var ((kagi--fastgpt-prompts))
(before-each (before-each
(spy-on #'message) (spy-on #'message)
(spy-on #'kagi--fastgpt-display-result)) (spy-on #'kagi--fastgpt-display-result)
(spy-on #'font-lock-default-function)
(spy-on #'font-lock-default-fontify-region))
(it "formats references properly" (it "formats references properly"
(spy-on #'kagi--call-api (spy-on #'kagi--call-api
:and-return-value :and-return-value
@ -116,19 +118,21 @@ https://www.example.com"))
(it "does not insert the output by default" (it "does not insert the output by default"
(spy-on #'insert) (spy-on #'insert)
(kagi-fastgpt-prompt "foo") (kagi-fastgpt-prompt "foo")
;; one insert call is to fill the temporary buffer for POST ;; one insert call for the temporary buffer for formatting
;; data
(expect #'insert :to-have-been-called-times 1)) (expect #'insert :to-have-been-called-times 1))
(it "shows short output in the echo area when called interactively" (it "shows short output without formatting in the echo area when called interactively"
(spy-on #'kagi--call-api :and-return-value (kagi-test--dummy-output dummy-output)) (spy-on #'kagi--call-api :and-return-value (kagi-test--dummy-output dummy-output))
(kagi-fastgpt-prompt "foo" nil t) (kagi-fastgpt-prompt "foo" nil t)
(expect #'message :to-have-been-called-with dummy-output) (expect #'message :to-have-been-called-with dummy-output)
(expect #'kagi--fastgpt-display-result :not :to-have-been-called)) (expect #'kagi--fastgpt-display-result :not :to-have-been-called)
(it "shows longer output in a separate buffer when called interactively" (expect #'font-lock-default-fontify-region :not :to-have-been-called))
(it "shows longer output with formatting in a separate buffer when called interactively"
(spy-on #'kagi--call-api :and-return-value (kagi-test--dummy-output (format "%s\n%s" dummy-output dummy-output))) (spy-on #'kagi--call-api :and-return-value (kagi-test--dummy-output (format "%s\n%s" dummy-output dummy-output)))
(kagi-fastgpt-prompt "foo" nil t) (kagi-fastgpt-prompt "foo" nil t)
(expect #'message :not :to-have-been-called) (expect #'message :not :to-have-been-called)
(expect #'kagi--fastgpt-display-result :to-have-been-called)) (expect #'kagi--fastgpt-display-result :to-have-been-called)
(kagi-test--expect-arg #'font-lock-default-function 0 :to-equal #'markdown-mode)
(expect #'font-lock-default-fontify-region :to-have-been-called))
(it "makes exactly one API call" (it "makes exactly one API call"
(kagi-fastgpt-prompt "foo") (kagi-fastgpt-prompt "foo")
(expect #'kagi--call-api :to-have-been-called-times 1)) (expect #'kagi--call-api :to-have-been-called-times 1))
@ -169,7 +173,13 @@ https://www.example.com"))
(spy-on #'kagi--fastgpt) (spy-on #'kagi--fastgpt)
(spy-on #'completing-read :and-return-value "function") (spy-on #'completing-read :and-return-value "function")
(call-interactively #'kagi-fastgpt-prompt) (call-interactively #'kagi-fastgpt-prompt)
(kagi-test--expect-arg #'kagi--fastgpt 0 :to-equal "result"))) (kagi-test--expect-arg #'kagi--fastgpt 0 :to-equal "result"))
(it "lets markdown-mode format the output when called non-interactively"
(kagi-fastgpt-prompt "foo")
(kagi-test--expect-arg #'font-lock-default-function 0 :to-equal #'markdown-mode))
(it "inserts the output without formatting when inserting the output"
(kagi-fastgpt-prompt "foo" t)
(expect #'font-lock-default-fontify-region :not :to-have-been-called)))
(it "handles empty output and returned errors from the API gracefully" (it "handles empty output and returned errors from the API gracefully"
(spy-on #'kagi--call-api :and-return-value (kagi-test--error-output)) (spy-on #'kagi--call-api :and-return-value (kagi-test--error-output))
(spy-on #'kagi--fastgpt :and-call-through) (spy-on #'kagi--fastgpt :and-call-through)