Skip to content

Commit

Permalink
Add test to show additional bug fixed to do with case insensitivity i…
Browse files Browse the repository at this point in the history
…n allowed values

Before, when using allowedValues, simple arguments would take the value of the defined allowed values whereas group params would take the value of the argument passed into the dsl. With the change to the parser, they are now consistent in taking the defined allowed value in simple and group argument
  • Loading branch information
RyanHealey committed Dec 22, 2022
1 parent 2ab7991 commit 337bde8
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/test/java/com/lmax/simpledsl/internal/DslParamsParserTest.java
Original file line number Diff line number Diff line change
@@ -622,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()
{
@@ -767,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()
{

0 comments on commit 337bde8

Please sign in to comment.