1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

Add string input variables to ob-octave.el. Add tests for ob-octave.el

This commit is contained in:
Litvinov Sergey 2011-11-08 22:19:04 +01:00 committed by Eric Schulte
parent 69aa8884ed
commit e6377a8295
4 changed files with 111 additions and 1 deletions

View File

@ -117,7 +117,11 @@ specifying a variable of the same value."
(if (listp var) (if (listp var)
(concat "[" (mapconcat #'org-babel-octave-var-to-octave var (concat "[" (mapconcat #'org-babel-octave-var-to-octave var
(if (listp (car var)) "; " ",")) "]") (if (listp (car var)) "; " ",")) "]")
(format "%s" (or var "nil")))) (cond
((stringp var)
(format "\'%s\'" var))
(t
(format "%s" var)))))
(defun org-babel-prep-session:octave (session params &optional matlabp) (defun org-babel-prep-session:octave (session params &optional matlabp)
"Prepare SESSION according to the header arguments specified in PARAMS." "Prepare SESSION according to the header arguments specified in PARAMS."

View File

@ -80,6 +80,7 @@ First tangle this file out to your desktop.
(concat org-dir "/testing/examples/ob-C-test.org") (concat org-dir "/testing/examples/ob-C-test.org")
(concat org-dir "/testing/examples/normal.org") (concat org-dir "/testing/examples/normal.org")
(concat org-dir "/testing/examples/ob-awk-test.org") (concat org-dir "/testing/examples/ob-awk-test.org")
(concat org-dir "/testing/examples/ob-octave.org")
(concat org-dir "/testing/examples/ob-fortran-test.org") (concat org-dir "/testing/examples/ob-fortran-test.org")
(concat org-dir "/testing/examples/ob-maxima-test.org") (concat org-dir "/testing/examples/ob-maxima-test.org")
(concat org-dir "/testing/examples/link-in-heading.org") (concat org-dir "/testing/examples/link-in-heading.org")

View File

@ -0,0 +1,45 @@
#+Title: a collection of examples for ob-octave tests
#+OPTIONS: ^:nil
* Simple tests
:PROPERTIES:
:ID: 54dcd61d-cf6c-4d7a-b9e5-854953c8a753
:END:
Number output
#+begin_src octave :exports results :results silent
ans = 10
#+end_src
Array output
#+begin_src octave :exports results :results silent
ans = 1:4'
#+end_src
* Input tests
:PROPERTIES:
:ID: cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba
:END:
Input an integer variable
#+begin_src octave :exports results :results silent :var s=42
ans = s
#+end_src
Input an array
#+begin_src octave :exports results :results silent :var s='(1.0 2.0 3.0)
ans = s
#+end_src
Input a matrix
#+begin_src octave :exports results :results silent :var s='((1 2) (3 4))
ans = s
#+end_src
Input a string
#+begin_src octave :exports results :results silent :var s="test"
ans = s(1:2)
#+end_src
Input elisp nil
#+begin_src octave :exports results :results silent :var s='nil
ans = s
#+end_src

View File

@ -0,0 +1,60 @@
;;; test-ob-octave.el --- tests for ob-octave.el
;; Copyright (c) 2010 Sergey Litvinov
;; Authors: Sergey Litvinov
;; Released under the GNU General Public License version 3
;; see: http://www.gnu.org/licenses/gpl-3.0.html
(org-test-for-executable "octave")
(let ((load-path (cons (expand-file-name
".." (file-name-directory
(or load-file-name buffer-file-name)))
load-path)))
(require 'org-test)
(require 'org-test-ob-consts))
(require 'ob-octave)
(ert-deftest ob-octave/input-none ()
"Number output"
(org-test-at-id "54dcd61d-cf6c-4d7a-b9e5-854953c8a753"
(org-babel-next-src-block)
(should (= 10 (org-babel-execute-src-block)))))
(ert-deftest ob-octave/output-vector ()
"Vector output"
(org-test-at-id "54dcd61d-cf6c-4d7a-b9e5-854953c8a753"
(org-babel-next-src-block 2)
(should (equal '((1 2 3 4)) (org-babel-execute-src-block)))))
(ert-deftest ob-octave/input-variable ()
"Input variable"
(org-test-at-id "cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba"
(org-babel-next-src-block)
(should (= 42 (org-babel-execute-src-block)))))
(ert-deftest ob-octave/input-array ()
"Input an array"
(org-test-at-id "cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba"
(org-babel-next-src-block 2)
(should (equal '((1 2 3)) (org-babel-execute-src-block)))))
(ert-deftest ob-octave/input-matrix ()
"Input a matrix"
(org-test-at-id "cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba"
(org-babel-next-src-block 3)
(should (equal '((1 2) (3 4)) (org-babel-execute-src-block)))))
(ert-deftest ob-octave/input-string ()
"Input a string"
(org-test-at-id "cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba"
(org-babel-next-src-block 4)
(should (equal "te" (org-babel-execute-src-block)))))
(ert-deftest ob-octave/input-nil ()
"Input elisp nil"
(org-test-at-id "cc2d82bb-2ac0-45be-a0c8-d1463b86a3ba"
(org-babel-next-src-block 5)
(should (equal nil (org-babel-execute-src-block)))))