mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-11-23 07:18:53 +00:00
added tests, and fixed uncovered bugs
tests currently cover the following all of which are passing - basic execution - referencing tables - referencing other source blocks
This commit is contained in:
parent
480c22bbeb
commit
75ca370de8
@ -92,10 +92,11 @@ return nil."
|
|||||||
(let ((case-fold-search t)
|
(let ((case-fold-search t)
|
||||||
type args new-ref) ;; case search?
|
type args new-ref) ;; case search?
|
||||||
;; assign any arguments to pass to source block
|
;; assign any arguments to pass to source block
|
||||||
(when (string-match "\\(.+\\)\(\\(.+\\)\)" ref)
|
(when (string-match "\\(.+\\)\(\\(.*\\)\)" ref)
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(setq args (mapcar (lambda (ref) (cons :var ref))
|
(if (> (length (match-string 2)) 0)
|
||||||
(split-string (match-string 2 ref) ",[ \f\t\n\r\v]*"))))
|
(setq args (mapcar (lambda (ref) (cons :var ref))
|
||||||
|
(split-string (match-string 2 ref) ",[ \f\t\n\r\v]*")))))
|
||||||
(setq ref (match-string 1 ref)))
|
(setq ref (match-string 1 ref)))
|
||||||
(when (string-match "\\(.+\\):\\(.+\\)" ref)
|
(when (string-match "\\(.+\\):\\(.+\\)" ref)
|
||||||
(find-file (match-string 1 ref))
|
(find-file (match-string 1 ref))
|
||||||
|
@ -48,7 +48,8 @@ automatically generated wrapper for `litorgy-script-execute'.")
|
|||||||
def main
|
def main
|
||||||
%s
|
%s
|
||||||
end
|
end
|
||||||
puts main().inspect
|
results = main()
|
||||||
|
puts (results.class == String) ? results : results.inspect
|
||||||
")
|
")
|
||||||
|
|
||||||
(defvar litorgy-script-python-wrapper-method
|
(defvar litorgy-script-python-wrapper-method
|
||||||
@ -108,12 +109,17 @@ Emacs-lisp table, otherwise return the results as a string."
|
|||||||
(if (string-match "^\\[.+\\]$" results)
|
(if (string-match "^\\[.+\\]$" results)
|
||||||
;; somewhat hacky, but thanks to similarities between languages
|
;; somewhat hacky, but thanks to similarities between languages
|
||||||
;; it seems to work
|
;; it seems to work
|
||||||
(replace-regexp-in-string
|
(litorgy-read
|
||||||
|
(replace-regexp-in-string
|
||||||
"\\[" "(" (replace-regexp-in-string
|
"\\[" "(" (replace-regexp-in-string
|
||||||
"\\]" ")" (replace-regexp-in-string
|
"\\]" ")" (replace-regexp-in-string
|
||||||
", " " " (replace-regexp-in-string
|
", " " " (replace-regexp-in-string
|
||||||
"'" "\"" results))))
|
"'" "\"" results)))))
|
||||||
results)))
|
;; strip trailing endline
|
||||||
|
(progn
|
||||||
|
(while (string= "\n" (substring results -1))
|
||||||
|
(setq results (substring results 0 -1)))
|
||||||
|
results))))
|
||||||
|
|
||||||
(provide 'litorgy-script)
|
(provide 'litorgy-script)
|
||||||
;;; litorgy-script.el ends here
|
;;; litorgy-script.el ends here
|
||||||
|
@ -68,16 +68,19 @@ source code block.
|
|||||||
#+begin_src emacs-lisp :var results=source-block(n=2, m=3) :results silent
|
#+begin_src emacs-lisp :var results=source-block(n=2, m=3) :results silent
|
||||||
results
|
results
|
||||||
#+end_src"
|
#+end_src"
|
||||||
(let ((params (eval `(litorgy-parse-header-arguments
|
(unless (stringp source-block) (setq source-block (symbol-name source-block)))
|
||||||
(concat ":var results="
|
(if (and source-block (> (length source-block) 0))
|
||||||
(symbol-name ,source-block)
|
(let ((params (eval `(litorgy-parse-header-arguments
|
||||||
"("
|
(concat ":var results="
|
||||||
(mapconcat (lambda (var-spec)
|
,source-block
|
||||||
(format "%S=%s" (first var-spec) (second var-spec)))
|
"("
|
||||||
',variables ", ")
|
(mapconcat (lambda (var-spec)
|
||||||
")")))))
|
(format "%S=%s" (first var-spec) (second var-spec)))
|
||||||
(litorgy-execute-src-block
|
',variables ", ")
|
||||||
nil (list "emacs-lisp" "results" (org-combine-plists params '((:results . "silent")))))))
|
")")))))
|
||||||
|
(litorgy-execute-src-block
|
||||||
|
nil (list "emacs-lisp" "results" (org-combine-plists params '((:results . "silent"))))))
|
||||||
|
""))
|
||||||
|
|
||||||
(provide 'litorgy-table)
|
(provide 'litorgy-table)
|
||||||
;;; litorgy-table.el ends here
|
;;; litorgy-table.el ends here
|
||||||
|
@ -121,8 +121,9 @@ the header arguments specified at the source code block."
|
|||||||
(error "Language is not in `litorgy-interpreters': %s" lang))
|
(error "Language is not in `litorgy-interpreters': %s" lang))
|
||||||
(setq result (funcall cmd body params))
|
(setq result (funcall cmd body params))
|
||||||
(if arg
|
(if arg
|
||||||
(progn (message (format "%S" result)) result)
|
(message (if (stringp result) result (format "%S" result)))
|
||||||
(litorgy-insert-result result (cdr (assoc :results params))))))
|
(litorgy-insert-result result (cdr (assoc :results params))))
|
||||||
|
result))
|
||||||
|
|
||||||
(defun litorgy-eval-buffer (&optional arg)
|
(defun litorgy-eval-buffer (&optional arg)
|
||||||
"Replace EVAL snippets in the entire buffer."
|
"Replace EVAL snippets in the entire buffer."
|
||||||
@ -264,17 +265,17 @@ string.
|
|||||||
|
|
||||||
This is taken almost directly from `org-read-prop'."
|
This is taken almost directly from `org-read-prop'."
|
||||||
(if (and (stringp cell) (not (equal cell "")))
|
(if (and (stringp cell) (not (equal cell "")))
|
||||||
(let ((out (string-to-number cell)))
|
(if (litorgy-number-p cell)
|
||||||
(if (equal out 0)
|
(string-to-number cell)
|
||||||
(if (or (equal "(" (substring cell 0 1))
|
(if (or (equal "(" (substring cell 0 1))
|
||||||
(equal "'" (substring cell 0 1)))
|
(equal "'" (substring cell 0 1)))
|
||||||
(read cell)
|
(read cell)
|
||||||
(if (string-match "^\\(+0\\|-0\\|0\\)$" cell)
|
(progn (set-text-properties 0 (length cell) nil cell) cell)))
|
||||||
0
|
|
||||||
(progn (set-text-properties 0 (length cell) nil cell)
|
|
||||||
cell)))
|
|
||||||
out))
|
|
||||||
cell))
|
cell))
|
||||||
|
|
||||||
|
(defun litorgy-number-p (string)
|
||||||
|
"Return t if STRING represents a number"
|
||||||
|
(string-match "^[[:digit:]]*\\.?[[:digit:]]*$" string))
|
||||||
|
|
||||||
(provide 'litorgy)
|
(provide 'litorgy)
|
||||||
;;; litorgy.el ends here
|
;;; litorgy.el ends here
|
||||||
|
116
rorg.org
116
rorg.org
@ -355,6 +355,122 @@ recognition of ruby arrays as such.
|
|||||||
| 1 | 2 | 3 | 4 |
|
| 1 | 2 | 3 | 4 |
|
||||||
|
|
||||||
|
|
||||||
|
* Tests
|
||||||
|
|
||||||
|
Evaluate all the cells in this table for a comprehensive test of the
|
||||||
|
litorgy functionality.
|
||||||
|
|
||||||
|
#+TBLNAME: litorgy-tests
|
||||||
|
| functionality | block | expected | results | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| basic evaluation | | | | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| emacs lisp | basic-elisp | 5 | 5 | pass |
|
||||||
|
| shell | basic-shell | 6 | 6 | pass |
|
||||||
|
| ruby | basic-ruby | litorgy | litorgy | pass |
|
||||||
|
| python | basic-python | hello world | hello world | pass |
|
||||||
|
| R | basic-R | 13 | 13 | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| tables | | | | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| emacs lisp | table-elisp | 3 | 3 | pass |
|
||||||
|
| ruby | table-ruby | 1-2-3 | 1-2-3 | pass |
|
||||||
|
| python | table-python | 5 | 5 | pass |
|
||||||
|
| R | table-R | 3.5 | 3.5 | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| source block references | | | | pass |
|
||||||
|
|-------------------------+------------------+-------------+-------------+------|
|
||||||
|
| all languages | chained-ref-last | Array | Array | pass |
|
||||||
|
#+TBLFM: $4='(sbe $2)::$5='(if (string= $3 $4) "pass" (format "expected %S but was %S" $3 $4))
|
||||||
|
|
||||||
|
** basic tests
|
||||||
|
|
||||||
|
#+srcname: basic-elisp
|
||||||
|
#+begin_src emacs-lisp :results silent
|
||||||
|
(+ 1 4)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: basic-shell
|
||||||
|
#+begin_src sh :results silent
|
||||||
|
expr 1 + 5
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
|
#+srcname: basic-ruby
|
||||||
|
#+begin_src ruby :results silent
|
||||||
|
"litorgy"
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: basic-python
|
||||||
|
#+begin_src python :results silent
|
||||||
|
'hello world'
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: basic-R
|
||||||
|
#+begin_src R :results silent
|
||||||
|
b <- 9
|
||||||
|
b + 4
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** read tables
|
||||||
|
|
||||||
|
#+tblname: test-table
|
||||||
|
| 1 | 2 | 3 |
|
||||||
|
| 4 | 5 | 6 |
|
||||||
|
|
||||||
|
#+srcname: table-elisp
|
||||||
|
#+begin_src emacs-lisp :results silent :var table=test-table
|
||||||
|
(length (car table))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: table-ruby
|
||||||
|
#+begin_src ruby :results silent :var table=test-table
|
||||||
|
table.first.join("-")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: table-python
|
||||||
|
#+begin_src python :var table=test-table
|
||||||
|
table[1][1]
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+srcname: table-R
|
||||||
|
#+begin_src R :var table=test-table
|
||||||
|
mean(mean(table))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** references
|
||||||
|
|
||||||
|
Lets pass a references through all of our languages...
|
||||||
|
|
||||||
|
Lets start by reversing the table from the previous examples
|
||||||
|
|
||||||
|
#+srcname: chained-ref-first
|
||||||
|
#+begin_src python :var table = test-table
|
||||||
|
table.reverse
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Take the first part of the list
|
||||||
|
|
||||||
|
#+srcname: chained-ref-second
|
||||||
|
#+begin_src R :var table = chained-ref-first
|
||||||
|
table[1]
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
Turn the numbers into string
|
||||||
|
|
||||||
|
#+srcname: chained-ref-third
|
||||||
|
#+begin_src emacs-lisp :var table = chained-ref-second
|
||||||
|
(mapcar (lambda (el) (format "%S" el)) table)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
and Check that it is still a list
|
||||||
|
|
||||||
|
#+srcname: chained-ref-last
|
||||||
|
#+begin_src ruby :var table=chained-ref-third
|
||||||
|
table.class.name
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
|
||||||
* Sandbox
|
* Sandbox
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:CUSTOM_ID: sandbox
|
:CUSTOM_ID: sandbox
|
||||||
|
Loading…
Reference in New Issue
Block a user