From bd4ccd3afdd185c1030336d86c2c15726f9e874a Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 17 Dec 2025 16:11:04 +0000 Subject: javascript: Tokenize using PEG grammar. Javascript expressions may contain recursively nested parentheses. Matching these parentheses and tokenizing correctly requires a real parser. --- tests/javascript.scm | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tests/javascript.scm') 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") -- cgit 1.4.1