diff --git a/test/net/sourceforge/plantuml/test/JunitUtils.java b/test/net/sourceforge/plantuml/test/JunitUtils.java new file mode 100644 index 000000000..8064ba1fc --- /dev/null +++ b/test/net/sourceforge/plantuml/test/JunitUtils.java @@ -0,0 +1,26 @@ +package net.sourceforge.plantuml.test; + +import org.junit.jupiter.params.converter.ArgumentConversionException; +import org.junit.jupiter.params.converter.SimpleArgumentConverter; + +import net.sourceforge.plantuml.json.Json; +import net.sourceforge.plantuml.json.JsonValue; + +/** + * Class to help test with `Junit`. + */ +public class JunitUtils { + /** + * `StringJsonConverter` class to use with `@ConvertWith`. + */ + public static class StringJsonConverter extends SimpleArgumentConverter { + @Override + protected Object convert(Object source, Class targetType) throws ArgumentConversionException { + if (source instanceof String) + return (JsonValue) Json.parse((String) source); + else + throw new IllegalArgumentException("Conversion from " + source.getClass() + " to " + + targetType + " not supported."); + } + } +} \ No newline at end of file diff --git a/test/net/sourceforge/plantuml/tim/TimTestUtils.java b/test/net/sourceforge/plantuml/tim/TimTestUtils.java new file mode 100644 index 000000000..81993d3a2 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/TimTestUtils.java @@ -0,0 +1,43 @@ +package net.sourceforge.plantuml.tim; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.tim.expression.TValue; +import net.sourceforge.plantuml.json.JsonValue; + +/** + * Class to help test of `tim/stdlib`. + */ +public class TimTestUtils { + + // Tfunc: () -> (String) + public static void assertTimExpectedOutput(TFunction func, String expected) throws EaterException, EaterExceptionLocated { + TValue tValue = func.executeReturnFunction(null, null, null, null, null); + assertEquals(expected, tValue.toString()); + } + + // Tfunc: (Integer) -> (String) + public static void assertTimExpectedOutputFromInput(TFunction func, Integer input, String expected) throws EaterException, EaterExceptionLocated { + List values = Collections.singletonList(TValue.fromInt(input)); + TValue tValue = func.executeReturnFunction(null, null, null, values, null); + assertEquals(expected, tValue.toString()); + } + + // Tfunc: (String) -> (String) + public static void assertTimExpectedOutputFromInput(TFunction func, String input, String expected) throws EaterException, EaterExceptionLocated { + List values = Collections.singletonList(TValue.fromString(input)); + TValue tValue = func.executeReturnFunction(null, null, null, values, null); + assertEquals(expected, tValue.toString()); + } + + // Tfunc: (JsonValue) -> (String) + public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + List values = Collections.singletonList(TValue.fromJson(input)); + TValue tValue = func.executeReturnFunction(null, null, null, values, null); + assertEquals(expected, tValue.toString()); + } + +} \ No newline at end of file diff --git a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java new file mode 100644 index 000000000..addb2050c --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysFalseTest.java @@ -0,0 +1,50 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class AlwaysFalseTest { + TFunction cut = new AlwaysFalse(); + final String cutName = "AlwaysFalse"; + + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 0 ", + " 'a' , 0 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 0 ", + " 123 , 0 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java new file mode 100644 index 000000000..439bde93d --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/AlwaysTrueTest.java @@ -0,0 +1,50 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class AlwaysTrueTest { + TFunction cut = new AlwaysTrue(); + final String cutName = "AlwaysTrue"; + + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "1"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 1 ", + " 1 , 1 ", + " 'a' , 1 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 1 ", + " 1 , 1 ", + " 123 , 1 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java b/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java new file mode 100644 index 000000000..1134c293d --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/Dec2hexTest.java @@ -0,0 +1,58 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class Dec2hexTest { + TFunction cut = new Dec2hex(); + final String cutName = "Dec2hex"; + + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, ""); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 0 ", + " 10 , 0 ", + " 15 , 0 ", + " 16 , 0 ", + " 255 , 0 ", + " 65535 , 0 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " 10 , a ", + " 15 , f ", + " 16 , 10 ", + " 255 , ff ", + " 65535 , ffff ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java b/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java new file mode 100644 index 000000000..74bdf712a --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/FeatureTest.java @@ -0,0 +1,68 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class FeatureTest { + TFunction cut = new Feature(); + final String cutName = "Feature"; + + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " style, 1", + " theme, 1", + " Style, 1", + " Theme, 1", + " 0 , 0", + " 1 , 0", + " abc , 0", + + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0, 0", + " 10, 0", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " \"style\", 1", + " \"theme\", 1", + " 0, 0", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java new file mode 100644 index 000000000..c9985befd --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonKeyTest.java @@ -0,0 +1,73 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class GetJsonKeyTest { + TFunction cut = new GetJsonKey(); + final String cutName = "GetJsonKey"; + + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @Disabled // EaterException: Not JSON data + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0, Not JSON data", + " a, Not JSON data", + " -1, Not JSON data", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @Disabled // EaterException: Not JSON data + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0, Not JSON data", + " -1, Not JSON data", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " [] , []", + " '{\"a\":[1, 2]}' , [\"a\"]", + " '[{\"a\":[1, 2]}]' , [\"a\"]", + " '{\"a\":\"abc\"}' , [\"a\"]", + " '[{\"a\":[1, 2]}, {\"b\":[3, 4]}]' , '[\"a\",\"b\"]'", + " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '[\"a\",\"b\",\"b\"]'", + // TODO: Manage Array with different type inside + // Ref.: + // - https://datatracker.ietf.org/doc/html/rfc8259#section-5 + // - https://json-schema.org/understanding-json-schema/reference/array.html + //" '[3, \"different\", { \"types\" : \"of values\" }]', [\"types\"]", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java new file mode 100644 index 000000000..1b720c9e5 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/GetJsonTypeTest.java @@ -0,0 +1,73 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class GetJsonTypeTest { + TFunction cut = new GetJsonType(); + final String cutName = "GetJsonType"; + + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0, string", + " a, string", + " -1, string", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0, number", + " -1, number", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " 0 , number", + " 123 , number", + " \"abc\" , string", + " \"string\" , string", + " '[1, 2]' , array", + " '[\"a\", \"b\"]' , array", + " '{\"a\":[1, 2]}' , object", + " '{\"a\":\"abc\"}' , object", + " true , boolean ", + " false , boolean ", + " 1 , number ", + " null , json ", + " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , object", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java b/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java new file mode 100644 index 000000000..329347b79 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/Hex2decTest.java @@ -0,0 +1,61 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class Hex2decTest { + TFunction cut = new Hex2dec(); + final String cutName = "Hex2dec"; + + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " a , 10 ", + " f , 15 ", + " 10 , 16 ", + " ff , 255 ", + " ffff , 65535 ", + " ' ' , 0 ", + " g , 0 ", + " -g , 0 ", + " à , 0 ", + " -1 , -1 ", + " -a , -10 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " 10 , 16 ", + " -1 , -1 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java b/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java new file mode 100644 index 000000000..d149c26b9 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/LowerTest.java @@ -0,0 +1,76 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class LowerTest { + TFunction cut = new Lower(); + final String cutName = "Lower"; + + // TODO: Manage Lower function without param. (today: we observe `Function not found %lower`) + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, ""); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " A , a ", + " a , a ", + " F , f ", + " G , g ", + " É , é ", + " 😀 , 😀 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " 10 , 10 ", + " -1 , -1 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " '{\"a\":[1, 2]}' , '{\"a\":[1,2]}'", + " '{\"A\":[1, 2]}' , '{\"a\":[1,2]}'", + " '[1, 2]' , '[1,2]'", + " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}'", + " '{\"A\":[1, 2], \"B\":\"ABC\", \"B\":true}' , '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}' ", + " true, true" + // TODO: See JSON management of TRUE/FALSE + //" TRUE , true ", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java b/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java new file mode 100644 index 000000000..137ff9bef --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/SizeTest.java @@ -0,0 +1,81 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class SizeTest { + TFunction cut = new Size(); + final String cutName = "Size"; + + // TODO: Manage `Size` function without param. (today: we observe `Function not found`) + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 1 ", + " 1 , 1 ", + " 10 , 2 ", + " a , 1 ", + " A , 1 ", + " ABC , 3 ", + " '[1, 2]' , 6 ", + " '{[1, 2]}' , 8 ", + " à , 1 ", +// TODO: fix `Size` to allow Unicode chars, the corresponding tests are here: +// " 😀 , 1 ", +// " \uD83D\uDE00 , 1", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 0 ", + " 10 , 0 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " 0, 0", + " \"abc\", 0", + " '\"abc\"', 0", + " '{\"a\":[1, 2]}' , 1", + " '[1, 2]' , 2", + " '[\"a\", \"b\"]' , 2", + " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , 3", + " true, 0 ", + " 1, 0 ", + " null, 0 ", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java b/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java new file mode 100644 index 000000000..049f0b531 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/UpperTest.java @@ -0,0 +1,72 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +class UpperTest { + TFunction cut = new Upper(); + final String cutName = "Upper"; + + // TODO: Manage Upper function without param. (today: we observe `Function not found %upper`) + @Disabled + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, ""); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " a , A ", + " A , A ", + " f , F ", + " g , G ", + " é , É ", + " 😀 , 😀 ", + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0 , 0 ", + " 1 , 1 ", + " 10 , 10 ", + " -1 , -1 ", + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " '{\"a\":[1, 2]}' , '{\"A\":[1,2]}'", + " '[1, 2]' , '[1,2]'", + " '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}' , '{\"A\":[1,2],\"B\":\"ABC\",\"B\":TRUE}'", + " true , TRUE ", + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +} diff --git a/test/net/sourceforge/plantuml/tim/stdlib/_TemplateStdlibTest.template b/test/net/sourceforge/plantuml/tim/stdlib/_TemplateStdlibTest.template new file mode 100644 index 000000000..a949f6023 --- /dev/null +++ b/test/net/sourceforge/plantuml/tim/stdlib/_TemplateStdlibTest.template @@ -0,0 +1,59 @@ +package net.sourceforge.plantuml.tim.stdlib; + +import static net.sourceforge.plantuml.test.JunitUtils.StringJsonConverter; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutput; +import static net.sourceforge.plantuml.tim.TimTestUtils.assertTimExpectedOutputFromInput; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; +import org.junit.jupiter.api.IndicativeSentencesGeneration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import net.sourceforge.plantuml.json.JsonValue; +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.EaterExceptionLocated; +import net.sourceforge.plantuml.tim.TFunction; + +/** + * Tests the builtin function. + */ +@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class) + +// Change `XXX` by the name of the tim.stdlib Class Under Test +@Disabled +class XXXTest { + TFunction cut = new XXX(); + final String cutName = "XXX"; + + @Test + void Test_without_Param() throws EaterException, EaterExceptionLocated { + assertTimExpectedOutput(cut, "0"); // Change expected value here + } + + @ParameterizedTest(name = "[{index}] " + cutName + "(''{0}'') = {1}") + @CsvSource(nullValues = "null", value = { + " 0, 0", // Put test values here + }) + void Test_with_String(String input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(nullValues = "null", value = { + " 0, 0", // Put test values here + }) + void Test_with_Integer(Integer input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } + + @ParameterizedTest(name = "[{index}] " + cutName + "({0}) = {1}") + @CsvSource(value = { + " 0, 0", // Put test values here + }) + void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException, EaterExceptionLocated { + assertTimExpectedOutputFromInput(cut, input, expected); + } +}