diff --git a/examples-to-docs.el b/examples-to-docs.el index 3be657f..a16575b 100644 --- a/examples-to-docs.el +++ b/examples-to-docs.el @@ -4,36 +4,29 @@ (defun example-to-string (example) (let ((actual (car example)) - (expected (cadr (cdr example)))) + (expected (nth 2 example))) (--> (format "%S ;; => %S" actual expected) (replace-regexp-in-string "\\\\\\?" "?" it) (replace-regexp-in-string "\n" "\\n" it t t) (replace-regexp-in-string "\t" "\\t" it t t) (replace-regexp-in-string "\r" "\\r" it t t)))) -(defun examples-to-strings (examples) - (let (result) - (while examples - (setq result (cons (example-to-string examples) result)) - (setq examples (cddr (cdr examples)))) - (nreverse result))) - (defun docs--signature (cmd) (if (eq 'macro (car cmd)) - (car (cddr cmd)) - (cadr cmd))) + (nth 2 cmd) + (nth 1 cmd))) (defun docs--docstring (cmd) (if (eq 'macro (car cmd)) - (cadr (cddr cmd)) - (car (cddr cmd)))) + (nth 3 cmd) + (nth 2 cmd))) (defmacro defexamples (cmd &rest examples) `(add-to-list 'functions (list ',cmd (docs--signature (symbol-function ',cmd)) (docs--docstring (symbol-function ',cmd)) - (examples-to-strings ',examples)))) + (-map 'example-to-string (-partition 3 ',examples))))) (defun quote-and-downcase (string) (format "`%s`" (downcase string))) @@ -47,8 +40,8 @@ (defun function-to-md (function) (let ((command-name (car function)) (signature (cadr function)) - (docstring (quote-docstring (cadr (cdr function)))) - (examples (cadr (cddr function)))) + (docstring (quote-docstring (nth 2 function))) + (examples (nth 3 function))) (format "### %s `%s`\n\n%s\n\n```cl\n%s\n```\n" command-name signature diff --git a/examples-to-tests.el b/examples-to-tests.el index 080a65f..a4cc365 100644 --- a/examples-to-tests.el +++ b/examples-to-tests.el @@ -1,19 +1,13 @@ (require 'ert) +(require 'dash) -(defun examples-to-should-1 (examples) +(defun example-to-should (example) (let ((actual (car examples)) - (expected (cadr (cdr examples)))) + (expected (nth 2 examples))) `(should (equal ,actual ,expected)))) -(defun examples-to-should (examples) - (let (result) - (while examples - (setq result (cons (examples-to-should-1 examples) result)) - (setq examples (cddr (cdr examples)))) - (nreverse result))) - (defmacro defexamples (cmd &rest examples) `(ert-deftest ,cmd () - ,@(examples-to-should examples))) + ,@(-map 'example-to-should (-partition 3 examples)))) (provide 'examples-to-tests) diff --git a/run-tests.sh b/run-tests.sh index 697df4b..25ce1fd 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -4,4 +4,4 @@ if [ -z "$EMACS" ] ; then EMACS="emacs" fi -$EMACS -batch -l ert.el -l examples-to-tests.el -l dash.el -l examples.el -f ert-run-tests-batch-and-exit +$EMACS -batch -l ert.el -l dash.el -l examples-to-tests.el -l examples.el -f ert-run-tests-batch-and-exit