aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ravanan/javascript.scm42
-rw-r--r--tests/javascript.scm27
2 files changed, 40 insertions, 29 deletions
diff --git a/ravanan/javascript.scm b/ravanan/javascript.scm
index a416d27..d57a02d 100644
--- a/ravanan/javascript.scm
+++ b/ravanan/javascript.scm
@@ -175,21 +175,27 @@ keys @code{\"inputs\"}, @code{\"self\"} and @code{\"runtime\"}.
;; token is a string literal.
token))
- (let ((evaluated-tokens (map evaluate-token
- (tokenize-parameter-references str))))
- (if context
- ;; Evaluate immediately.
- (string-join (map (lambda (token)
- (if (string? token)
- token
- (scm->json-string (canonicalize-json token))))
- evaluated-tokens)
- "")
- ;; Compile to a G-expression that interpolates parameter reference
- ;; string.
- #~(string-join (map (lambda (token)
- (if (string? token)
- token
- (scm->json-string (canonicalize-json token))))
- (list #$@evaluated-tokens))
- ""))))
+ (match (tokenize-parameter-references str)
+ ;; There is only one token. This is not a string interpolation. Do not
+ ;; serialize JSON.
+ ((only-token)
+ (evaluate-token only-token))
+ ;; This is a string interpolation. Evaluate tokens and serialize JSON.
+ (tokens
+ (let ((evaluated-tokens (map evaluate-token tokens)))
+ (if context
+ ;; Evaluate immediately.
+ (string-join (map (lambda (token)
+ (if (string? token)
+ token
+ (scm->json-string (canonicalize-json token))))
+ evaluated-tokens)
+ "")
+ ;; Compile to a G-expression that interpolates parameter reference
+ ;; string.
+ #~(string-join (map (lambda (token)
+ (if (string? token)
+ token
+ (scm->json-string (canonicalize-json token))))
+ (list #$@evaluated-tokens))
+ ""))))))
diff --git a/tests/javascript.scm b/tests/javascript.scm
index c766ac3..75936c0 100644
--- a/tests/javascript.scm
+++ b/tests/javascript.scm
@@ -40,6 +40,14 @@
(evaluate-parameter-reference "$(inputs.message['bar'][\"foo\"][2])"
'(("inputs" ("message" ("bar" ("foo" . #("a" "b" "c" "d"))))))))
+(test-equal "evaluate parameter reference to JSON object"
+ '(("class" . "File")
+ ("path" . "/foo/bar"))
+ (evaluate-parameter-reference "$(inputs.fasta)"
+ '(("inputs" ("fasta"
+ ("class" . "File")
+ ("path" . "/foo/bar"))))))
+
(test-equal "evaluate parameter reference with string interpolation"
"24foo12foobar"
(evaluate-parameter-reference "$(runtime.cores)foo$(inputs.threads)$(inputs.output_filename)"
@@ -58,10 +66,15 @@
("vector" . #(0 1 2 3))))))
(test-equal "evaluate parameter reference with node"
- "3"
+ 3
(evaluate-parameter-reference "$(inputs.n + 1)"
'(("inputs" ("n" . 2)))))
+(test-equal "evaluate parameter reference to JSON object using node"
+ '(json-ref inputs "fasta")
+ (gexp->sexp-rec
+ (evaluate-parameter-reference "$(inputs.fasta)")))
+
(test-equal "evaluate parameter reference with string interpolation using node"
"24foo24foobar"
(evaluate-parameter-reference "$(runtime.cores)foo$(inputs.threads*2)$(inputs.output_filename)"
@@ -80,11 +93,7 @@
("vector" . #(0 1 2 3))))))
(test-equal "evaluate parameter reference (without context)"
- '(string-join
- (map (lambda (token)
- (if (string? token) token (scm->json-string (canonicalize-json token))))
- (list (json-ref inputs "message" "bar" "foo" 2)))
- "")
+ '(json-ref inputs "message" "bar" "foo" 2)
(gexp->sexp-rec
(evaluate-parameter-reference "$(inputs.message['bar'][\"foo\"][2])")))
@@ -110,11 +119,7 @@
(evaluate-parameter-reference "foo$(inputs.vector)$(inputs.object)")))
(test-equal "evaluate parameter reference with node (without context)"
- '(string-join
- (map (lambda (token)
- (if (string? token) token (scm->json-string (canonicalize-json token))))
- (list (evaluate-javascript (*approximate*) "(inputs.n + 1)" "")))
- "")
+ '(evaluate-javascript (*approximate*) "(inputs.n + 1)" "")
(gexp->sexp-rec
(evaluate-parameter-reference "$(inputs.n + 1)")))