Skip to content

Commit 8dd32f5

Browse files
committed
[#9][#1021] added tests
1 parent 9662c3b commit 8dd32f5

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

src/test/java/picocli/SubcommandTests.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,102 @@ class TopLevel {}
14461446
assertTrue(grandChildCount > 0);
14471447
}
14481448

1449+
@Test
1450+
public void testSubcommandsCaseInsensitive_BeforeSubcommandsAdded() {
1451+
@Command
1452+
class TopLevel {}
1453+
CommandLine commandLine = new CommandLine(new TopLevel());
1454+
assertEquals(false, commandLine.isSubcommandsCaseInsensitive());
1455+
commandLine.setSubcommandsCaseInsensitive(true);
1456+
assertEquals(true, commandLine.isSubcommandsCaseInsensitive());
1457+
1458+
int childCount = 0;
1459+
int grandChildCount = 0;
1460+
commandLine.addSubcommand("main", createNestedCommand());
1461+
for (CommandLine sub : commandLine.getSubcommands().values()) {
1462+
childCount++;
1463+
assertEquals("subcommand added afterwards is not impacted", false, sub.isSubcommandsCaseInsensitive());
1464+
for (CommandLine subsub : sub.getSubcommands().values()) {
1465+
grandChildCount++;
1466+
assertEquals("subcommand added afterwards is not impacted", false, subsub.isSubcommandsCaseInsensitive());
1467+
}
1468+
}
1469+
assertTrue(childCount > 0);
1470+
assertTrue(grandChildCount > 0);
1471+
}
1472+
1473+
@Test
1474+
public void testSubcommandsCaseInsensitive_AfterSubcommandsAdded() {
1475+
@Command
1476+
class TopLevel {}
1477+
CommandLine commandLine = new CommandLine(new TopLevel());
1478+
commandLine.addSubcommand("main", createNestedCommand());
1479+
assertEquals(false, commandLine.isSubcommandsCaseInsensitive());
1480+
commandLine.setSubcommandsCaseInsensitive(true);
1481+
assertEquals(true, commandLine.isSubcommandsCaseInsensitive());
1482+
1483+
int childCount = 0;
1484+
int grandChildCount = 0;
1485+
for (CommandLine sub : commandLine.getSubcommands().values()) {
1486+
childCount++;
1487+
assertEquals("subcommand added before IS impacted", true, sub.isSubcommandsCaseInsensitive());
1488+
for (CommandLine subsub : sub.getSubcommands().values()) {
1489+
grandChildCount++;
1490+
assertEquals("subsubcommand added before IS impacted", true, sub.isSubcommandsCaseInsensitive());
1491+
}
1492+
}
1493+
assertTrue(childCount > 0);
1494+
assertTrue(grandChildCount > 0);
1495+
}
1496+
1497+
@Test
1498+
public void testOptionsCaseInsensitive_BeforeSubcommandsAdded() {
1499+
@Command
1500+
class TopLevel {}
1501+
CommandLine commandLine = new CommandLine(new TopLevel());
1502+
assertEquals(false, commandLine.isOptionsCaseInsensitive());
1503+
commandLine.setOptionsCaseInsensitive(true);
1504+
assertEquals(true, commandLine.isOptionsCaseInsensitive());
1505+
1506+
int childCount = 0;
1507+
int grandChildCount = 0;
1508+
commandLine.addSubcommand("main", createNestedCommand());
1509+
for (CommandLine sub : commandLine.getSubcommands().values()) {
1510+
childCount++;
1511+
assertEquals("subcommand added afterwards is not impacted", false, sub.isOptionsCaseInsensitive());
1512+
for (CommandLine subsub : sub.getSubcommands().values()) {
1513+
grandChildCount++;
1514+
assertEquals("subcommand added afterwards is not impacted", false, subsub.isOptionsCaseInsensitive());
1515+
}
1516+
}
1517+
assertTrue(childCount > 0);
1518+
assertTrue(grandChildCount > 0);
1519+
}
1520+
1521+
@Test
1522+
public void testOptionsCaseInsensitive_AfterSubcommandsAdded() {
1523+
@Command
1524+
class TopLevel {}
1525+
CommandLine commandLine = new CommandLine(new TopLevel());
1526+
commandLine.addSubcommand("main", createNestedCommand());
1527+
assertEquals(false, commandLine.isOptionsCaseInsensitive());
1528+
commandLine.setOptionsCaseInsensitive(true);
1529+
assertEquals(true, commandLine.isOptionsCaseInsensitive());
1530+
1531+
int childCount = 0;
1532+
int grandChildCount = 0;
1533+
for (CommandLine sub : commandLine.getSubcommands().values()) {
1534+
childCount++;
1535+
assertEquals("subcommand added before IS impacted", true, sub.isOptionsCaseInsensitive());
1536+
for (CommandLine subsub : sub.getSubcommands().values()) {
1537+
grandChildCount++;
1538+
assertEquals("subsubcommand added before IS impacted", true, sub.isOptionsCaseInsensitive());
1539+
}
1540+
}
1541+
assertTrue(childCount > 0);
1542+
assertTrue(grandChildCount > 0);
1543+
}
1544+
14491545
@Test
14501546
public void testParserTrimQuotes_BeforeSubcommandsAdded() {
14511547
@Command

0 commit comments

Comments
 (0)