From 7a48cad1f81c8bea8bf2b7288920d403a37c8ef5 Mon Sep 17 00:00:00 2001 From: Enrico Daga Date: Fri, 30 Jun 2023 14:38:44 +0100 Subject: [PATCH] Fix #152 --- .../engine/functions/reflection/Converters.java | 4 ++++ .../io/github/sparqlanything/engine/test/FunctionsTest.java | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/functions/reflection/Converters.java b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/functions/reflection/Converters.java index d602633d..ea9f8833 100644 --- a/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/functions/reflection/Converters.java +++ b/sparql-anything-engine/src/main/java/io/github/sparqlanything/engine/functions/reflection/Converters.java @@ -54,6 +54,10 @@ public Character asType(NodeValue nodeValue) { public NodeValueString asNodeValue(Character object) { return (NodeValueString) NodeValue.makeNodeString(object.toString()); } + + public boolean compatibleWith(NodeValue nodeValue){ + return nodeValue.getClass().equals(getNodeValueType()) && nodeValue.getString().length() == 1; + } } public static class StringConverter implements NodeValueConverter { diff --git a/sparql-anything-engine/src/test/java/io/github/sparqlanything/engine/test/FunctionsTest.java b/sparql-anything-engine/src/test/java/io/github/sparqlanything/engine/test/FunctionsTest.java index c8fd5675..0e3b2d8b 100644 --- a/sparql-anything-engine/src/test/java/io/github/sparqlanything/engine/test/FunctionsTest.java +++ b/sparql-anything-engine/src/test/java/io/github/sparqlanything/engine/test/FunctionsTest.java @@ -415,6 +415,10 @@ public void testWordUtilsFunctions() { testStringFunction("fx:WordUtils.uncapitalize", WordUtils.uncapitalize("TEST"), "TEST"); } + @Test + public void testStringReplace(){ + testStringFunction("fx:String.replace", "test".replace("te", "fe"), "test", Lists.newArrayList("te", "fe")); + } @Test public void testStringFunctions(){ testStringFunction("fx:String.trim", " test ".trim(), "test"); @@ -423,8 +427,8 @@ public void testStringFunctions(){ testStringFunction("fx:String.indexOf", String.valueOf("test".indexOf("e")), "test", Lists.newArrayList("e")); testStringFunction("fx:String.startsWith", String.valueOf("test".startsWith("te")), "test", Lists.newArrayList("te")); testStringFunction("fx:String.endsWith", String.valueOf("test".endsWith("st")), "test", Lists.newArrayList("st")); - testStringFunction("fx:String.replace", "test".replace("te", "fe"), "test", Lists.newArrayList("te", "fe")); testStringFunction("fx:String.replace", "test".replace("t", "f"), "test", Lists.newArrayList("t", "f")); + testStringFunction("fx:String.replace", "test".replace("te", "fe"), "test", Lists.newArrayList("te", "fe")); testStringFunction("fx:String.strip", " test \t".strip(), " test \t"); testStringFunction("fx:String.stripLeading", " test \t".stripLeading(), " test \t"); testStringFunction("fx:String.stripTrailing", " test \t".stripTrailing(), " test \t");