Skip to content

Commit

Permalink
chore: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurkambay authored and ishche committed May 13, 2024
1 parent 0094f34 commit 77d66cb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* Extended Text contains information about original text and current text with the mapping
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.experimental.UtilityClass;
import org.eclipse.lsp.cobol.common.model.Locality;
import org.eclipse.lsp.cobol.common.model.tree.CopyNode;
import org.eclipse.lsp.cobol.common.model.tree.Node;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
Expand All @@ -37,6 +38,13 @@ public class RangeUtils {
*/
public static Optional<Node> findNodeByPosition(Node node, String uri, Position position) {
Node candidate = null;
if (isFromCopybook(uri, node)) {
if (node.getChildren().isEmpty()) {
return Optional.of(node);
}
candidate = node;
}

if (isInside(uri, position, node.getLocality())) {
if (node.getChildren().isEmpty()) {
return Optional.of(node);
Expand All @@ -53,6 +61,14 @@ public static Optional<Node> findNodeByPosition(Node node, String uri, Position
return candidate == null ? Optional.empty() : Optional.of(candidate);
}

private boolean isFromCopybook(String uri, Node node) {
if (!(node instanceof CopyNode)) {
return false;
}
CopyNode copyNode = (CopyNode) node;
return uri.equals(copyNode.getUri());
}

/**
* Test if one position is after the another position.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ startRule: .*? (execRule .*?) * EOF;
execRule: EXEC SQL sqlCode END_EXEC
| EXEC SQL END_EXEC
| EXEC SQLIMS sqlCode END_EXEC // TODO: check when should this grammar be activated. Probably based on some compiler directives
| {notifyError("cobolParser.missingEndExec");} EXEC SQL sqlCode EOF
| {notifyError("cobolParser.missingEndExec");} EXEC SQL sqlCode DOT_FS? EOF
| {notifyError("cobolParser.missingEndExec");} EXEC SQL;

sqlCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,15 @@ public List<Node> visitParagraphs(ParagraphsContext ctx) {

@Override
public List<Node> visitProcedureDivisionBody(ProcedureDivisionBodyContext ctx) {
return addTreeNode(ctx, ProcedureDivisionBodyNode::new);

ParserRuleContext context = new ParserRuleContext();
context.start = ctx.getParent().start;
context.stop = ctx.stop;

List<Node> children = visitChildren(ctx);
return retrieveLocality(context)
.map(constructNode(ProcedureDivisionBodyNode::new, children))
.orElse(children);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<ProcessorDescription> getProcessors() {
new ImplicitDb2VariablesProcessor()),
new ProcessorDescription(
Db2DataAndProcedureDivisionNode.class,
ProcessingPhase.POST_DEFINITION,
ProcessingPhase.VALIDATION,
new Db2DataAndProcedureDivisionProcessor(messageService)),
new ProcessorDescription(
Db2DeclareVariableNode.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

/**
* This test checks that the an asterisk out of indicator area before the COPY statement doesn't
* This test checks that the asterisk out of indicator area before the COPY statement doesn't
* break syntax analysis
*/
class TestAsteriskBeforeCopyDoesntBreakAnalysis {
Expand Down Expand Up @@ -60,7 +61,8 @@ void test() {
}

@Test
void testРц() {
@Disabled("Experimental parser")
void testEx() {

UseCaseEngine.runTest(
TEXT,
Expand Down

0 comments on commit 77d66cb

Please sign in to comment.