Fix command sorting with varargs
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2023-02-02 18:07:29 +01:00
Ursprung 65df8ddab0
Commit 45e9698634
4 geänderte Dateien mit 29 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -140,7 +140,6 @@ public abstract class AbstractSWCommand<T> {
}
Collections.sort(commandList);
System.out.println(commandList.stream().map(o -> o.method).collect(Collectors.toList()));
initialized = true;
}

Datei anzeigen

@ -82,6 +82,8 @@ public class SubCommand<T> implements Comparable<SubCommand<T>> {
if (tVarArgs) tLength *= -1;
if (oVarArgs) oLength *= -1;
if (tVarArgs && oVarArgs) return Integer.compare(tLength, oLength);
return -Integer.compare(tLength, oLength);
}

Datei anzeigen

@ -38,6 +38,11 @@ public class SubCMDSortingCommand extends TestSWCommand {
throw new ExecutionIdentifier("Command with 1 parameter");
}
@Register
public void test(String s, String i1, String i2, String i3, String... args) {
throw new ExecutionIdentifier("Command with 3+n parameters");
}
@Register
public void test(String s, String... args) {
throw new ExecutionIdentifier("Command with n parameters");

Datei anzeigen

@ -58,4 +58,26 @@ public class SubCMDSortingCommandTest {
assertCMDFramework(e, ExecutionIdentifier.class, "Command with n parameters");
}
}
@Test
public void testThreeArgsVarArg() {
SubCMDSortingCommand cmd = new SubCMDSortingCommand();
try {
cmd.execute("", "", new String[]{"Hello", "World", "YoyoNow", "Hugo"});
assert false;
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 3+n parameters");
}
}
@Test
public void testThreeArgsVarArg2() {
SubCMDSortingCommand cmd = new SubCMDSortingCommand();
try {
cmd.execute("", "", new String[]{"Hello", "World", "YoyoNow"});
assert false;
} catch (Exception e) {
assertCMDFramework(e, ExecutionIdentifier.class, "Command with 3+n parameters");
}
}
}