Skip to content

Commit

Permalink
[tests] Further revise LSP tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed May 19, 2022
1 parent 82b4d4b commit 1b5dbd2
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ListIterator;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
Expand All @@ -27,8 +28,8 @@ class ErrorInserter {

/** A basic error inserter builder on which more specific error inserters can be built. */
private static final Builder BASE_ERROR_INSERTER = new Builder()
.insertCondition(s -> Stream.of(";", "}", "{").anyMatch(s::endsWith))
.insertCondition(s -> !s.trim().startsWith("else"))
.insertCondition((s0, s1) -> Stream.of(";", "}", "{").anyMatch(s0::endsWith))
.insertCondition((s0, s1) -> !s1.trim().startsWith("else"))
.insertable(" 0 = 1;").insertable("some_undeclared_var1524263 = 9;").insertable(" ++;");
public static final Builder C = BASE_ERROR_INSERTER
.replacer("lf_set(", "UNDEFINED_NAME2828376(")
Expand Down Expand Up @@ -79,7 +80,7 @@ private boolean get() {
* @param insertCondition Whether the error inserter is permitted to insert a line after a given line.
* @throws IOException if the content of {@code originalTest} cannot be read.
*/
private AlteredTest(Path originalTest, Predicate<String> insertCondition) throws IOException {
private AlteredTest(Path originalTest, BiPredicate<String, String> insertCondition) throws IOException {
this.badLines = new ArrayList<>();
this.path = originalTest;
this.lines = new LinkedList<>(); // Constant-time insertion during iteration is desired.
Expand All @@ -88,10 +89,9 @@ private AlteredTest(Path originalTest, Predicate<String> insertCondition) throws
boolean ret = true;
it.previous();
if (it.hasPrevious()) {
ret = insertCondition.test(it.previous());
ret = insertCondition.test(it.previous(), it.next());
}
it.next();
it.next();
return ret;
};
}
Expand Down Expand Up @@ -231,18 +231,18 @@ public T next() {
}
private final Node<Function<String, String>> replacers;
private final Node<String> insertables;
private final Predicate<String> insertCondition;
private final BiPredicate<String, String> insertCondition;

/** Initializes a builder for error inserters. */
public Builder() {
this(null, null, s -> true);
this(null, null, (s0, s1) -> true);
}

/** Construct a builder with the given replacers and insertables. */
private Builder(
Node<Function<String, String>> replacers,
Node<String> insertables,
Predicate<String> insertCondition
BiPredicate<String, String> insertCondition
) {
this.replacers = replacers;
this.insertables = insertables;
Expand Down Expand Up @@ -280,9 +280,10 @@ public Builder insertable(String line) {
}

/**
* Record that for any line X, insertCondition(X) is a necessary condition that a line may be inserted after X.
* Record that for any lines X, Y, insertCondition(X, Y) is a necessary condition that a line may be inserted
* between X and Y.
*/
public Builder insertCondition(Predicate<String> insertCondition) {
public Builder insertCondition(BiPredicate<String, String> insertCondition) {
return new Builder(replacers, insertables, insertCondition.and(insertCondition));
}

Expand All @@ -302,13 +303,13 @@ public ErrorInserter get(Random random) {
private final Random random;
private final ImmutableList<Function<String, String>> replacers;
private final ImmutableList<String> insertables;
private final Predicate<String> insertCondition;
private final BiPredicate<String, String> insertCondition;

private ErrorInserter(
Random random,
ImmutableList<Function<String, String>> replacers,
ImmutableList<String> insertables,
Predicate<String> insertCondition
BiPredicate<String, String> insertCondition
) {
this.random = random;
this.replacers = replacers;
Expand Down

0 comments on commit 1b5dbd2

Please sign in to comment.