Updated tests

This commit is contained in:
Paul H 2025-06-24 23:02:54 +02:00
parent 95ceff1506
commit 770abc054a

View File

@ -12,14 +12,25 @@ class ParserTest {
public void testParser() {
Parser parser = null; // <-- Your implementation goes here
// test invalid strings -> should return null
assertNull(parser.parse(""));
assertNull(parser.parse("-"));
assertNull(parser.parse("ls -"));
assertNull(parser.parse("ls --"));
// test valid string
testInput(parser, "ls", "ls", List.of(), List.of());
testInput(parser, "ls -la", "ls", List.of("l", "a"), List.of());
testInput(parser, "ls ./hello/world", "ls", List.of(), List.of("./hello/world"));
testInput(parser, "ls -la ./what", "ls", List.of("l", "a"), List.of("./what"));
testInput(parser, "rm -r /bin /opt", "rm", List.of("r"), List.of("/bin", "/opt"));
testInput(parser, "cd .", "cd", List.of(), List.of("."));
testInput(parser, "mkdir .", "mkdir", List.of(), List.of("."));
testInput(parser, "super -abc -de -f super nice danke paul", "super", List.of("a", "b", "c", "d", "e", "f"), List.of("super", "nice", "danke", "paul"));
testInput(parser, " ls -la", "ls", List.of("l", "a"), List.of());
testInput(parser, "ls ./hello/world ", "ls", List.of(), List.of("./hello/world"));
testInput(parser, "ls -la ./what", "ls", List.of("l", "a"), List.of("./what"));
testInput(parser, "rm -r /bin /opt", "rm", List.of("r"), List.of("/bin", "/opt"));
testInput(parser, " cd . ", "cd", List.of(), List.of("."));
testInput(parser, " mkdir . ", "mkdir", List.of(), List.of("."));
testInput(parser, "super -abc -de -f super nice danke paul", "super", List.of("a", "b", "c", "d", "e", "f"), List.of("super", "nice", "danke", "paul"));
// new tests
testInput(parser, "print hello-world", "print", List.of(), List.of("hello-world"));
}
private void testInput(Parser parser, String input, String expectedCommand, List<String> expectedFlags, List<String> expectedArgs) {