* [PATCH][babel] add a string input to ob-octave
@ 2011-10-01 0:16 Litvinov Sergey
2011-10-01 7:10 ` Nicolas Goaziou
0 siblings, 1 reply; 4+ messages in thread
From: Litvinov Sergey @ 2011-10-01 0:16 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 106 bytes --]
Please consider a tiny patch to add a string input variable to
ob-octave. I also add tests for ob-octave.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-string-input-variables-to-ob-octave.el.-Add-test.patch --]
[-- Type: text/x-diff, Size: 4995 bytes --]
From 4848960cefc1b1486705f7aed022ba199189b6e1 Mon Sep 17 00:00:00 2001
From: Litvinov Sergey <slitvinov@gmail.com>
Date: Sat, 1 Oct 2011 02:04:49 +0200
Subject: [PATCH] Add string input variables to ob-octave.el. Add tests for ob-octave.el
---
lisp/ob-octave.el | 6 +++-
testing/README.org | 1 +
testing/examples/ob-octave-test.org | 43 +++++++++++++++++++++++++++
testing/lisp/test-ob-octave.el | 55 +++++++++++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 1 deletions(-)
create mode 100644 testing/examples/ob-octave-test.org
create mode 100644 testing/lisp/test-ob-octave.el
diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index 3d90954..cfc1f1d 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -117,7 +117,11 @@ specifying a variable of the same value."
(if (listp var)
(concat "[" (mapconcat #'org-babel-octave-var-to-octave var
(if (listp (car var)) "; " ",")) "]")
- (format "%s" (or var "nil"))))
+ (cond
+ ((stringp var)
+ (format "\'%s\'" (or var "nil")))
+ (t
+ (format "%s" (or var "nil"))))))
(defun org-babel-prep-session:octave (session params &optional matlabp)
"Prepare SESSION according to the header arguments specified in PARAMS."
diff --git a/testing/README.org b/testing/README.org
index 2f16a55..221a33c 100644
--- a/testing/README.org
+++ b/testing/README.org
@@ -79,6 +79,7 @@ First tangle this file out to your desktop.
(list (concat org-dir "/testing/examples/babel.org")
(concat org-dir "/testing/examples/normal.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/link-in-heading.org")
(concat org-dir "/testing/examples/links.org")))
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
new file mode 100644
index 0000000..37cf3f9
--- /dev/null
+++ b/testing/examples/ob-octave-test.org
@@ -0,0 +1,43 @@
+#+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
+
+
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
new file mode 100644
index 0000000..f3972ec
--- /dev/null
+++ b/testing/lisp/test-ob-octave.el
@@ -0,0 +1,55 @@
+;;; 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)))))
+
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][babel] add a string input to ob-octave
2011-10-01 0:16 [PATCH][babel] add a string input to ob-octave Litvinov Sergey
@ 2011-10-01 7:10 ` Nicolas Goaziou
2011-10-01 11:49 ` Litvinov Sergey
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2011-10-01 7:10 UTC (permalink / raw)
To: Litvinov Sergey; +Cc: emacs-orgmode
Hello,
Litvinov Sergey <slitvinov@gmail.com> writes:
> + (cond
> + ((stringp var)
> + (format "\'%s\'" (or var "nil")))
> + (t
> + (format "%s" (or var "nil"))))))
Just nitpicking:
In the first case, var is already identified as a string, so it will
always be non-nil, and your "or" is useless.
In the second case, (or var "nil") is redundant, as (format "%s" nil)
already returns "nil".
In other words, replacing (or var "nil") with var would be enough in
both cases.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][babel] add a string input to ob-octave
2011-10-01 7:10 ` Nicolas Goaziou
@ 2011-10-01 11:49 ` Litvinov Sergey
2011-10-06 14:49 ` Eric Schulte
0 siblings, 1 reply; 4+ messages in thread
From: Litvinov Sergey @ 2011-10-01 11:49 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 136 bytes --]
> In other words, replacing (or var "nil") with var would be enough
Thanks. Fixed in the patch below. The patch also adds an ert test.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-Remove-redundant-condition-check-in-ob-octave.el.-Ad.patch --]
[-- Type: text/x-diff, Size: 2063 bytes --]
From b4b679abdc7bec9f3033b50f81d567a0bb48b147 Mon Sep 17 00:00:00 2001
From: Litvinov Sergey <slitvinov@gmail.com>
Date: Sat, 1 Oct 2011 13:37:56 +0200
Subject: [PATCH 2/2] Remove redundant condition check in ob-octave.el. Add a test.
---
lisp/ob-octave.el | 4 ++--
testing/examples/ob-octave-test.org | 6 ++++--
testing/lisp/test-ob-octave.el | 6 ++++++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
index cfc1f1d..f840739 100644
--- a/lisp/ob-octave.el
+++ b/lisp/ob-octave.el
@@ -119,9 +119,9 @@ specifying a variable of the same value."
(if (listp (car var)) "; " ",")) "]")
(cond
((stringp var)
- (format "\'%s\'" (or var "nil")))
+ (format "\'%s\'" var))
(t
- (format "%s" (or var "nil"))))))
+ (format "%s" var)))))
(defun org-babel-prep-session:octave (session params &optional matlabp)
"Prepare SESSION according to the header arguments specified in PARAMS."
diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
index 37cf3f9..97d9b00 100644
--- a/testing/examples/ob-octave-test.org
+++ b/testing/examples/ob-octave-test.org
@@ -24,7 +24,6 @@ Input an integer variable
ans = s
#+end_src
-
Input an array
#+begin_src octave :exports results :results silent :var s='(1.0 2.0 3.0)
ans = s
@@ -40,4 +39,7 @@ Input a string
ans = s(1:2)
#+end_src
-
+Input elisp nil
+#+begin_src octave :exports results :results silent :var s='nil
+ans = s
+#+end_src
diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
index f3972ec..145266d 100644
--- a/testing/lisp/test-ob-octave.el
+++ b/testing/lisp/test-ob-octave.el
@@ -53,3 +53,9 @@
(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)))))
+
--
1.7.4.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][babel] add a string input to ob-octave
2011-10-01 11:49 ` Litvinov Sergey
@ 2011-10-06 14:49 ` Eric Schulte
0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2011-10-06 14:49 UTC (permalink / raw)
To: Litvinov Sergey; +Cc: emacs-orgmode
Fantastic,
I will apply this as soon as your FSF attribution goes through.
Speaking of has there been any progress on that front?
Thanks -- Eric
Litvinov Sergey <slitvinov@gmail.com> writes:
>> In other words, replacing (or var "nil") with var would be enough
>
> Thanks. Fixed in the patch below. The patch also adds an ert test.
>
> From b4b679abdc7bec9f3033b50f81d567a0bb48b147 Mon Sep 17 00:00:00 2001
> From: Litvinov Sergey <slitvinov@gmail.com>
> Date: Sat, 1 Oct 2011 13:37:56 +0200
> Subject: [PATCH 2/2] Remove redundant condition check in ob-octave.el. Add a test.
>
> ---
> lisp/ob-octave.el | 4 ++--
> testing/examples/ob-octave-test.org | 6 ++++--
> testing/lisp/test-ob-octave.el | 6 ++++++
> 3 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/lisp/ob-octave.el b/lisp/ob-octave.el
> index cfc1f1d..f840739 100644
> --- a/lisp/ob-octave.el
> +++ b/lisp/ob-octave.el
> @@ -119,9 +119,9 @@ specifying a variable of the same value."
> (if (listp (car var)) "; " ",")) "]")
> (cond
> ((stringp var)
> - (format "\'%s\'" (or var "nil")))
> + (format "\'%s\'" var))
> (t
> - (format "%s" (or var "nil"))))))
> + (format "%s" var)))))
>
> (defun org-babel-prep-session:octave (session params &optional matlabp)
> "Prepare SESSION according to the header arguments specified in PARAMS."
> diff --git a/testing/examples/ob-octave-test.org b/testing/examples/ob-octave-test.org
> index 37cf3f9..97d9b00 100644
> --- a/testing/examples/ob-octave-test.org
> +++ b/testing/examples/ob-octave-test.org
> @@ -24,7 +24,6 @@ Input an integer variable
> ans = s
> #+end_src
>
> -
> Input an array
> #+begin_src octave :exports results :results silent :var s='(1.0 2.0 3.0)
> ans = s
> @@ -40,4 +39,7 @@ Input a string
> ans = s(1:2)
> #+end_src
>
> -
> +Input elisp nil
> +#+begin_src octave :exports results :results silent :var s='nil
> +ans = s
> +#+end_src
> diff --git a/testing/lisp/test-ob-octave.el b/testing/lisp/test-ob-octave.el
> index f3972ec..145266d 100644
> --- a/testing/lisp/test-ob-octave.el
> +++ b/testing/lisp/test-ob-octave.el
> @@ -53,3 +53,9 @@
> (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)))))
> +
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-10-06 15:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-01 0:16 [PATCH][babel] add a string input to ob-octave Litvinov Sergey
2011-10-01 7:10 ` Nicolas Goaziou
2011-10-01 11:49 ` Litvinov Sergey
2011-10-06 14:49 ` Eric Schulte
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).