mirror of
https://github.com/octoleo/plantuml.git
synced 2024-09-27 22:49:04 +00:00
Compare commits
No commits in common. "81e7e76c5083aebb1866e401fb7c40e0b9f26bc6" and "91e87b9691630d27249f186ece2ffcae823a2bf8" have entirely different histories.
81e7e76c50
...
91e87b9691
@ -46,7 +46,6 @@ import net.sourceforge.plantuml.cheneer.command.CommandEndGroup;
|
||||
import net.sourceforge.plantuml.cheneer.command.CommandMultiSubclass;
|
||||
import net.sourceforge.plantuml.cheneer.command.CommandSimpleSubclass;
|
||||
import net.sourceforge.plantuml.command.Command;
|
||||
import net.sourceforge.plantuml.command.CommandRankDir;
|
||||
import net.sourceforge.plantuml.command.CommonCommands;
|
||||
import net.sourceforge.plantuml.command.PSystemCommandFactory;
|
||||
import net.sourceforge.plantuml.core.DiagramType;
|
||||
@ -60,8 +59,8 @@ public class ChenEerDiagramFactory extends PSystemCommandFactory {
|
||||
|
||||
@Override
|
||||
protected void initCommandsList(List<Command> cmds) {
|
||||
CommonCommands.addCommonCommands1(cmds);
|
||||
cmds.add(new CommandRankDir());
|
||||
CommonCommands.addTitleCommands(cmds);
|
||||
CommonCommands.addCommonCommands2(cmds);
|
||||
|
||||
cmds.add(new CommandCreateEntity());
|
||||
cmds.add(new CommandCreateAttribute());
|
||||
|
@ -110,9 +110,7 @@ import net.sourceforge.plantuml.tim.stdlib.IntVal;
|
||||
import net.sourceforge.plantuml.tim.stdlib.InvokeProcedure;
|
||||
import net.sourceforge.plantuml.tim.stdlib.IsDark;
|
||||
import net.sourceforge.plantuml.tim.stdlib.IsLight;
|
||||
import net.sourceforge.plantuml.tim.stdlib.JsonAdd;
|
||||
import net.sourceforge.plantuml.tim.stdlib.JsonKeyExists;
|
||||
import net.sourceforge.plantuml.tim.stdlib.JsonRemove;
|
||||
import net.sourceforge.plantuml.tim.stdlib.Lighten;
|
||||
import net.sourceforge.plantuml.tim.stdlib.LoadJson;
|
||||
import net.sourceforge.plantuml.tim.stdlib.LogicalAnd;
|
||||
@ -134,7 +132,6 @@ import net.sourceforge.plantuml.tim.stdlib.SetVariableValue;
|
||||
import net.sourceforge.plantuml.tim.stdlib.Size;
|
||||
import net.sourceforge.plantuml.tim.stdlib.SplitStr;
|
||||
import net.sourceforge.plantuml.tim.stdlib.SplitStrRegex;
|
||||
import net.sourceforge.plantuml.tim.stdlib.Str2Json;
|
||||
import net.sourceforge.plantuml.tim.stdlib.StringFunction;
|
||||
import net.sourceforge.plantuml.tim.stdlib.Strlen;
|
||||
import net.sourceforge.plantuml.tim.stdlib.Strpos;
|
||||
@ -219,9 +216,6 @@ public class TContext {
|
||||
functionsSet.addFunction(new GetAllTheme());
|
||||
functionsSet.addFunction(new GetAllStdlib());
|
||||
functionsSet.addFunction(new SplitStrRegex());
|
||||
functionsSet.addFunction(new Str2Json());
|
||||
functionsSet.addFunction(new JsonAdd());
|
||||
functionsSet.addFunction(new JsonRemove());
|
||||
// %standard_exists_function
|
||||
// %str_replace
|
||||
// !exit
|
||||
|
@ -1,89 +0,0 @@
|
||||
/* ========================================================================
|
||||
* PlantUML : a free UML diagram generator
|
||||
* ========================================================================
|
||||
*
|
||||
* (C) Copyright 2009-2021, Arnaud Roques
|
||||
*
|
||||
* Project Info: https://plantuml.com
|
||||
*
|
||||
* If you like this project or if you find it useful, you can support us at:
|
||||
*
|
||||
* https://plantuml.com/patreon (only 1$ per month!)
|
||||
* https://plantuml.com/paypal
|
||||
*
|
||||
* This file is part of PlantUML.
|
||||
*
|
||||
* PlantUML is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PlantUML distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
* USA.
|
||||
*
|
||||
*
|
||||
* Original Author: Arnaud Roques
|
||||
* Contribution: The-Lum
|
||||
*
|
||||
*/
|
||||
package net.sourceforge.plantuml.tim.stdlib;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.plantuml.json.JsonArray;
|
||||
import net.sourceforge.plantuml.json.JsonObject;
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.text.StringLocated;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TContext;
|
||||
import net.sourceforge.plantuml.tim.TFunctionSignature;
|
||||
import net.sourceforge.plantuml.tim.TMemory;
|
||||
import net.sourceforge.plantuml.tim.expression.TValue;
|
||||
|
||||
public class JsonAdd extends SimpleReturnFunction {
|
||||
|
||||
public TFunctionSignature getSignature() {
|
||||
return new TFunctionSignature("%json_add", 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
||||
return nbArg == 2 || nbArg == 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List<TValue> values,
|
||||
Map<String, TValue> named) throws EaterException {
|
||||
final TValue data = values.get(0);
|
||||
if (data.isJson() == false)
|
||||
throw new EaterException("Not JSON data", location);
|
||||
|
||||
final JsonValue json = data.toJson();
|
||||
|
||||
if (!json.isArray() && !json.isObject())
|
||||
return data;
|
||||
if (json.isArray()) {
|
||||
final JsonValue value = values.get(1).toJson();
|
||||
final JsonArray array = (JsonArray) json;
|
||||
array.add(value);
|
||||
return TValue.fromJson(array);
|
||||
}
|
||||
if (json.isObject()) {
|
||||
final String name = values.get(1).toString();
|
||||
final JsonValue value = values.get(2).toJson();
|
||||
final JsonObject object = (JsonObject) json;
|
||||
object.add(name, value);
|
||||
return TValue.fromJson(object);
|
||||
}
|
||||
throw new EaterException("Bad JSON type", location);
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/* ========================================================================
|
||||
* PlantUML : a free UML diagram generator
|
||||
* ========================================================================
|
||||
*
|
||||
* (C) Copyright 2009-2021, Arnaud Roques
|
||||
*
|
||||
* Project Info: https://plantuml.com
|
||||
*
|
||||
* If you like this project or if you find it useful, you can support us at:
|
||||
*
|
||||
* https://plantuml.com/patreon (only 1$ per month!)
|
||||
* https://plantuml.com/paypal
|
||||
*
|
||||
* This file is part of PlantUML.
|
||||
*
|
||||
* PlantUML is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PlantUML distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
* USA.
|
||||
*
|
||||
*
|
||||
* Original Author: Arnaud Roques
|
||||
* Contribution: The-Lum
|
||||
*
|
||||
*/
|
||||
package net.sourceforge.plantuml.tim.stdlib;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.plantuml.json.JsonArray;
|
||||
import net.sourceforge.plantuml.json.JsonObject;
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.text.StringLocated;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TContext;
|
||||
import net.sourceforge.plantuml.tim.TFunctionSignature;
|
||||
import net.sourceforge.plantuml.tim.TMemory;
|
||||
import net.sourceforge.plantuml.tim.expression.TValue;
|
||||
|
||||
public class JsonRemove extends SimpleReturnFunction {
|
||||
|
||||
public TFunctionSignature getSignature() {
|
||||
return new TFunctionSignature("%json_remove", 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
||||
return nbArg == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List<TValue> values,
|
||||
Map<String, TValue> named) throws EaterException {
|
||||
final TValue data = values.get(0);
|
||||
if (data.isJson() == false)
|
||||
throw new EaterException("Not JSON data", location);
|
||||
|
||||
final JsonValue json = data.toJson();
|
||||
|
||||
if (!json.isArray() && !json.isObject())
|
||||
return data;
|
||||
if (json.isArray()) {
|
||||
final JsonArray array = (JsonArray) json;
|
||||
if (values.get(1).isNumber()) {
|
||||
final Integer index = values.get(1).toInt();
|
||||
if (0 <= index && index < array.size())
|
||||
array.remove(index);
|
||||
}
|
||||
return TValue.fromJson(array);
|
||||
}
|
||||
if (json.isObject()) {
|
||||
final JsonObject object = (JsonObject) json;
|
||||
final String name = values.get(1).toString();
|
||||
object.remove(name);
|
||||
return TValue.fromJson(object);
|
||||
}
|
||||
throw new EaterException("Bad JSON type", location);
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/* ========================================================================
|
||||
* PlantUML : a free UML diagram generator
|
||||
* ========================================================================
|
||||
*
|
||||
* (C) Copyright 2009-2021, Arnaud Roques
|
||||
*
|
||||
* Project Info: https://plantuml.com
|
||||
*
|
||||
* If you like this project or if you find it useful, you can support us at:
|
||||
*
|
||||
* https://plantuml.com/patreon (only 1$ per month!)
|
||||
* https://plantuml.com/paypal
|
||||
*
|
||||
* This file is part of PlantUML.
|
||||
*
|
||||
* PlantUML is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* PlantUML distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||
* USA.
|
||||
*
|
||||
*
|
||||
* Original Author: Arnaud Roques
|
||||
* Contribution: The-Lum
|
||||
*
|
||||
*/
|
||||
package net.sourceforge.plantuml.tim.stdlib;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.plantuml.json.Json;
|
||||
import net.sourceforge.plantuml.json.JsonArray;
|
||||
import net.sourceforge.plantuml.json.JsonObject;
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.text.StringLocated;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TContext;
|
||||
import net.sourceforge.plantuml.tim.TFunctionSignature;
|
||||
import net.sourceforge.plantuml.tim.TMemory;
|
||||
import net.sourceforge.plantuml.tim.expression.TValue;
|
||||
|
||||
public class Str2Json extends SimpleReturnFunction {
|
||||
|
||||
public TFunctionSignature getSignature() {
|
||||
return new TFunctionSignature("%str2json", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCover(int nbArg, Set<String> namedArgument) {
|
||||
return nbArg == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TValue executeReturnFunction(TContext context, TMemory memory, StringLocated location, List<TValue> values,
|
||||
Map<String, TValue> named) throws EaterException {
|
||||
try {
|
||||
final String value = values.get(0).toString();
|
||||
final JsonValue json = Json.parse(value);
|
||||
return TValue.fromJson(json);
|
||||
} catch (Throwable t) {
|
||||
return TValue.fromString("");
|
||||
}
|
||||
}
|
||||
}
|
@ -16,28 +16,21 @@ public class TimTestUtils {
|
||||
|
||||
// Tfunc: () -> (String)
|
||||
public static void assertTimExpectedOutput(TFunction func, String expected) throws EaterException {
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, Collections.emptyList(), null);
|
||||
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 {
|
||||
final List<TValue> values = Collections.singletonList(TValue.fromInt(input));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
// Tfunc: (Integer, Integer) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, Integer input1, Integer input2, String expected) throws EaterException {
|
||||
final List<TValue> values = Arrays.asList(TValue.fromInt(input1), TValue.fromInt(input2));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
List<TValue> 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 {
|
||||
final List<TValue> values = Collections.singletonList(TValue.fromString(input));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
List<TValue> values = Collections.singletonList(TValue.fromString(input));
|
||||
TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
@ -50,36 +43,8 @@ public class TimTestUtils {
|
||||
|
||||
// Tfunc: (JsonValue) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input, String expected) throws EaterException {
|
||||
final List<TValue> values = Collections.singletonList(TValue.fromJson(input));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
// Tfunc: (JsonValue, JsonValue) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input1, JsonValue input2, String expected) throws EaterException {
|
||||
final List<TValue> values = Arrays.asList(TValue.fromJson(input1), TValue.fromJson(input2));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
// Tfunc: (JsonValue, Int) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input1, Integer input2, String expected) throws EaterException {
|
||||
final List<TValue> values = Arrays.asList(TValue.fromJson(input1), TValue.fromInt(input2));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
// Tfunc: (JsonValue, String) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input1, String input2, String expected) throws EaterException {
|
||||
final List<TValue> values = Arrays.asList(TValue.fromJson(input1), TValue.fromString(input2));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
// Tfunc: (JsonValue, String, JsonValue) -> (String)
|
||||
public static void assertTimExpectedOutputFromInput(TFunction func, JsonValue input1, String input2, JsonValue input3, String expected) throws EaterException {
|
||||
final List<TValue> values = Arrays.asList(TValue.fromJson(input1), TValue.fromString(input2), TValue.fromJson(input3));
|
||||
final TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
List<TValue> values = Collections.singletonList(TValue.fromJson(input));
|
||||
TValue tValue = func.executeReturnFunction(null, null, null, values, null);
|
||||
assertEquals(expected, tValue.toString());
|
||||
}
|
||||
|
||||
|
@ -1,117 +0,0 @@
|
||||
package net.sourceforge.plantuml.tim.stdlib;
|
||||
|
||||
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.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.converter.ConvertWith;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TFunction;
|
||||
import test.utils.JunitUtils.StringJsonConverter;
|
||||
|
||||
/**
|
||||
* Tests the builtin function.
|
||||
*/
|
||||
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
|
||||
|
||||
class JsonAddTest {
|
||||
TFunction cut = new JsonAdd();
|
||||
final String cutName = "json_add";
|
||||
final String paramTestName = "[{index}] " + cutName + "({0}, {1}) = {2}";
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" [], 1, [1]",
|
||||
" [0], \"a\", '[0,\"a\"]' ",
|
||||
" [0], {\"a\": 123}, '[0,{\"a\":123}]' ",
|
||||
" [0], [1], '[0,[1]]' ",
|
||||
" '[{\"a\":[1, 2]}]', 1, '[{\"a\":[1,2]},1]' ",
|
||||
|
||||
})
|
||||
void Test_with_Array_Json(@ConvertWith(StringJsonConverter.class) JsonValue input1, @ConvertWith(StringJsonConverter.class) JsonValue input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "[{index}] " + cutName + "({0}, {1}, {2}) = {3}")
|
||||
@CsvSource(value = {
|
||||
" {}, a, 1, {\"a\":1}",
|
||||
" {}, a, '[1,2,3]', '{\"a\":[1,2,3]}'",
|
||||
" {}, a, '{\"b\":123}', '{\"a\":{\"b\":123}}'",
|
||||
" {}, a, '{\"b\":\"abc\"}', '{\"a\":{\"b\":\"abc\"}}'",
|
||||
" {\"z\":0}, a, 1, '{\"z\":0,\"a\":1}'",
|
||||
" {\"z\":0}, a, '[1,2,3]', '{\"z\":0,\"a\":[1,2,3]}'",
|
||||
" {\"z\":0}, a, '{\"b\":123}', '{\"z\":0,\"a\":{\"b\":123}}'",
|
||||
" {\"z\":0}, a, '{\"b\":\"abc\"}', '{\"z\":0,\"a\":{\"b\":\"abc\"}}'",
|
||||
" '{\"a\": 1, \"b\": \"two\"}', c, 3, '{\"a\":1,\"b\":\"two\",\"c\":3}'",
|
||||
" '{\"a\": 1, \"b\": \"two\"}', d, '{\"da\": 1, \"db\": \"two\"}', '{\"a\":1,\"b\":\"two\",\"d\":{\"da\":1,\"db\":\"two\"}}'",
|
||||
|
||||
})
|
||||
void Test_with_Object_Json(@ConvertWith(StringJsonConverter.class) JsonValue input1, String input2, @ConvertWith(StringJsonConverter.class) JsonValue input3, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, input3, expected);
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Not_Nominal_Test {
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" 0, 1, 0",
|
||||
" 1, 1, 1",
|
||||
" true, 1, true",
|
||||
" false, 1, false",
|
||||
" \"a\", 1, a",
|
||||
" null, 1, null",
|
||||
" 0, \"b\", 0",
|
||||
" 1, \"b\", 1",
|
||||
" true, \"b\", true",
|
||||
" false, \"b\", false",
|
||||
" \"a\", \"b\", a",
|
||||
" null, \"b\", null",
|
||||
" 0, true, 0",
|
||||
" 1, true, 1",
|
||||
" true, true, true",
|
||||
" false, true, false",
|
||||
" \"a\", true, a",
|
||||
" null, true, null",
|
||||
})
|
||||
void Test_with_Simple(@ConvertWith(StringJsonConverter.class) JsonValue input1, @ConvertWith(StringJsonConverter.class) JsonValue input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" 0, 1, 0",
|
||||
" 1, 1, 1",
|
||||
" true, 1, true",
|
||||
" false, 1, false",
|
||||
" \"a\", 1, a",
|
||||
" null, 1, null",
|
||||
})
|
||||
void Test_with_Simple(@ConvertWith(StringJsonConverter.class) JsonValue input1, Integer input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" 0, 1, 0",
|
||||
" 1, 1, 1",
|
||||
" true, 1, true",
|
||||
" false, 1, false",
|
||||
" \"a\", 1, a",
|
||||
" null, 1, null",
|
||||
" 0, b, 0",
|
||||
" 1, b, 1",
|
||||
" true, b, true",
|
||||
" false, b, false",
|
||||
" \"a\", b, a",
|
||||
" null, b, null",
|
||||
})
|
||||
void Test_with_Simple(@ConvertWith(StringJsonConverter.class) JsonValue input1, String input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
package net.sourceforge.plantuml.tim.stdlib;
|
||||
|
||||
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.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.converter.ConvertWith;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TFunction;
|
||||
import test.utils.JunitUtils.StringJsonConverter;
|
||||
|
||||
/**
|
||||
* Tests the builtin function.
|
||||
*/
|
||||
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
|
||||
|
||||
class JsonRemoveTest {
|
||||
TFunction cut = new JsonRemove();
|
||||
final String cutName = "json_remove";
|
||||
final String paramTestName = "[{index}] " + cutName + "({0}, {1}) = {2}";
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" [], -1, []",
|
||||
" [], 1, []",
|
||||
" [0], 0, [] ",
|
||||
" [0], 1, [0] ",
|
||||
" '[1,2,3]', -1, '[1,2,3]' ", // To debate...
|
||||
" '[1,2,3]', 0, '[2,3]' ",
|
||||
" '[1,2,3]', 1, '[1,3]' ",
|
||||
" '[1,2,3]', 2, '[1,2]' ",
|
||||
" '[1,2,3]', 3, '[1,2,3]' ",
|
||||
" '[{\"a\":[1, 2]}, 1, \"a\"]', 2, '[{\"a\":[1,2]},1]' ",
|
||||
})
|
||||
void Test_with_Array_Json(@ConvertWith(StringJsonConverter.class) JsonValue input1, Integer input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" '{\"z\":0,\"a\":1}', a, '{\"z\":0}'",
|
||||
" '{\"z\":0,\"a\":1}', b, '{\"z\":0,\"a\":1}'",
|
||||
" '{\"a\": 1, \"b\": \"two\",\"c\":3}', c, '{\"a\":1,\"b\":\"two\"}'",
|
||||
" '{\"a\":1,\"b\":\"two\",\"d\":{\"da\":1,\"db\":\"two\"}}', d, '{\"a\":1,\"b\":\"two\"}'",
|
||||
|
||||
})
|
||||
void Test_with_Object_Json(@ConvertWith(StringJsonConverter.class) JsonValue input1, String input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
|
||||
@Nested
|
||||
class Not_Nominal_Test {
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" [], a, []",
|
||||
" '[1,2,3]', abc, '[1,2,3]' ",
|
||||
" '[1,2,3]', 1, '[1,2,3]' ",
|
||||
" 123, 1, 123",
|
||||
" true, a, true",
|
||||
" true, 1, true",
|
||||
" \"abc\", a, abc",
|
||||
" \"a b c\", a, a b c",
|
||||
" \"a b c\", 1, a b c",
|
||||
})
|
||||
void Test_with_not_good_type(@ConvertWith(StringJsonConverter.class) JsonValue input1, String input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" '{\"z\":0,\"a\":1}', 5, '{\"z\":0,\"a\":1}'",
|
||||
" '{\"z\":0,\"5\":1}', 5, '{\"z\":0}'", // Allow cast int -> string
|
||||
" '{\"a\": 1, \"b\": \"two\",\"c\":3}', 10, '{\"a\":1,\"b\":\"two\",\"c\":3}'",
|
||||
})
|
||||
void Test_with_not_good_type(@ConvertWith(StringJsonConverter.class) JsonValue input1, Integer input2, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input1, input2, expected);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
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.ParameterizedTest;
|
||||
import org.junit.jupiter.params.converter.ConvertWith;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import net.sourceforge.plantuml.json.JsonValue;
|
||||
import net.sourceforge.plantuml.tim.EaterException;
|
||||
import net.sourceforge.plantuml.tim.TFunction;
|
||||
|
||||
import test.utils.JunitUtils.StringJsonConverter;
|
||||
|
||||
/**
|
||||
* Tests the builtin function.
|
||||
*/
|
||||
@IndicativeSentencesGeneration(separator = ": ", generator = ReplaceUnderscores.class)
|
||||
|
||||
class Str2JsonTest {
|
||||
TFunction cut = new Str2Json();
|
||||
final String cutName = "str2json";
|
||||
final String paramTestName = "[{index}] " + cutName + "({0}) = {1}";
|
||||
|
||||
@Test
|
||||
void Test_without_Param() throws EaterException {
|
||||
assertTimExpectedOutput(cut, "");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(nullValues = "null", value = {
|
||||
" 0, 0",
|
||||
" -1, -1",
|
||||
" 12, 12",
|
||||
})
|
||||
void Test_with_Integer(Integer input, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input, expected);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" 0, 0 ",
|
||||
" 1, 1 ",
|
||||
" 12, 12 ",
|
||||
" -1, -1 ",
|
||||
" true, true ",
|
||||
" [true], [true] ",
|
||||
" null, null ",
|
||||
" '', '' ",
|
||||
" \"\", '' ",
|
||||
" a, '' ",
|
||||
" \"a\", a ",
|
||||
" '\"a\"', a ",
|
||||
" \"a b\", a b ",
|
||||
" 'a b', '' ",
|
||||
" [], [] ",
|
||||
" '[1, 2]', '[1,2]' ",
|
||||
" '[\"a\"]', '[\"a\"]' ",
|
||||
" '{\"a\":[1, 2]}', '{\"a\":[1,2]}' ",
|
||||
" '[{\"a\":[1, 2]}]' , '[{\"a\":[1,2]}]' ",
|
||||
" '{\"a\":\"abc\"}', {\"a\":\"abc\"} ",
|
||||
" '[{\"a\":[1, 2]}, {\"b\":[3, 4]}]', '[{\"a\":[1,2]},{\"b\":[3,4]}]'",
|
||||
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}', '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}'",
|
||||
" '[3, \"different\", { \"types\" : \"of values\" }]', '[3,\"different\",{\"types\":\"of values\"}]'",
|
||||
" '{\"a\": 1, \"b\": \"two\"}', '{\"a\":1,\"b\":\"two\"}' ",
|
||||
})
|
||||
void Test_with_String(String input, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input, expected);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = paramTestName)
|
||||
@CsvSource(value = {
|
||||
" 0, 0 ",
|
||||
" 1, 1 ",
|
||||
" 12, 12 ",
|
||||
" -1, -1 ",
|
||||
" true, true ",
|
||||
" [true], [true] ",
|
||||
" null, null ",
|
||||
//" '', '' ",
|
||||
//" \"\", '' ",
|
||||
//" a, '' ",
|
||||
//" \"a\", a ",
|
||||
//" '\"a\"', a ",
|
||||
//" \"a b\", a b ",
|
||||
//" 'a b', a b ",
|
||||
" [], [] ",
|
||||
" '[1, 2]', '[1,2]' ",
|
||||
" '[\"a\"]', '[\"a\"]' ",
|
||||
" '{\"a\":[1, 2]}', '{\"a\":[1,2]}' ",
|
||||
" '[{\"a\":[1, 2]}]' , '[{\"a\":[1,2]}]' ",
|
||||
" '{\"a\":\"abc\"}', {\"a\":\"abc\"} ",
|
||||
" '[{\"a\":[1, 2]}, {\"b\":[3, 4]}]', '[{\"a\":[1,2]},{\"b\":[3,4]}]'",
|
||||
" '{\"a\":[1, 2], \"b\":\"abc\", \"b\":true}', '{\"a\":[1,2],\"b\":\"abc\",\"b\":true}'",
|
||||
" '[3, \"different\", { \"types\" : \"of values\" }]', '[3,\"different\",{\"types\":\"of values\"}]'",
|
||||
" '{\"a\": 1, \"b\": \"two\"}', '{\"a\":1,\"b\":\"two\"}' ",
|
||||
})
|
||||
void Test_with_Json(@ConvertWith(StringJsonConverter.class) JsonValue input, String expected) throws EaterException {
|
||||
assertTimExpectedOutputFromInput(cut, input, expected);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package nonreg.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import nonreg.BasicTest;
|
||||
|
||||
/*
|
||||
|
||||
Test diagram MUST be put between triple quotes
|
||||
|
||||
"""
|
||||
@startchen
|
||||
left to right direction
|
||||
|
||||
entity Person {
|
||||
}
|
||||
entity Location {
|
||||
}
|
||||
relationship Birthplace {
|
||||
}
|
||||
|
||||
Person -N- Birthplace
|
||||
Birthplace -1- Location
|
||||
|
||||
@endchen
|
||||
"""
|
||||
|
||||
*/
|
||||
public class ChenRankDir_Test extends BasicTest {
|
||||
|
||||
@Test
|
||||
void testSimple() throws IOException {
|
||||
checkImage("(3 entities)");
|
||||
}
|
||||
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
package nonreg.simple;
|
||||
|
||||
public class ChenRankDir_TestResult {
|
||||
}
|
||||
/*
|
||||
"""
|
||||
DPI: 96
|
||||
dimension: [ 644.3264 ; 111.8193 ]
|
||||
scaleFactor: 1.0000
|
||||
seed: -4308824771398432496
|
||||
svgLinkTarget: _top
|
||||
hoverPathColorRGB: null
|
||||
preserveAspectRatio: none
|
||||
|
||||
RECTANGLE:
|
||||
pt1: [ 6.0000 ; 42.0000 ]
|
||||
pt2: [ 119.9805 ; 76.0000 ]
|
||||
xCorner: 0
|
||||
yCorner: 0
|
||||
stroke: 0.0-0.0-0.5
|
||||
shadow: 0
|
||||
color: ff181818
|
||||
backcolor: fff1f1f1
|
||||
|
||||
TEXT:
|
||||
text: Person
|
||||
position: [ 16.0000 ; 62.8889 ]
|
||||
orientation: 0
|
||||
font: SansSerif.plain/14 []
|
||||
color: ff000000
|
||||
extendedColor: NULL_COLOR
|
||||
|
||||
RECTANGLE:
|
||||
pt1: [ 480.0000 ; 42.0000 ]
|
||||
pt2: [ 639.3264 ; 76.0000 ]
|
||||
xCorner: 0
|
||||
yCorner: 0
|
||||
stroke: 0.0-0.0-0.5
|
||||
shadow: 0
|
||||
color: ff181818
|
||||
backcolor: fff1f1f1
|
||||
|
||||
TEXT:
|
||||
text: Location
|
||||
position: [ 490.0000 ; 62.8889 ]
|
||||
orientation: 0
|
||||
font: SansSerif.plain/14 []
|
||||
color: ff000000
|
||||
extendedColor: NULL_COLOR
|
||||
|
||||
POLYGON:
|
||||
points:
|
||||
- [ 206.0000 ; 58.9096 ]
|
||||
- [ 299.8193 ; 12.0000 ]
|
||||
- [ 393.6386 ; 58.9096 ]
|
||||
- [ 299.8193 ; 105.8193 ]
|
||||
stroke: 0.0-0.0-0.5
|
||||
shadow: 0
|
||||
color: ff181818
|
||||
backcolor: fff1f1f1
|
||||
|
||||
TEXT:
|
||||
text: Birthplace
|
||||
position: [ 231.1803 ; 62.7985 ]
|
||||
orientation: 0
|
||||
font: SansSerif.plain/14 []
|
||||
color: ff000000
|
||||
extendedColor: NULL_COLOR
|
||||
|
||||
PATH:
|
||||
- type: SEG_MOVETO
|
||||
pt1: [ 114.2884 ; 53.0000 ]
|
||||
- type: SEG_CUBICTO
|
||||
pt1: [ 139.8162 ; 53.0000 ]
|
||||
pt2: [ 170.6921 ; 53.0000 ]
|
||||
pt3: [ 199.5468 ; 53.0000 ]
|
||||
stroke: 0.0-0.0-1.0
|
||||
shadow: 0
|
||||
color: ff181818
|
||||
backcolor: NULL_COLOR
|
||||
|
||||
EMPTY:
|
||||
pt1: [ 157.0000 ; 46.0000 ]
|
||||
pt2: [ 169.5088 ; 59.0000 ]
|
||||
|
||||
TEXT:
|
||||
text: N
|
||||
position: [ 158.0000 ; 55.5556 ]
|
||||
orientation: 0
|
||||
font: SansSerif.plain/11 []
|
||||
color: ff000000
|
||||
extendedColor: NULL_COLOR
|
||||
|
||||
PATH:
|
||||
- type: SEG_MOVETO
|
||||
pt1: [ 388.3275 ; 53.0000 ]
|
||||
- type: SEG_CUBICTO
|
||||
pt1: [ 416.3938 ; 53.0000 ]
|
||||
pt2: [ 446.8953 ; 53.0000 ]
|
||||
pt3: [ 473.9060 ; 53.0000 ]
|
||||
stroke: 0.0-0.0-1.0
|
||||
shadow: 0
|
||||
color: ff181818
|
||||
backcolor: NULL_COLOR
|
||||
|
||||
EMPTY:
|
||||
pt1: [ 431.0000 ; 46.0000 ]
|
||||
pt2: [ 443.3969 ; 59.0000 ]
|
||||
|
||||
TEXT:
|
||||
text: 1
|
||||
position: [ 432.0000 ; 55.5556 ]
|
||||
orientation: 0
|
||||
font: SansSerif.plain/11 []
|
||||
color: ff000000
|
||||
extendedColor: NULL_COLOR
|
||||
|
||||
"""
|
||||
*/
|
Loading…
Reference in New Issue
Block a user