You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@jena.apache.org by GitBox <gi...@apache.org> on 2021/03/25 19:31:29 UTC

[GitHub] [jena] afs commented on a change in pull request #967: JENA-1951: Finish merge; remove legacy; adjust for RDF-star

afs commented on a change in pull request #967:
URL: https://github.com/apache/jena/pull/967#discussion_r601783360



##########
File path: jena-arq/src/test/java/org/apache/jena/sparql/function/scripting/TestScriptFunction.java
##########
@@ -16,183 +16,222 @@
  * limitations under the License.
  */
 
-package org.apache.jena.sparql.function.js;
+package org.apache.jena.sparql.function.scripting;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Arrays;
-
-import org.apache.jena.atlas.lib.StrUtils;
 import org.apache.jena.datatypes.xsd.XSDDatatype;
 import org.apache.jena.query.ARQ;
 import org.apache.jena.sparql.expr.ExprEvalException;
 import org.apache.jena.sparql.expr.NodeValue;
 import org.apache.jena.sparql.sse.SSE;
 import org.apache.jena.sparql.util.Context;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.junit.Assert.*;
+
+@RunWith(Parameterized.class)
+public class TestScriptFunction {
+    private static Context ctx = ARQ.getContext();
+
+    private String language;
+    private String library;
+    private String functions;
 
-public class TestJavaScriptFunctions {
-    static final String JS_LIB_FILE = "testing/ARQ/JS/test-library.js";
-    
-    static final String CamelCaseJS = 
-        StrUtils.strjoinNL
-         ("function toCamelCase(str) { return str.split(' ').map(cc).join('');}"
-         ,"function ucFirst(word)    { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}"
-         ,"function lcFirst(word)    { return word.toLowerCase(); }"
-         ,"function cc(word,index)   { return (index == 0) ? lcFirst(word) : ucFirst(word); }"
-         );
+    @Parameterized.Parameters
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                { "js", "testing/ARQ/Scripting/test-library.js",
+                        "function toCamelCase(str) { return str.split(' ').map(cc).join('');}\n"
+                        + "function ucFirst(word)    { return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();}\n"
+                        + "function lcFirst(word)    { return word.toLowerCase(); }\n"
+                        + "function cc(word,index)   { return (index == 0) ? lcFirst(word) : ucFirst(word); }\n" }
+                , {"python", "testing/ARQ/Scripting/test-library.py",
+                        "def toCamelCase(str):\n" +
+                        "  return ''.join([cc(word, index) for index, word in enumerate(str.split(' '))])\n" +
+                        "def ucFirst(word):\n" +
+                        "  return word[0].upper() + word[1:].lower()\n" +
+                        "def lcFirst(word):\n" +
+                        "  return word.lower()\n" +
+                        "def cc(word,index):\n" +
+                        "  if index == 0:\n" +
+                        "    return lcFirst(word)\n" +
+                        "  return ucFirst(word)\n" }
+        });
+    }
+
+
+    public TestScriptFunction(String language, String library, String functions) {
+        this.language = language;
+        this.library = library;
+        this.functions = functions;
+    }
 
-    private static EnvJavaScript setupJS() {
-        Context cxt = ARQ.getContext().copy();
-        cxt.set(EnvJavaScript.symJavaScriptFunctions, CamelCaseJS);
-        cxt.set(EnvJavaScript.symJavaScriptLibFile, JS_LIB_FILE);
-        return EnvJavaScript.create(cxt);
+    @Before
+    public void setup() {
+        ctx.set(LanguageSymbols.scriptLibrary(language), library);
+        ctx.set(LanguageSymbols.scriptFunctions(language), functions);
     }
 
-    private EnvJavaScript envJS = setupJS();
+    @After
+    public void teardown() {
+        ctx.unset(LanguageSymbols.scriptFunctions(language));
+        ctx.unset(LanguageSymbols.scriptFunctions(language));

Review comment:
       good catch.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@jena.apache.org
For additional commands, e-mail: pr-help@jena.apache.org