Skip to content

Commit

Permalink
Merge pull request #21 from RyanHealey/feature/multiple-values-in-rep…
Browse files Browse the repository at this point in the history
…eating-groups

Split multiple values in repeating groups by delimiter
  • Loading branch information
swarren12 authored Jan 9, 2023
2 parents 1e06e14 + 337bde8 commit 81182e5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ void consume(final RepeatingArgGroup groupArg, final Deque<NameValuePair> argume
break;
}

checkValidValue(arg, argument.value);
argValues.add(argument.value);
SimpleArgumentProcessor.addValue(arg, argument.value, argValues);
arguments.pollFirst();
}

Expand Down
45 changes: 42 additions & 3 deletions src/test/java/com/lmax/simpledsl/internal/DslParamsParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.lmax.simpledsl.api.RepeatingArgGroup;
import com.lmax.simpledsl.api.RepeatingGroup;
import com.lmax.simpledsl.api.RequiredArg;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
Expand Down Expand Up @@ -491,7 +490,6 @@ public void shouldBeAbleToSpecifyMultipleValuesForParamInGroup()
}

@Test
@Disabled("Doesn't work?")
public void shouldBeAbleToSpecifyMultipleValuesForParamInGroupUsingTheDefaultSeparator()
{
final String[] args = {"a: value", "group: Joe", "group: Jenny", "value: 1, 2"};
Expand All @@ -518,7 +516,6 @@ public void shouldBeAbleToSpecifyMultipleValuesForParamInGroupUsingTheDefaultSep
}

@Test
@Disabled("Doesn't work?")
public void shouldBeAbleToSpecifyMultipleValuesForParamInGroupUsingACustomSeparator()
{
final String[] args = {"a: value", "group: Joe", "group: Jenny", "value: 1;2"};
Expand Down Expand Up @@ -625,6 +622,28 @@ public void shouldMatchAllowedValuesCaseInsensitivelyAndReturnValuesUsingTheCase
assertArrayEquals(new String[]{"abc", "def"}, params.values("myValue"));
}

@Test
public void shouldMatchAllowedValuesCaseInsensitivelyAndReturnValuesUsingTheCaseProvidedInTheDSLWithinRepeatingGroups()
{
final String[] args = {"a: value", "myGroup: joe", "myValue: a"};
final DslArg[] parameters = {
new RequiredArg("a"),
new RepeatingArgGroup(
new RequiredArg("myGroup").setAllowedValues("Joe", "Jenny"),
new RequiredArg("myValue").setAllowedValues("A", "B"))
};

final DslParamsParser parser = new DslParamsParser();

final DslParams params = parser.parse(args, parameters);

assertEquals("value", params.value("a"));
final RepeatingGroup[] groups = params.valuesAsGroup("myGroup");
assertEquals(1, groups.length);
assertEquals("Joe", groups[0].value("myGroup"));
assertEquals("A", groups[0].value("myValue"));
}

@Test
public void shouldMatchAllowedValuesSpecifiedViaABoolean()
{
Expand Down Expand Up @@ -770,6 +789,26 @@ public void shouldThrowAnExceptionIfInvalidParameterValueIsSpecifiedInRepeatingG
assertEquals("myValue parameter value '1' must be one of: [A, B]", exception.getMessage());
}

@Test
public void shouldThrowAnExceptionIfInvalidParameterValueIsSpecifiedInRepeatingGroupIdentity()
{
final String[] args = {"a: value", "myGroup: Joe", "myValue: 1"};
final DslArg[] parameters = {
new RequiredArg("a"),
new RepeatingArgGroup(
new RequiredArg("myGroup").setAllowedValues("A", "B"),
new RequiredArg("myValue"))
};

final DslParamsParser parser = new DslParamsParser();

final IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> parser.parse(args, parameters));

assertEquals("myGroup parameter value 'Joe' must be one of: [A, B]", exception.getMessage());
}

@Test
public void shouldThrowAnExceptionWhenMissingAValueForARequiredArg()
{
Expand Down

0 comments on commit 81182e5

Please sign in to comment.