Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

marginally better feature parsing #1250

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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