Skip to content

Coverage for core parser #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
30cfb54
adding junit test for PreprocessorStringUtils
Jan 9, 2020
165b8d8
added junit tests to CobolTestSuite
Jan 9, 2020
6016165
Merge branch 'development' into CoverageForCoreParser
Jan 9, 2020
ed06780
merging development
Jan 13, 2020
cccc333
Merge branch 'development' into CoverageForCoreParser
Jan 14, 2020
0f16efe
Merge branch 'development' into CoverageForCoreParser
Jan 16, 2020
1c9b8b5
adding junit test for CobolLineIndicatorProcessorImpl
Jan 16, 2020
4618c68
increased coverage on CobolLineIndicatorProcessorImplTest
Jan 20, 2020
0c02872
Merge branch 'development' into CoverageForCoreParser
Jan 20, 2020
13e0ca6
Merge branch 'development' into CoverageForCoreParser
Jan 23, 2020
b1c32d1
Merge branch 'development' into CoverageForCoreParser
Jan 27, 2020
961348f
added coverage for CobolErrorStrategy class
Jan 27, 2020
0ca20b3
corrected copyright and added missing test classes
Jan 27, 2020
9b28fc0
fixed copyright in PreprocessorStringUtilsTest
Jan 27, 2020
c388edd
Merge branch 'development' into CoverageForCoreParser
Jan 27, 2020
93566f1
adjusted CobolLineIndicatorProcessorImplTest after refactoring
Jan 27, 2020
ff45197
converted fields to local variables and removed commented line and ad…
Jan 27, 2020
7bc2a4f
corrected formatting for CobolLineIndicatorProcessorImplTest
Jan 27, 2020
cf547f1
switched methods to camel-case naming in CobolErrorStrategyTest
Jan 27, 2020
8c41b14
Merge branch 'development' into CoverageForCoreParser
Jan 28, 2020
01e8448
adjusting CobolLineIndicatorProcessorImplTest work in progress
Jan 28, 2020
90cf130
Merge branch 'development' into CoverageForCoreParser
Jan 29, 2020
0f11078
Merge branch 'development' into CoverageForCoreParser
Jan 30, 2020
72b5c46
removed unused import
Jan 30, 2020
357f35e
reworked CobolLineIndicatorProcessorImplTest.java
Jan 30, 2020
a64956f
added javadoc format documentation for each test class
Jan 30, 2020
94eb6e1
added javadoc comments for classes CobolErrorStrategyTest and CobolLi…
Jan 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@
import com.ca.lsp.core.cobol.engine.CobolLanguageEngineTest;
import com.ca.lsp.core.cobol.preprocessor.sub.line.reader.impl.CobolLineReaderImplTest;
import com.ca.lsp.core.cobol.preprocessor.sub.line.rewriter.impl.CobolCommentEntriesMarkerImplTest;
import com.ca.lsp.core.cobol.preprocessor.sub.line.rewriter.impl.CobolLineIndicatorProcessorImplTest;
import com.ca.lsp.core.cobol.preprocessor.sub.line.transformer.ContinuationLineTransformationTest;
import com.ca.lsp.core.cobol.preprocessor.sub.line.writer.impl.CobolLineWriterImplTest;
import com.ca.lsp.core.cobol.preprocessor.sub.util.PreprocessorStringUtilsTest;
import com.ca.lsp.core.cobol.semantics.CobolCleanExtraLanguageTest;
import com.ca.lsp.core.cobol.semantics.CobolVariableCheckTest;
import com.ca.lsp.core.cobol.semantics.CobolVariableContextTest;
import com.ca.lsp.core.cobol.strategy.CobolErrorStrategyTest;
import com.ca.lsp.core.cobol.visitor.LevenshteinDistanceTest;
import com.ca.lsp.core.cobol.visitor.VariableDefinitionTest;
import org.junit.runner.RunWith;
Expand All @@ -36,7 +40,11 @@
CobolVariableContextTest.class,
CobolVariableCheckTest.class,
CobolCleanExtraLanguageTest.class,
CobolLineWriterImplTest.class,
PreprocessorStringUtilsTest.class,
LevenshteinDistanceTest.class,
VariableDefinitionTest.class,
CobolLineIndicatorProcessorImplTest.class,
CobolErrorStrategyTest.class
})
public class CobolTestSuite {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
/*
* Copyright (c) 2020 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 com.ca.lsp.core.cobol.preprocessor.sub.line.rewriter.impl;

import static com.ca.lsp.core.cobol.preprocessor.CobolSourceFormat.FIXED;
import static com.ca.lsp.core.cobol.preprocessor.ProcessingConstants.COMMENT_TAG;
import static com.ca.lsp.core.cobol.preprocessor.sub.CobolLineTypeEnum.COMMENT;
import static com.ca.lsp.core.cobol.preprocessor.sub.CobolLineTypeEnum.COMPILER_DIRECTIVE;
import static com.ca.lsp.core.cobol.preprocessor.sub.CobolLineTypeEnum.CONTINUATION;
import static com.ca.lsp.core.cobol.preprocessor.sub.CobolLineTypeEnum.NORMAL;
import static com.ca.lsp.core.cobol.preprocessor.sub.CobolLineTypeEnum.DEBUG;
import static com.ca.lsp.core.cobol.preprocessor.ProcessingConstants.WS;
import static org.junit.Assert.assertEquals;

import com.ca.lsp.core.cobol.preprocessor.sub.CobolLine;

import java.util.Arrays;
import java.util.List;
import org.junit.Test;

/** Testing that the cobol lines are formatted correctly before being used for token analysis */
public class CobolLineIndicatorProcessorImplTest {

private static final String EMPTY_STRING = "";

/** Testing Debug lines preformatting for Token analysis */
@Test
public void debugLineTest() {
CobolLine debugLine = new CobolLine();
debugLine.setType(DEBUG);
debugLine.setIndicatorArea(WS);
debugLine.setContentAreaA(" ");
debugLine.setContentAreaB(" DEBUG LINE HERE ");

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
CobolLine outcome = processor.processLine(debugLine);

assertEquals(
WS + " DEBUG LINE HERE", outcome.getIndicatorArea() + outcome.getContentArea());
}

/** Testing normal lines preformatting for Token analysis */
@Test
public void normalLineTest() {
CobolLine normalLine = new CobolLine();
normalLine.setType(NORMAL);
normalLine.setFormat(FIXED);
normalLine.setIndicatorArea(WS);
normalLine.setContentAreaA(" ");
normalLine.setContentAreaB(" RANDOM TEXT , ");

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
CobolLine outcome = processor.processLine(normalLine);

assertEquals(
WS + " RANDOM TEXT , ", outcome.getIndicatorArea() + outcome.getContentArea());
}

/** Testing Compiler Directive lines preformatting for Token analysis */
@Test
public void compilerDirectiveTest() {
CobolLine compilerDirectiveLine = new CobolLine();
compilerDirectiveLine.setType(COMPILER_DIRECTIVE);
compilerDirectiveLine.setIndicatorArea(WS);
compilerDirectiveLine.setContentAreaA(" ");
compilerDirectiveLine.setContentAreaB("DEFINE");

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
CobolLine outcome = processor.processLine(compilerDirectiveLine);

assertEquals(WS + EMPTY_STRING, outcome.getIndicatorArea() + outcome.getContentArea());
}

/** Testing comment lines preformatting for Token analysis */
@Test
public void commentLineTest() {
CobolLine commentLine = new CobolLine();
commentLine.setType(COMMENT);
commentLine.setIndicatorArea("*");
commentLine.setContentAreaA(" ");
commentLine.setContentAreaB("THIS IS A COMMENT ");

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();

CobolLine outcome = processor.processLine(commentLine);

assertEquals(
COMMENT_TAG + WS + " THIS IS A COMMENT",
outcome.getIndicatorArea() + outcome.getContentArea());
}

/** Testing normal continuation line preformatting for Token analysis */
@Test
public void continuationLineTest() {
CobolLine startContinuationLine = new CobolLine();
startContinuationLine.setType(NORMAL);
startContinuationLine.setIndicatorArea(WS);
startContinuationLine.setContentAreaA(" ");
startContinuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine middleContinuationLine = new CobolLine();
middleContinuationLine.setType(CONTINUATION);
middleContinuationLine.setIndicatorArea("-");
middleContinuationLine.setContentAreaA(" ");
middleContinuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine lastContinuationLine = new CobolLine();
lastContinuationLine.setType(CONTINUATION);
lastContinuationLine.setIndicatorArea("-");
lastContinuationLine.setContentAreaA(" ");
lastContinuationLine.setContentAreaB(" \"CONTINUED LINE ENDS HERE\" ");

startContinuationLine.setSuccessor(middleContinuationLine);
middleContinuationLine.setSuccessor(lastContinuationLine);

List<CobolLine> listOfLines =
Arrays.asList(startContinuationLine, middleContinuationLine, lastContinuationLine);
CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
List<CobolLine> outcomeList = processor.processLines(listOfLines);

assertEquals(
WS + " \"RANDOM TEXT ",
outcomeList.get(0).getIndicatorArea() + outcomeList.get(0).getContentArea());
assertEquals(
WS + "RANDOM TEXT ",
outcomeList.get(1).getIndicatorArea() + outcomeList.get(1).getContentArea());
assertEquals(
WS + "\"CONTINUED LINE ENDS HERE\"",
outcomeList.get(2).getIndicatorArea() + outcomeList.get(2).getContentArea());
}

/** Testing empty continuation line preformatting for Token analysis */
@Test
public void emptyContinuationLine() {
CobolLine continuationLine = new CobolLine();
continuationLine.setType(NORMAL);
continuationLine.setIndicatorArea(WS);
continuationLine.setContentAreaA(" ");
continuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine emptyContinuationLine = new CobolLine();
emptyContinuationLine.setType(CONTINUATION);
emptyContinuationLine.setIndicatorArea("-");
emptyContinuationLine.setContentAreaA(" ");
emptyContinuationLine.setContentAreaB(" ");

continuationLine.setSuccessor(emptyContinuationLine);

final List<CobolLine> listOfLines = Arrays.asList(continuationLine, emptyContinuationLine);
CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
List<CobolLine> outcomeList = processor.processLines(listOfLines);

assertEquals(
WS + " \"RANDOM TEXT ",
outcomeList.get(0).getIndicatorArea() + outcomeList.get(0).getContentArea());
assertEquals(
WS + EMPTY_STRING,
outcomeList.get(1).getIndicatorArea() + outcomeList.get(1).getContentArea());
}

/** Testing continuation lines with trailing comma preformatting for Token analysis */
@Test
public void trailingCommaContinuationLineTest() {
CobolLine startContinuationLine = new CobolLine();
startContinuationLine.setType(NORMAL);
startContinuationLine.setIndicatorArea(WS);
startContinuationLine.setContentAreaA(" ");
startContinuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine trailingCommaContinuationLine = new CobolLine();
trailingCommaContinuationLine.setType(CONTINUATION);
trailingCommaContinuationLine.setIndicatorArea("-");
trailingCommaContinuationLine.setContentAreaA(" ");
trailingCommaContinuationLine.setContentAreaB(" ,");

startContinuationLine.setSuccessor(trailingCommaContinuationLine);
trailingCommaContinuationLine.setPredecessor(startContinuationLine);

List<CobolLine> listOfLines =
Arrays.asList(startContinuationLine, trailingCommaContinuationLine);
CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
List<CobolLine> outcomeList = processor.processLines(listOfLines);

assertEquals(
WS + " \"RANDOM TEXT ",
outcomeList.get(0).getIndicatorArea() + outcomeList.get(0).getContentArea());
assertEquals(
WS + " ," + WS,
outcomeList.get(1).getIndicatorArea() + outcomeList.get(1).getContentArea());
}

/**
* Testing a continuation line with no quotes at the start of the line preformatting for Token
* analysis
*/
@Test
public void continuationLineWithoutBeginningQuotes() {
CobolLine startContinuationLine = new CobolLine();
startContinuationLine.setType(NORMAL);
startContinuationLine.setIndicatorArea(WS);
startContinuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine quoteContinuationLine = new CobolLine();
quoteContinuationLine.setType(CONTINUATION);
quoteContinuationLine.setIndicatorArea("-");
quoteContinuationLine.setContentAreaA(" ");
quoteContinuationLine.setContentAreaB(" \"RANDOM TEXT SINGLE CONTINUATION LINE\"");

CobolLine lastContinuationLine = new CobolLine();
lastContinuationLine.setType(CONTINUATION);
lastContinuationLine.setIndicatorArea("-");
lastContinuationLine.setContentAreaA(" ");
lastContinuationLine.setContentAreaB(" RANDOM TEXT SINGLE CONTINUATION LINE\"");

startContinuationLine.setSuccessor(quoteContinuationLine);
quoteContinuationLine.setSuccessor(lastContinuationLine);

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();

CobolLine outcome = processor.processLine(lastContinuationLine);

assertEquals(
WS + "RANDOM TEXT SINGLE CONTINUATION LINE\"",
outcome.getIndicatorArea() + outcome.getContentArea());
}

/**
* Testing a continuation line with quotes at the start and end of the line preformatting for
* Token analysis
*/
@Test
public void continuationLineWithOuterQuotes() {
CobolLine startContinuationLine = new CobolLine();
startContinuationLine.setType(NORMAL);
startContinuationLine.setIndicatorArea(WS);
startContinuationLine.setContentAreaB(" \"RANDOM TEXT ");

CobolLine quoteContinuationLine = new CobolLine();
quoteContinuationLine.setType(CONTINUATION);
quoteContinuationLine.setIndicatorArea("-");
quoteContinuationLine.setContentAreaA(" ");
quoteContinuationLine.setContentAreaB(" \"RANDOM TEXT SINGLE CONTINUATION LINE\"");

CobolLine lastContinuationLine = new CobolLine();
lastContinuationLine.setType(CONTINUATION);
lastContinuationLine.setIndicatorArea("-");
lastContinuationLine.setContentAreaA(" ");
lastContinuationLine.setContentAreaB(" \"RANDOM TEXT SINGLE CONTINUATION LINE\"");

startContinuationLine.setSuccessor(quoteContinuationLine);
quoteContinuationLine.setSuccessor(lastContinuationLine);

CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();

CobolLine outcome = processor.processLine(lastContinuationLine);

assertEquals(
WS + "RANDOM TEXT SINGLE CONTINUATION LINE\"",
outcome.getIndicatorArea() + outcome.getContentArea());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2020 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 com.ca.lsp.core.cobol.preprocessor.sub.util;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class PreprocessorStringUtilsTest {

static final String TEST_SINGLE_QUOTE_STRING = "\'TESTING IF ALL QUOTES WILL BE REMOVED\'";
static final String TEST_DOUBLE_QUOTE_STRING = "\"TESTING IF ALL QUOTES WILL BE REMOVED\"";
static final String EXPECTED_STRING = "TESTING IF ALL QUOTES WILL BE REMOVED";

@Test
public void trimQuotesTest() {
assertEquals(EXPECTED_STRING, PreprocessorStringUtils.trimQuotes(TEST_SINGLE_QUOTE_STRING));
assertEquals(EXPECTED_STRING, PreprocessorStringUtils.trimQuotes(TEST_DOUBLE_QUOTE_STRING));
}
}
Loading