aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-11 21:12:13 -0500
committerCraig Jennings <c@cjennings.net>2026-07-11 21:12:13 -0500
commit9b906b32b6eccc289aca61b412d828f0daf32f72 (patch)
tree630db249faa801b1d01cfacdd5551119a77bbf52 /tests
parent5d8262e7854e43c3a5013d60b8d32fa869bbb924 (diff)
downloaddotemacs-9b906b32b6eccc289aca61b412d828f0daf32f72.tar.gz
dotemacs-9b906b32b6eccc289aca61b412d828f0daf32f72.zip
fix(lorem-optimum): guard empty chain, make cj/lipsum a command
cj/lipsum returned nil when the Markov chain was empty (for example with the training file missing), so cj/lipsum-insert ran (insert nil) and raised a cryptic wrong-type error far from the cause. It now signals a user-error naming the fix: train the chain or restore the file. The Commentary advertised M-x cj/lipsum, but the function had no interactive spec. I added one, echoing the words interactively while still returning the string for cj/lipsum-insert and cj/lipsum-paragraphs.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-lorem-optimum.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test-lorem-optimum.el b/tests/test-lorem-optimum.el
index f928c972..b7d97a8e 100644
--- a/tests/test-lorem-optimum.el
+++ b/tests/test-lorem-optimum.el
@@ -253,5 +253,26 @@ an empty string, not an error."
(let ((cj/lipsum-chain (cj/markov-chain-create)))
(should (equal "" (cj/lipsum-title)))))
+;;; cj/lipsum entry point
+
+(ert-deftest test-lipsum-returns-string-with-populated-chain ()
+ "Normal: cj/lipsum returns a non-empty string when the chain is trained."
+ (let ((cj/lipsum-chain
+ (test-learn "Lorem ipsum dolor sit amet consectetur adipiscing elit")))
+ (let ((result (cj/lipsum 5)))
+ (should (stringp result))
+ (should (> (length result) 0)))))
+
+(ert-deftest test-lipsum-empty-chain-signals-user-error ()
+ "Error: cj/lipsum on an empty chain signals a user-error naming the fix,
+rather than returning nil and letting cj/lipsum-insert do (insert nil),
+which raises a cryptic wrong-type error far from the cause."
+ (let ((cj/lipsum-chain (cj/markov-chain-create)))
+ (should-error (cj/lipsum 5) :type 'user-error)))
+
+(ert-deftest test-lipsum-is-interactive-command ()
+ "Normal: cj/lipsum is a command, as its Commentary (M-x cj/lipsum) advertises."
+ (should (commandp 'cj/lipsum)))
+
(provide 'test-lorem-optimum)
;;; test-lorem-optimum.el ends here