branch: externals/ellama
commit f9c8c32e8672749488bba0081375c97253e899d7
Author: Sergey Kostyaev <sskosty...@gmail.com>
Commit: Sergey Kostyaev <sskosty...@gmail.com>

    Add tests for ellama text formatting and duplicate string handling
    
    Added two new tests for ellama functionality:
    1. test-ellama-lorem-ipsum verifies proper line wrapping and formatting of 
long
    text
    2. test-ellama-duplicate-strings checks handling of duplicate strings with
    markdown formatting
    
    Both tests use a fake LLM provider to simulate streaming responses and 
validate
    that the output matches expected formatted results.
---
 tests/test-ellama.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index a83803b364..ce0a1ebf49 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -53,6 +53,62 @@
         (ellama-code-improve)
         (should (equal original (buffer-string)))))))
 
+(ert-deftest test-ellama-lorem-ipsum ()
+  (let ((fill-column 70)
+        (raw "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do 
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim 
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo 
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse 
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non 
proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed do 
eiusmod tempor incididunt [...]
+        (expected "Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Sed do
+eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
+minim veniam, quis nostrud exercitation ullamco laboris nisi ut
+aliquip ex ea commodo consequat. Duis aute irure dolor in
+reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum. Sed do eiusmod
+tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
+veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
+ea commodo consequat. Duis aute irure dolor in reprehenderit in
+voluptate velit esse cillum dolore eu fugiat nulla pariatur.")
+        (ellama-provider (make-llm-fake))
+        prev-lines)
+    (with-temp-buffer
+      (org-mode)
+      (cl-letf (((symbol-function 'llm-chat-streaming)
+                (lambda (_provider prompt partial-callback response-callback 
_error-callback _multi-output)
+                  (should (string-match "test" (llm-chat-prompt-to-text 
prompt)))
+                  (dolist (s (string-split raw " "))
+                    (funcall partial-callback `(:text ,(concat prev-lines s)))
+                    (setq prev-lines (concat prev-lines s)))
+                  (funcall response-callback `(:text ,raw)))))
+        (ellama-write "test")
+        (should (equal expected (buffer-string)))))))
+
+(ert-deftest test-ellama-duplicate-strings ()
+  (let ((fill-column 80)
+       (raw "Great question! Whether you should start with **\"Natural 
Language Processing with Transformers\"** (O’Reilly) or wait for **\"Build a 
Large Language Model (From Scratch)\"** depends on your **goals, background, 
and learning style**. Here’s a detailed comparison to help
+you decide:
+
+---
+
+")
+       (expected "Great question! Whether you should start with *\"Natural 
Language Processing with
+Transformers\"* (O’Reilly) or wait for *\"Build a Large Language Model (From
+Scratch)\"* depends on your *goals, background, and learning style*. Here’s a
+detailed comparison to help you decide:
+
+---")
+       (ellama-provider (make-llm-fake))
+       prev-lines)
+    (with-temp-buffer
+      (org-mode)
+      (cl-letf (((symbol-function 'llm-chat-streaming)
+                (lambda (_provider prompt partial-callback response-callback 
_error-callback _multi-output)
+                  (should (string-match "test" (llm-chat-prompt-to-text 
prompt)))
+                  (dolist (s (string-split raw " "))
+                    (funcall partial-callback `(:text ,(concat prev-lines s " 
")))
+                    (setq prev-lines (concat prev-lines s " ")))
+                  (funcall response-callback `(:text ,raw)))))
+       (ellama-write "test")
+       (should (equal expected (buffer-string)))))))
+
 (ert-deftest test-ellama-context-element-format-buffer-markdown ()
   (let ((element (ellama-context-element-buffer :name "*scratch*")))
     (should (equal "```emacs-lisp\n(display-buffer \"*scratch*\")\n```\n"

Reply via email to