Skip to content

Commit

Permalink
Merge pull request #1250 from hcoles/feature/feature_parsing
Browse files Browse the repository at this point in the history
marginally better feature parsing
  • Loading branch information
hcoles authored Aug 30, 2023
2 parents e52bbe2 + 93330e9 commit 3e38926
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 3e38926

Please sign in to comment.