From 770abc054ade0ae600791f545a59ad05de1547a1 Mon Sep 17 00:00:00 2001
From: Paul H
Date: Tue, 24 Jun 2025 23:02:54 +0200
Subject: [PATCH] Updated tests
---
.../de/pabulaner/jcmd/core/ParserTest.java | 25 +++++++++++++------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/test/java/de/pabulaner/jcmd/core/ParserTest.java b/src/test/java/de/pabulaner/jcmd/core/ParserTest.java
index f2d4268..889b2bc 100644
--- a/src/test/java/de/pabulaner/jcmd/core/ParserTest.java
+++ b/src/test/java/de/pabulaner/jcmd/core/ParserTest.java
@@ -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 expectedFlags, List expectedArgs) {