diff of cbbbcc2ceb0ac25188c96907bed0378f69d20eb3
cbbbcc2ceb0ac25188c96907bed0378f69d20eb3
diff --git a/aggressive-murja.asd b/aggressive-murja.asd
index e943848..3e1a42a 100644
--- a/aggressive-murja.asd
+++ b/aggressive-murja.asd
@@ -56,6 +56,8 @@
"fiveam")
:components ((:module "test"
:components
- ((:file "tests"))))
+ ((:file "literal")
+ (:file "literal-test")
+ (:file "tests"))))
:perform (test-op (op c)
(eval (read-from-string "(fiveam:run! 'murja.tests:main-suite)"))))
diff --git a/test/literal-test.lisp b/test/literal-test.lisp
new file mode 100644
index 0000000..b1b2273
--- /dev/null
+++ b/test/literal-test.lisp
@@ -0,0 +1,37 @@
+(defpackage murja.tests.literal-test
+ (:use :cl :fiveam)
+ (:import-from :murja.tests.literal :literal :drop-while))
+
+(in-package :murja.tests.literal-test)
+
+(def-suite literal-suite)
+(in-suite literal-suite)
+
+(def-test literal-helper-function-tests ()
+ (is (equalp (list 12 23 5434 34 5 2 34)
+ (drop-while (list 0 1 2 3 4 5 12 23 5434 34 5 2 34) (lambda (x) (< x 10)))))
+
+ (is (equalp `(PROGN
+ (DEFUN FAC (N)
+ (IF (EQUALP N 1)
+ 1
+ (* N (FAC (1- N)))))
+ (LITERAL AND OTHER STUFF LIKE !L (FORMAT T "fac of 7 is ~d~%" (fac 7)) INTO
+ JUST THE QUOTATION-WRAPPED CODE))
+ (macroexpand `(literal Transforms a block of documentation that returns lisp code like
+ !L
+ (defun fac (n)
+ (if (equalp n 1)
+ 1
+ (* n (fac (1- n)))))
+
+ and other stuff like
+ !L
+ (format t "fac of 7 is ~d~%" (fac 7))
+
+ into just the quotation-wrapped code)))))
+
+
+(if (and (sb-ext:posix-getenv "GHA")
+ (not (run! 'literal-suite)))
+ (sb-ext:exit :code 666))
diff --git a/test/literal.lisp b/test/literal.lisp
new file mode 100644
index 0000000..4af80ab
--- /dev/null
+++ b/test/literal.lisp
@@ -0,0 +1,24 @@
+(defpackage murja.tests.literal
+ (:use :cl)
+ (:import-from :lisp-fixup :partial)
+ (:export :literal :drop-while))
+
+(in-package :murja.tests.literal)
+
+(defun drop-while (list pred)
+ (if (and (first list) (funcall pred (first list)))
+ (drop-while (rest list) pred)
+ list))
+
+(defmacro literal (&rest body)
+ "(literal Transforms a block of documentation that returns lisp code like !L (defun fac (n) (if (equalp n 1) 1 (* n (fac (1- n))))) and other stuff like !L (format t \"fac of 7 is ~d~%\" (fac 7)) into just the quotation-wrapped code)
+=>
+ (progn
+ (defun fac (n) (if (equalp n 1) 1 (* n (fac (1- n)))))
+ (format t \"fac of 7 is ~d~%\" (fac 7)))"
+ (let ((body (rest (drop-while body (complement (partial #'string= '!L))))))
+ (if body
+ `(progn
+ ,(first body)
+ (literal ,@(rest body))))))
+