Add Quotable strings

Dieser Commit ist enthalten in:
yoyosource 2022-12-18 13:55:11 +01:00
Ursprung d38ddb54c7
Commit 2ae13e3642
3 geänderte Dateien mit 21 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -103,10 +103,12 @@ public class SWCommandUtils {
Class<?> varArgType = parameter.isVarArgs() ? parameter.getType().getComponentType() : null; Class<?> varArgType = parameter.isVarArgs() ? parameter.getType().getComponentType() : null;
AbstractSWCommand.OptionalValue optionalValue = parameter.getAnnotation(AbstractSWCommand.OptionalValue.class); AbstractSWCommand.OptionalValue optionalValue = parameter.getAnnotation(AbstractSWCommand.OptionalValue.class);
AbstractSWCommand.AllowNull allowNull = parameter.getAnnotation(AbstractSWCommand.AllowNull.class); AbstractSWCommand.AllowNull allowNull = parameter.getAnnotation(AbstractSWCommand.AllowNull.class);
AbstractSWCommand.Quotable quotable = parameter.getAnnotation(AbstractSWCommand.Quotable.class);
CommandPart<T> commandPart = new CommandPart<>(command, typeMapper, validator, varArgType, optionalValue != null ? optionalValue.value() : null, parameter, i); CommandPart<T> commandPart = new CommandPart<>(command, typeMapper, validator, varArgType, optionalValue != null ? optionalValue.value() : null, parameter, i);
commandPart.setOnlyUseIfNoneIsGiven(optionalValue != null && optionalValue.onlyUINIG()); commandPart.setOnlyUseIfNoneIsGiven(optionalValue != null && optionalValue.onlyUINIG());
commandPart.setAllowNullValues(allowNull != null); commandPart.setAllowNullValues(allowNull != null);
commandPart.setQuotable(quotable != null);
if (current != null) { if (current != null) {
current.setNext(commandPart); current.setNext(commandPart);
} }

Datei anzeigen

@ -54,7 +54,7 @@ public class ArgumentCommand extends TestSWCommand {
} }
@Register @Register
public void argument(String sender, String arg) { public void argument(String sender, @Quotable String arg) {
throw new ExecutionIdentifier("RunArgument with String"); throw new ExecutionIdentifier("RunArgument with String");
} }
} }

Datei anzeigen

@ -44,6 +44,7 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"true", "false"}); cmd.execute("test", "", new String[]{"true", "false"});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Boolean"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Boolean");
} }
@ -54,6 +55,7 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0"}); cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0"});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Float"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Float");
} }
@ -64,6 +66,7 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0", "0.0"}); cmd.execute("test", "", new String[]{"0.0", "0.0", "0.0", "0.0"});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Double"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Double");
} }
@ -74,6 +77,7 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"0"}); cmd.execute("test", "", new String[]{"0"});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Integer"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Integer");
} }
@ -84,6 +88,7 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"0", "0"}); cmd.execute("test", "", new String[]{"0", "0"});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Long"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with Long");
} }
@ -94,11 +99,22 @@ public class ArgumentCommandTest {
ArgumentCommand cmd = new ArgumentCommand(); ArgumentCommand cmd = new ArgumentCommand();
try { try {
cmd.execute("test", "", new String[]{"Hello World"}); cmd.execute("test", "", new String[]{"Hello World"});
assert false;
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with String");
}
try {
cmd.execute("test", "", new String[]{"\"Hello World\""});
assert false;
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with String");
}
try {
cmd.execute("test", "", new String[]{"\"Hello", "World\""});
assert false;
} catch (Exception e) { } catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with String"); assertCMDFramework(e, ExecutionIdentifier.class, "RunArgument with String");
} }
cmd.execute("test", "", new String[]{"\"Hello World\""});
cmd.execute("test", "", new String[]{"\"Hello", "World\""});
} }
@Test @Test