Skip to content

Commit

Permalink
Filter out blank lines and comments in a multi-line transformations (#…
Browse files Browse the repository at this point in the history
…4357)

Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng authored Sep 7, 2024
1 parent 1145613 commit 5cf91cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ public ChannelTransformation(@Nullable String transformationString) {
public ChannelTransformation(@Nullable List<String> transformationStrings) {
if (transformationStrings != null) {
try {
transformationSteps = transformationStrings.stream()
.flatMap(ChannelTransformation::splitTransformationString).map(TransformationStep::new)
transformationSteps = transformationStrings.stream() //
.map(String::trim) //
.filter(line -> !line.isBlank()) //
.filter(line -> !line.startsWith("#")) //
.filter(line -> !line.startsWith("//")) //
.flatMap(ChannelTransformation::splitTransformationString) //
.map(TransformationStep::new) //
.toList();
return;
} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,15 @@ public void testIsValidTransform() {
assertFalse(ChannelTransformation.isValidTransformation("FOO∩BAZ:BAR"));
assertFalse(ChannelTransformation.isValidTransformation("FOO∩BAZ(BAR)"));
}

@Test
public void testBlanksAndCommentsAreDiscarded() {
List<String> pattern = List.of("#hash comment", "//double slashes", " # preceded by spaces",
" // ditto for slashes", " ", "\t", "\t\t\t", "\t# preceded by a tab",
"\t // preceded by tab and space");

ChannelTransformation transformation = new ChannelTransformation(pattern);

assertTrue(transformation.isEmpty());
}
}

0 comments on commit 5cf91cd

Please sign in to comment.