about summary refs log tree commit diff
path: root/tests/javascript.scm
diff options
context:
space:
mode:
authorArun Isaac2025-12-17 16:11:04 +0000
committerArun Isaac2025-12-17 16:13:04 +0000
commitbd4ccd3afdd185c1030336d86c2c15726f9e874a (patch)
tree5bb90742f56abe9bbfe3b00f1cb4d611722d0a1f /tests/javascript.scm
parentd7a92a2976874cbb9584d943e88e8ccdfd810d53 (diff)
downloadravanan-bd4ccd3afdd185c1030336d86c2c15726f9e874a.tar.gz
ravanan-bd4ccd3afdd185c1030336d86c2c15726f9e874a.tar.lz
ravanan-bd4ccd3afdd185c1030336d86c2c15726f9e874a.zip
javascript: Tokenize using PEG grammar.
Javascript expressions may contain recursively nested parentheses.
Matching these parentheses and tokenizing correctly requires a real
parser.
Diffstat (limited to 'tests/javascript.scm')
-rw-r--r--tests/javascript.scm21
1 files changed, 13 insertions, 8 deletions
diff --git a/tests/javascript.scm b/tests/javascript.scm
index c670e98..9f86e7f 100644
--- a/tests/javascript.scm
+++ b/tests/javascript.scm
@@ -110,8 +110,8 @@
 
 (test-equal "evaluate parameter reference with string interpolation (without context)"
   '(string-join
-    (map (lambda (token)
-           (if (string? token) token (scm->json-string (canonicalize-json token))))
+    (map (lambda (value)
+           (if (string? value) value (scm->json-string (canonicalize-json value))))
          (list (json-ref runtime "cores")
                "foo"
                (json-ref inputs "threads")
@@ -122,8 +122,8 @@
 
 (test-equal "evaluate parameter reference with string interpolation of JSON trees (without context)"
   '(string-join
-    (map (lambda (token)
-           (if (string? token) token (scm->json-string (canonicalize-json token))))
+    (map (lambda (value)
+           (if (string? value) value (scm->json-string (canonicalize-json value))))
          (list "foo" (json-ref inputs "vector") (json-ref inputs "object")))
     "")
   (gexp->sexp-rec
@@ -141,8 +141,8 @@
 
 (test-equal "evaluate parameter reference with string interpolation using node (without context)"
   '(string-join
-    (map (lambda (token)
-           (if (string? token) token (scm->json-string (canonicalize-json token))))
+    (map (lambda (value)
+           (if (string? value) value (scm->json-string (canonicalize-json value))))
          (list (json-ref runtime "cores")
                "foo"
                (evaluate-javascript (*approximate*)
@@ -158,8 +158,8 @@
 
 (test-equal "evaluate parameter reference with string interpolation of JSON trees using node (without context)"
   '(string-join
-    (map (lambda (token)
-           (if (string? token) token (scm->json-string (canonicalize-json token))))
+    (map (lambda (value)
+           (if (string? value) value (scm->json-string (canonicalize-json value))))
          (list "foo"
                (json-ref inputs "vector")
                (json-ref inputs "object")
@@ -173,4 +173,9 @@
   (gexp->sexp-rec
    (evaluate-javascript-expression "foo$(inputs.vector)$(inputs.object)$(inputs.object.foo*20)")))
 
+(test-equal "evaluate javascript expression with parentheses"
+  0
+  (evaluate-javascript-expression "$(1 - (2 - 1))"
+                                  '()))
+
 (test-end "javascript")