Skip to content

Commit

Permalink
marginally better feature parsing
Browse files Browse the repository at this point in the history
Fail slightly more gracefully when brackets supplied the wrong way
round.
  • Loading branch information
hcoles committed Aug 30, 2023
1 parent e52bbe2 commit 93330e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pitest/src/main/java/org/pitest/plugin/FeatureParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ private void extractValue(String part, Map<String, List<String>> vals) {
if (current == null) {
current = new ArrayList<>();
}
current.add(pairs[i + 1].trim());
if (i + 1 < pairs.length) {
current.add(pairs[i + 1].trim());
} else {
throw new RuntimeException("Could not parse feature. Parameters should be configured with +feature(param[value], param2[value2])");
}
vals.put(key, current);
}
}
Expand Down
16 changes: 9 additions & 7 deletions pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pitest.plugin;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode;

import java.util.Collections;
import java.util.List;
Expand All @@ -11,17 +12,12 @@
import java.util.Optional;

public class FeatureParserTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

FeatureParser testee = new FeatureParser();

@Test
public void shouldRejectInputNotStartingWithPlusOrMinus() {
this.thrown.expect(RuntimeException.class);
final FeatureSetting actual = parse("FOO");
assertThat(actual.addsFeature()).isFalse();
assertThatCode( () -> parse("FOO"))
.hasMessageContaining("Could not parse FOO");
}

@Test
Expand Down Expand Up @@ -88,6 +84,12 @@ public void shouldParseListValues() {
assertThat(actual.getList("things")).contains("1","2","3","4");
}

@Test
public void failsCleanlyWhenBracketsWrongWayRound() {
assertThatCode(() -> parse("+BAR[things(1])]"))
.hasMessageContaining("Could not parse feature. Parameters should be configured with +feature(param[value], param2[value2])");
}


private FeatureSetting parse(String dsl) {
final List<FeatureSetting> actual = this.testee.parseFeatures(Collections.singletonList(dsl));
Expand Down

0 comments on commit 93330e9

Please sign in to comment.