Skip to content

Commit 6c49e8c

Browse files
testing "accepting null from the arguments list"
1 parent 750dde5 commit 6c49e8c

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

commands/src/test/java/com/wizardlybump17/wlib/test/command/CommandTests.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import com.wizardlybump17.wlib.command.exception.InputParsingException;
66
import com.wizardlybump17.wlib.command.executor.CommandNodeExecutor;
77
import com.wizardlybump17.wlib.command.input.primitive.number.AllowedIntegerInputs;
8+
import com.wizardlybump17.wlib.command.input.string.AllowedStringInputs;
89
import com.wizardlybump17.wlib.command.node.CommandNode;
910
import com.wizardlybump17.wlib.command.node.LiteralCommandNode;
1011
import com.wizardlybump17.wlib.command.node.primitive.number.IntegerCommandNode;
12+
import com.wizardlybump17.wlib.command.node.string.StringCommandNode;
1113
import com.wizardlybump17.wlib.command.result.CommandResult;
1214
import com.wizardlybump17.wlib.command.result.error.*;
1315
import com.wizardlybump17.wlib.command.sender.BasicCommandSender;
1416
import com.wizardlybump17.wlib.command.sender.CommandSender;
17+
import com.wizardlybump17.wlib.util.CollectionUtil;
1518
import org.jetbrains.annotations.NotNull;
1619
import org.junit.jupiter.api.Assertions;
1720
import org.junit.jupiter.api.DisplayName;
@@ -481,4 +484,64 @@ void testCommandArguments() {
481484
Assertions.assertEquals(CommandResult.successful(2, test, "Hello 10 world"), result);
482485
}
483486
}
487+
488+
@Test
489+
void testNullArgumentsSuccess() {
490+
Command command = new Command(
491+
new LiteralCommandNode(
492+
"test",
493+
List.of(
494+
new StringCommandNode(
495+
"nullable0",
496+
List.of(),
497+
AllowedStringInputs.anyNullable(),
498+
null,
499+
context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)),
500+
null
501+
)
502+
),
503+
null,
504+
null
505+
)
506+
);
507+
508+
Assertions.assertEquals(
509+
CommandResult.successful(1, command.findNode("nullable0"), "Hello World"),
510+
command.execute(CHAD_SENDER, List.of("test", "Hello World"))
511+
);
512+
Assertions.assertEquals(
513+
CommandResult.successful(1, command.findNode("nullable0"), null),
514+
command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null))
515+
);
516+
}
517+
518+
@Test
519+
void testNullArgumentsError() {
520+
Command command = new Command(
521+
new LiteralCommandNode(
522+
"test",
523+
List.of(
524+
new StringCommandNode(
525+
"nullable0",
526+
List.of(),
527+
AllowedStringInputs.anyNotNull(),
528+
null,
529+
context -> CommandResult.successful(context, context.arguments().getArgumentData("nullable0").orElse(null)),
530+
null
531+
)
532+
),
533+
null,
534+
null
535+
)
536+
);
537+
538+
Assertions.assertEquals(
539+
CommandResult.successful(1, command.findNode("nullable0"), "Hello World"),
540+
command.execute(CHAD_SENDER, List.of("test", "Hello World"))
541+
);
542+
Assertions.assertEquals(
543+
CommandResult.outOfRangeInput(1, command.findNode("nullable0")),
544+
command.execute(CHAD_SENDER, CollectionUtil.listOf("test", null))
545+
);
546+
}
484547
}

0 commit comments

Comments
 (0)