-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test as suggested in PR#2439
Signed-off-by: ap891843 <aman.prashant@broadcom.com>
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...rc/test/java/org/eclipse/lsp/cobol/usecases/TestCopynodeInsertionAtCorrectPlaceInAST.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2024 Broadcom. | ||
* The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Broadcom, Inc. - initial API and implementation | ||
* | ||
*/ | ||
package org.eclipse.lsp.cobol.usecases; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.eclipse.lsp.cobol.common.AnalysisResult; | ||
import org.eclipse.lsp.cobol.common.model.tree.Node; | ||
import org.eclipse.lsp.cobol.test.CobolText; | ||
import org.eclipse.lsp.cobol.test.engine.UseCaseEngine; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** Test CopyNode position in AST when it contains CICS or SQL statements */ | ||
public class TestCopynodeInsertionAtCorrectPlaceInAST { | ||
public static final String TEXT = | ||
" IDENTIFICATION DIVISION.\n" | ||
+ " PROGRAM-ID. CBACT01C.\n" | ||
+ " DATA DIVISION.\n" | ||
+ " WORKING-STORAGE SECTION.\n" | ||
+ " 01 {$*SOME-VAR} pic x.\n" | ||
+ " 01 {$*SOME_VAR_2} pic x.\n" | ||
+ " PROCEDURE DIVISION.\n" | ||
+ " IF {$SOME-VAR} > {$SOME_VAR_2} " | ||
+ " PERFORM {#HANDLE-ABEND}\n" | ||
+ " COPY {~COPY1}.\n" | ||
+ " DISPLAY '1'\n" | ||
+ " END-IF.\n" | ||
+ " {#*HANDLE-ABEND}."; | ||
|
||
public static final String COPYBOOK_CONTENT = | ||
" EXEC CICS HANDLE ABEND LABEL({#HANDLE-ABEND}) END-EXEC"; | ||
|
||
@Test | ||
void test() { | ||
AnalysisResult result = | ||
UseCaseEngine.runTest( | ||
TEXT, ImmutableList.of(new CobolText("COPY1", COPYBOOK_CONTENT)), ImmutableMap.of()); | ||
|
||
String astFlatStructure = | ||
result | ||
.getRootNode() | ||
.getDepthFirstStream() | ||
.map(Node::getNodeType) | ||
.map(Objects::toString) | ||
.collect(Collectors.joining("-->")); | ||
Assertions.assertTrue( | ||
astFlatStructure.matches(".*SENTENCE-->IF-->.*?-->PERFORM-->.*?-->COPY-->STATEMENT.*")); | ||
} | ||
} |