diff --git a/opengrok-indexer/src/test/java/org/opengrok/indexer/util/GetoptTest.java b/opengrok-indexer/src/test/java/org/opengrok/indexer/util/GetoptTest.java index 250269478d3..159eeedcc70 100644 --- a/opengrok-indexer/src/test/java/org/opengrok/indexer/util/GetoptTest.java +++ b/opengrok-indexer/src/test/java/org/opengrok/indexer/util/GetoptTest.java @@ -22,32 +22,62 @@ */ package org.opengrok.indexer.util; -import org.junit.jupiter.api.Test; - import java.text.ParseException; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; class GetoptTest { - @Test - void testParseNormal() throws Exception { - String[] argv = new String[] {"-a", "foo", "-bc", "--", "-f"}; + @Test + void testParseOptionA() throws Exception { + String[] argv = new String[]{"-a", "foo", "-bc", "--", "-f"}; Getopt instance = new Getopt(argv, "a:bcr:f"); - instance.parse(); assertEquals('a', (char) instance.getOpt()); assertEquals("foo", instance.getOptarg()); + } + + @Test + void testParseOptionB() throws Exception { + String[] argv = new String[]{"-a", "foo", "-bc", "--", "-f"}; + Getopt instance = new Getopt(argv, "a:bcr:f"); + instance.parse(); + assertEquals('b', (char) instance.getOpt()); assertNull(instance.getOptarg()); + } + + @Test + void testParseOptionC() throws Exception { + String[] argv = new String[]{"-a", "foo", "-bc", "--", "-f"}; + Getopt instance = new Getopt(argv, "a:bcr:f"); + instance.parse(); + assertEquals('c', (char) instance.getOpt()); assertNull(instance.getOptarg()); + } + + @Test + void testParseEndOfOptions() throws Exception { + String[] argv = new String[]{"-a", "foo", "-bc", "--", "-f"}; + Getopt instance = new Getopt(argv, "a:bcr:f"); + instance.parse(); + assertEquals(-1, instance.getOpt()); assertEquals(4, instance.getOptind()); + } + + @Test + void testGetNextArgument() throws Exception { + String[] argv = new String[]{"-a", "foo", "-bc", "--", "-f"}; + Getopt instance = new Getopt(argv, "a:bcr:f"); + instance.parse(); + assertTrue(instance.getOptind() < argv.length); assertEquals("-f", argv[instance.getOptind()]); }