Skip to content

Commit

Permalink
Fix numeric field type wrong interpretation when line is split
Browse files Browse the repository at this point in the history
  • Loading branch information
AkashKumar7902 committed Aug 28, 2023
1 parent 426fa6c commit efaacd4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ private void updateDependencies(CobolLine line) throws IOException {

if (reader.isFlagSet(Constants.DATA_DIVISION)) {
this.currentDataStructure = updateCurrentDataStructure(currentStatement, currentDataStructure);
line = line.convertCobolLinesToCobolLine(currentStatement);
updateNumericFields(line);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.openmainframeproject.cobolcheck.services.cobolLogic;

import org.openmainframeproject.cobolcheck.features.interpreter.StringTokenizerExtractor;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -111,4 +113,13 @@ private String removeSequenceNumberArea(String originalLine){
else
return " " + originalLine.substring(index);
}

public CobolLine convertCobolLinesToCobolLine(List<CobolLine> cobolLines) {
String line = "";
for (CobolLine cobolLine : cobolLines){
line += cobolLine.getUnNumberedString();
}
TokenExtractor tokenExtractor = new StringTokenizerExtractor();
return new CobolLine(line, tokenExtractor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,18 @@ private static Integer determineCobolLevelNumber(String levelNumberString){

private static String[] extractStatementWords(List<CobolLine> currentStatement){
String statementString = "";
for(CobolLine loopLine: currentStatement){
statementString += loopLine.getTrimmedString();
boolean[] isContinuationLine = new boolean[currentStatement.size()];
Arrays.fill(isContinuationLine, false);
for(int i = 1; i < currentStatement.size(); ++i) {
if(currentStatement.get(i).getTrimmedString().startsWith("-")){
isContinuationLine[i] = true;
}
}
for(int i = 0; i < currentStatement.size(); ++i){
statementString += currentStatement.get(i).getTrimmedString();
if(!isContinuationLine[i]){
statementString += " ";
}
}
statementString = statementString.trim().replace(Constants.PERIOD, "");
String[] statementWords = statementString.split("\\s+");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,19 @@ public void it_updates_numeric_fields() throws IOException {
String str4 = " 05 OUTPUT-FILE-STATUS PIC XX.";
String str5 = " 88 OUTPUT-OK VALUE '00'.";
String str6 = " 05.";
String str7 = " 08 WS-COUNT PIC S9(5) COMP-3.";
String str8 = " 05 WS-DISPLAY-NUM2 PIC 9(04) OCCURS";
String str9 = " 20.";
String str10 = " 05 TEMP-VAL PIC X(200) VALUE SPACES.";
String str11 = " 77 CHAR-CT PIC S9(3) COMP.";
String str7 = " 08 WS-COUNT ";
String str8 = " PIC S9(5) COMP-3.";
String str9 = " 05 WS-DISPLAY-NUM2 PIC 9(04) OCCURS";
String str10 = " 20.";
String str11 = " 05 TEMP-VAL PIC X(200) VALUE SPACES.";
String str12 = " 77 CHAR-CT PIC S9(3) COMP.";


Mockito.when(mockedReader.readLine()).thenReturn(str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, null);
Mockito.when(mockedReader.readLine()).thenReturn(str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12, null);

while (interpreterController.interpretNextLine() != null){
interpreterController.interpretNextLine();
}

assertEquals("PACKED_DECIMAL",
interpreterController.getNumericFieldDataTypeFor("WS-COUNT").name());
assertEquals("DISPLAY_NUMERIC",
Expand Down

0 comments on commit efaacd4

Please sign in to comment.