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 f05c71b
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions org.lflang.tests/src/org/lflang/tests/lsp/ErrorInserter.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ 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 {
Expand All @@ -87,13 +87,11 @@ private AlteredTest(Path originalTest, BiPredicate<String, String> insertConditi
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());
}
String s0 = it.previous();
it.next();
return ret;
String s1 = it.next();
it.previous();
return insertCondition.test(s0, s1);
};
}

Expand Down Expand Up @@ -172,9 +170,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 All @@ -197,7 +193,7 @@ private void alter(BiFunction<ListIterator<String>, String, Boolean> alterer) {
String uncommented = current.contains("//") ?
current.substring(0, current.indexOf("//")) : current;
if (uncommented.contains("=}")) inCodeBlock = false;
if (inCodeBlock && alterer.apply(it, current)) badLines.add(lineNumber);
if (inCodeBlock && alterer.apply(it, current)) badLines.add(lineNumber + 1);
if (uncommented.contains("{=")) inCodeBlock = true;
if (uncommented.contains("{=") && uncommented.contains("=}")) {
inCodeBlock = uncommented.lastIndexOf("{=") > uncommented.lastIndexOf("=}");
Expand Down

0 comments on commit f05c71b

Please sign in to comment.