Skip to content

Commit

Permalink
[tests] Repair LSP tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed May 28, 2022
1 parent 03a9e3d commit 8c41002
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 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 @@ -78,23 +78,15 @@ private boolean get() {
/**
* Initialize a possibly altered copy of {@code originalTest}.
* @param originalTest A path to an LF file that serves as a test.
* @param insertCondition Whether the error inserter is permitted to insert a line after a given line.
* @param insertCondition Whether the error inserter is permitted to insert a line between two given lines.
* @throws IOException if the content of {@code originalTest} cannot be read.
*/
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.
this.lines.addAll(Files.readAllLines(originalTest));
this.insertCondition = it -> {
boolean ret = true;
it.previous();
if (it.hasPrevious()) {
ret = insertCondition.test(it.previous(), it.next());
}
it.next();
return ret;
};
this.insertCondition = it -> insertCondition.test(it.previous(), it.hasNext() ? it.next() : ";");
}

/** Return the location where the content of {@code this} lives. */
Expand Down Expand Up @@ -172,9 +164,7 @@ public void insert(String line, Random random) {
OnceTrue onceTrue = new OnceTrue(random);
alter((it, current) -> {
if (insertCondition.test(it) && onceTrue.get()) {
it.remove();
it.add(line);
it.add(current);
return true;
}
return false;
Expand Down

0 comments on commit 8c41002

Please sign in to comment.