From 1b5dbd28d8507ecccd148c3b615f27f1cd116234 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 18 May 2022 20:40:57 -0700 Subject: [PATCH] [tests] Further revise LSP tests. --- .../org/lflang/tests/lsp/ErrorInserter.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java index 01f3d5a651..c90d510ddc 100644 --- a/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java +++ b/org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java @@ -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; @@ -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(") @@ -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 insertCondition) throws IOException { + private AlteredTest(Path originalTest, BiPredicate insertCondition) throws IOException { this.badLines = new ArrayList<>(); this.path = originalTest; this.lines = new LinkedList<>(); // Constant-time insertion during iteration is desired. @@ -88,10 +89,9 @@ private AlteredTest(Path originalTest, Predicate 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; }; } @@ -231,18 +231,18 @@ public T next() { } private final Node> replacers; private final Node insertables; - private final Predicate insertCondition; + private final BiPredicate 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> replacers, Node insertables, - Predicate insertCondition + BiPredicate insertCondition ) { this.replacers = replacers; this.insertables = insertables; @@ -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 insertCondition) { + public Builder insertCondition(BiPredicate insertCondition) { return new Builder(replacers, insertables, insertCondition.and(insertCondition)); } @@ -302,13 +303,13 @@ public ErrorInserter get(Random random) { private final Random random; private final ImmutableList> replacers; private final ImmutableList insertables; - private final Predicate insertCondition; + private final BiPredicate insertCondition; private ErrorInserter( Random random, ImmutableList> replacers, ImmutableList insertables, - Predicate insertCondition + BiPredicate insertCondition ) { this.random = random; this.replacers = replacers;