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 19 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,169 @@
/*
* 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;

public class CobolLineIndicatorProcessorImplTest {

/**
* Testing preprocessing formatting for COBOL files, making sure that only needed information is
* being passed to the parser to avoid issues and making token recognition easier
*/
@Test
public void processLinesTest() {
final String EMPTY_STRING = "";
CobolLine continuationLine = new CobolLine();
CobolLine trailingQuoteContinuationLine = new CobolLine();
CobolLine emptyContinuationLineToTest = new CobolLine();
CobolLine singleContinuationLineToTest = new CobolLine();
CobolLine goodContinuationLineToTest = new CobolLine();
CobolLine badContinuationLineToTest = new CobolLine();
CobolLine commentLineToTest = new CobolLine();
CobolLine continuationLineWithEndQuotes = new CobolLine();
CobolLine compilerDirectiveLineToTest = new CobolLine();
CobolLine normalLineToTest = new CobolLine();
CobolLine debugLineToTest = new CobolLine();
continuationLine.setType(CONTINUATION);
continuationLine.setIndicatorArea("-");
continuationLine.setContentAreaA(" \"CONTINUED LINE ENDS HERE\" ");

goodContinuationLineToTest.setType(CONTINUATION);
goodContinuationLineToTest.setSuccessor(continuationLine);
goodContinuationLineToTest.setIndicatorArea(WS);
goodContinuationLineToTest.setContentAreaA(" \"RANDOM TEXT ");
goodContinuationLineToTest.setContentAreaB(" ");

singleContinuationLineToTest.setType(CONTINUATION);
singleContinuationLineToTest.setSuccessor(continuationLine);
singleContinuationLineToTest.setIndicatorArea(WS);
singleContinuationLineToTest.setContentAreaA(" 'RANDOM TEXT ");
singleContinuationLineToTest.setContentAreaB(" ");

trailingQuoteContinuationLine.setType(CONTINUATION);
trailingQuoteContinuationLine.setSuccessor(continuationLine);
trailingQuoteContinuationLine.setIndicatorArea(WS);
trailingQuoteContinuationLine.setContentAreaA(" \"");
trailingQuoteContinuationLine.setContentAreaB("");

badContinuationLineToTest.setType(CONTINUATION);
badContinuationLineToTest.setPredecessor(goodContinuationLineToTest);
badContinuationLineToTest.setContentAreaA(" \"RANDOM TEXT ");
badContinuationLineToTest.setContentAreaB(" ");

emptyContinuationLineToTest.setType(CONTINUATION);
emptyContinuationLineToTest.setSuccessor(null);
emptyContinuationLineToTest.setContentAreaA(" ");
emptyContinuationLineToTest.setContentAreaB(" ");

commentLineToTest.setType(COMMENT);
commentLineToTest.setIndicatorArea("*");
commentLineToTest.setContentAreaA("THIS IS A COMMENT ");

compilerDirectiveLineToTest.setType(COMPILER_DIRECTIVE);
compilerDirectiveLineToTest.setIndicatorArea(WS);
compilerDirectiveLineToTest.setContentAreaA("DEFINE");

normalLineToTest.setType(NORMAL);
normalLineToTest.setFormat(FIXED);
normalLineToTest.setIndicatorArea(WS);
normalLineToTest.setContentAreaA(" RANDOM TEXT , ");

debugLineToTest.setType(DEBUG);
debugLineToTest.setIndicatorArea(WS);
debugLineToTest.setContentAreaA(" DEBUG LINE HERE ");

continuationLineWithEndQuotes.setType(CONTINUATION);
continuationLineWithEndQuotes.setPredecessor(continuationLine);
continuationLineWithEndQuotes.setSuccessor(continuationLine);
continuationLineWithEndQuotes.setIndicatorArea(WS);
continuationLineWithEndQuotes.setContentAreaA(" \"RANDOM TEXT \" ");
continuationLineWithEndQuotes.setContentAreaB(" ");

final List<CobolLine> listOfLines =
Arrays.asList(
goodContinuationLineToTest,
singleContinuationLineToTest,
trailingQuoteContinuationLine,
continuationLine,
badContinuationLineToTest,
emptyContinuationLineToTest,
commentLineToTest,
compilerDirectiveLineToTest,
normalLineToTest,
debugLineToTest,
continuationLineWithEndQuotes);
CobolLineIndicatorProcessorImpl processor = new CobolLineIndicatorProcessorImpl();
processor.processLines(listOfLines);

assertEquals(
WS + "\"RANDOM TEXT ",
processor.processLines(listOfLines).get(0).getIndicatorArea()
+ processor.processLines(listOfLines).get(0).getContentArea());
assertEquals(
WS + "'RANDOM TEXT ",
processor.processLines(listOfLines).get(1).getIndicatorArea()
+ processor.processLines(listOfLines).get(1).getContentArea());
assertEquals(
WS + "\"",
processor.processLines(listOfLines).get(2).getIndicatorArea()
+ processor.processLines(listOfLines).get(2).getContentArea());
assertEquals(
WS + "CONTINUED LINE ENDS HERE\"",
processor.processLines(listOfLines).get(3).getIndicatorArea()
+ processor.processLines(listOfLines).get(3).getContentArea());
assertEquals(
WS + "RANDOM TEXT",
processor.processLines(listOfLines).get(4).getIndicatorArea()
+ processor.processLines(listOfLines).get(4).getContentArea());
assertEquals(
WS + EMPTY_STRING,
processor.processLines(listOfLines).get(5).getIndicatorArea()
+ processor.processLines(listOfLines).get(5).getContentArea());
assertEquals(
COMMENT_TAG + WS + "THIS IS A COMMENT",
processor.processLines(listOfLines).get(6).getIndicatorArea()
+ processor.processLines(listOfLines).get(6).getContentArea());
assertEquals(
WS + EMPTY_STRING,
processor.processLines(listOfLines).get(7).getIndicatorArea()
+ processor.processLines(listOfLines).get(7).getContentArea());
assertEquals(
WS + " RANDOM TEXT , ",
processor.processLines(listOfLines).get(8).getIndicatorArea()
+ processor.processLines(listOfLines).get(8).getContentArea());
assertEquals(
WS + " DEBUG LINE HERE",
processor.processLines(listOfLines).get(9).getIndicatorArea()
+ processor.processLines(listOfLines).get(9).getContentArea());
assertEquals(
WS + "RANDOM TEXT \"",
processor.processLines(listOfLines).get(10).getIndicatorArea()
+ processor.processLines(listOfLines).get(10).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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* 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.strategy;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.util.Collections;
import org.antlr.v4.runtime.FailedPredicateException;
import org.antlr.v4.runtime.InputMismatchException;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.junit.Test;

public class CobolErrorStrategyTest {
@Test
public void noViableAltExceptionTest() {
Parser recognizer = mock(Parser.class);
TokenStream stream = mock(TokenStream.class);
Token token = mock(Token.class);

NoViableAltException error =
new NoViableAltException(recognizer, stream, token, token, null, null);
CobolErrorStrategy strategy = new CobolErrorStrategy();

when(recognizer.getInputStream()).thenReturn(stream);
when(stream.getText(token, token)).thenReturn("text");
when(recognizer.getRuleInvocationStack()).thenReturn(Collections.singletonList("rule"));

strategy.reportError(recognizer, error);

verify(recognizer).notifyErrorListeners(token, "No viable alternative at input text", error);
}

@Test
public void inputMismatchExceptionTest() {
Parser recognizer = mock(Parser.class);
Token token = mock(Token.class);
InputMismatchException errorMock = mock(InputMismatchException.class);
IntervalSet intervalSet = mock(IntervalSet.class);

String[] vocabString = new String[] {"text", "to", "test"};
VocabularyImpl vocab = new VocabularyImpl(vocabString, vocabString);
CobolErrorStrategy strategy = new CobolErrorStrategy();

when(recognizer.getRuleInvocationStack()).thenReturn(Collections.singletonList("rule"));
when(recognizer.getVocabulary()).thenReturn(vocab);
when(intervalSet.toString(vocab)).thenReturn("text");
when(errorMock.getExpectedTokens()).thenReturn(intervalSet);
when(errorMock.getOffendingToken()).thenReturn(token);

strategy.reportError(recognizer, errorMock);
verify(recognizer)
.notifyErrorListeners(token, "Syntax error on '<0>' expected text", errorMock);
}

@Test(expected = NullPointerException.class)
public void failedPredicateExceptionTest() {
Parser recognizer = mock(Parser.class);
FailedPredicateException errorMock = mock(FailedPredicateException.class);

CobolErrorStrategy strategy = new CobolErrorStrategy();

strategy.reportError(recognizer, errorMock);
}

@Test
public void unknownErrorTest() {
Parser recognizer = mock(Parser.class);
Token token = mock(Token.class);
RecognitionException errorMock = mock(RecognitionException.class);

CobolErrorStrategy strategy = new CobolErrorStrategy();

strategy.reportError(recognizer, errorMock);

verify(recognizer).notifyErrorListeners(null, null, errorMock);
}
}