Skip to content

Commit

Permalink
Allow keys to have upper case characters and periods in ArgsConfigura…
Browse files Browse the repository at this point in the history
…tion (#29)
  • Loading branch information
51-code authored Jan 13, 2025
1 parent b53836e commit 7c871d0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/teragrep/cnf_01/ArgsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Map<String, String> asMap() throws ConfigurationException {
final Map<String, String> map = new HashMap<>();

if (args.length != 0) {
final Pattern ptn = Pattern.compile("([a-z]+)(=.+)");
final Pattern ptn = Pattern.compile("([A-Za-z.]+)(=.+)");
for (final String arg : args) {
final Matcher matcher = ptn.matcher(arg);
if (!matcher.matches() || matcher.group(1) == null | matcher.group(2) == null) {
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/teragrep/cnf_01/ArgsConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ public void testValidArgs() {
Assertions.assertEquals("foo", map.get("bar"));
}

@Test
public void testCamelCaseArgs() {
String[] args = {
"exampleOption=value"
};
ArgsConfiguration config = new ArgsConfiguration(args);
Map<String, String> map = Assertions.assertDoesNotThrow(config::asMap);

Assertions.assertEquals(1, map.size());
Assertions.assertTrue(map.containsKey("exampleOption"));
Assertions.assertEquals("value", map.get("exampleOption"));
}

@Test
public void testDotArgs() {
String[] args = {
"example.option=value"
};
ArgsConfiguration config = new ArgsConfiguration(args);
Map<String, String> map = Assertions.assertDoesNotThrow(config::asMap);

Assertions.assertEquals(1, map.size());
Assertions.assertTrue(map.containsKey("example.option"));
Assertions.assertEquals("value", map.get("example.option"));
}

@Test
public void testInvalidArgs() {
String[] args = {
Expand Down

0 comments on commit 7c871d0

Please sign in to comment.