Skip to content

Commit

Permalink
Polish. Report parsing errors in Assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
traceyyoshima committed Nov 29, 2023
1 parent 6ab4caf commit d0ffc22
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/openrewrite/javascript/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import org.openrewrite.javascript.tree.JS;
import org.openrewrite.test.SourceSpec;
import org.openrewrite.test.SourceSpecs;
import org.opentest4j.AssertionFailedError;

import java.util.Optional;
import java.util.function.Consumer;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -91,12 +93,14 @@ public Space visitSpace(Space space, Space.Location loc, Integer integer) {

new JavaScriptVisitor<Integer>() {
@Override
public @Nullable J preVisit(J tree, Integer integer) {
if (tree instanceof J.Unknown) {
((J.Unknown) tree).getSource().getMarkers().findFirst(ParseExceptionResult.class)
.ifPresent(result -> assertThat(result.getMessage()).isEqualTo(""));
public J visitUnknownSource(J.Unknown.Source source, Integer integer) {
Optional<ParseExceptionResult> result = source.getMarkers().findFirst(ParseExceptionResult.class);
if (result.isPresent()) {
System.out.println(result.get().getMessage());
throw new AssertionFailedError("Parsing error, J.Unknown detected");
} else {
throw new UnsupportedOperationException("A J.Unknown should always have a parse exception result.");
}
return super.preVisit(tree, integer);
}
}.visit(cu, 0);
});
Expand Down

0 comments on commit d0ffc22

Please sign in to comment.