Skip to content

Commit

Permalink
item #10 corrected issue with mixed case support
Browse files Browse the repository at this point in the history
  • Loading branch information
davenicolette committed Jan 5, 2021
1 parent 0138840 commit 84789f4
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions ALLTESTS
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
TestCase "When message type is greeting it returns 'Hello, World!'"
SET MESSAGE-IS-GREETING TO TRUE
PERFORM 2000-SPEAK
Expect WS-GREETING To Be "Hello, World !"
EXPECT WS-GREETING TO BE "Hello, World !"

testCASE "When message type is farewell it returns See you later, alligator!"
SET MESSAGE-IS-FAREWELL TO TRUE
PERFORM 2000-SPEAK
expect WS-FAREWELL to be "See you later, alligator!"
Expect WS-FAREWELL To Be "See you later, alligator!"


Binary file modified TESTPRG
Binary file not shown.
18 changes: 17 additions & 1 deletion TESTPRG.CBL
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,31 @@
MOVE "When message type is greeting it returns 'Hello, World!
- "'"
TO UT-TEST-CASE-NAME
PERFORM UT-BEFORE
SET MESSAGE-IS-GREETING TO TRUE
PERFORM 2000-SPEAK
ADD 1 TO UT-TEST-CASE-COUNT
SET UT-NORMAL-COMPARE TO TRUE
MOVE WS-GREETING TO UT-ACTUAL
MOVE "Hello, World !"
TO UT-EXPECTED
SET UT-COMPARE-DEFAULT TO TRUE
PERFORM UT-ASSERT-EQUAL
PERFORM UT-AFTER
MOVE "When message type is farewell it returns See you later,
- " alligator!"
TO UT-TEST-CASE-NAME
WS-GREETING TO BE SET MESSAGE-IS-FAREWELL TO TRUE
PERFORM UT-BEFORE
SET MESSAGE-IS-FAREWELL TO TRUE
PERFORM 2000-SPEAK
ADD 1 TO UT-TEST-CASE-COUNT
SET UT-NORMAL-COMPARE TO TRUE
MOVE WS-FAREWELL TO UT-ACTUAL
MOVE "See you later, alligator!"
TO UT-EXPECTED
SET UT-COMPARE-DEFAULT TO TRUE
PERFORM UT-ASSERT-EQUAL
PERFORM UT-AFTER
* ZUTZCPD.CPY
DISPLAY SPACE
MOVE UT-TEST-CASE-COUNT TO UT-TEST-CASE-NUMBER
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/com/neopragma/cobolcheck/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public class Generator implements Constants, StringHelper {
private static final String COBOL_DISPLAY_SPACE =
" DISPLAY SPACE ";
private static final String COBOL_DISPLAY_TESTSUITE =
" DISPLAY TESTSUITE: ";
" DISPLAY \"TESTSUITE:\" ";
private static final String COBOL_DISPLAY_NAME =
" DISPLAY %s";
private static final String COBOL_STORE_TESTCASE_NAME_1 =
" MOVE %s";
private static final String COBOL_STORE_TESTCASE_NAME_2 =
" TO %sTEST-CASE-NAME";
private static final String COBOL_PERFORM_BEFORE =
private static final String COBOL_PERFORM_UT_BEFORE =
" PERFORM %sBEFORE";
private static final String COBOL_INCREMENT_TEST_CASE_COUNT =
" ADD 1 TO %sTEST-CASE-COUNT";
Expand Down Expand Up @@ -244,10 +244,11 @@ void insertTestSuiteNameIntoTestSource(String testSuiteName, Writer testSourceOu
void insertTestCaseNameIntoTestSource(String testCaseName, Writer testSourceOut) throws IOException {
writeCobolLine(String.format(COBOL_STORE_TESTCASE_NAME_1, testCaseName), testSourceOut);
testSourceOut.write(fixedLength(String.format(COBOL_STORE_TESTCASE_NAME_2, testCodePrefix)));
testSourceOut.write(fixedLength(String.format(COBOL_PERFORM_UT_BEFORE, testCodePrefix)));
}

void insertPerformBeforeEachIntoTestSource(Writer testSourceOut) throws IOException {
testSourceOut.write(fixedLength(String.format(COBOL_PERFORM_BEFORE, testCodePrefix)));
testSourceOut.write(fixedLength(String.format(COBOL_PERFORM_UT_BEFORE, testCodePrefix)));
}

void insertIncrementTestCaseCount(Writer testSourceOut) throws IOException {
Expand All @@ -272,9 +273,9 @@ void insertTestCodeForAlphanumericEqualityCheck(Writer testSourceOut) throws IOE
testSourceOut.write(fixedLength(String.format(
COBOL_SET_UT_COMPARE_DEFAULT, testCodePrefix, TRUE)));
testSourceOut.write(fixedLength(String.format(
COBOL_PERFORM_UT_ASSERT_EQUAL, testCodePrefix, TRUE)));
COBOL_PERFORM_UT_ASSERT_EQUAL, testCodePrefix)));
testSourceOut.write(fixedLength(String.format(
COBOL_PERFORM_UT_AFTER, testCodePrefix, TRUE)));
COBOL_PERFORM_UT_AFTER, testCodePrefix)));
}

/**
Expand Down Expand Up @@ -322,7 +323,8 @@ void parseTestSuite(BufferedReader testSuiteReader, Writer testSourceOut) throws
if (!testSuiteToken.startsWith("\"") && !testSuiteToken.startsWith("\'")) {
testSuiteToken = testSuiteToken.toUpperCase(Locale.ROOT);
}
System.out.println("parseTestSuite(), testSuiteToken after upcase <" + testSuiteToken + ">");

System.out.println("parseTestSuite(), testSuiteToken uppercase is <" + testSuiteToken + ">");

Keyword keyword = Keywords.getKeywordFor(testSuiteToken);

Expand All @@ -335,6 +337,9 @@ void parseTestSuite(BufferedReader testSuiteReader, Writer testSourceOut) throws
expectTestcaseName = true;
break;
case EXPECT_KEYWORD:

System.out.println("EXPECT keyword recognized");

if (cobolStatementInProgress) {
insertUserWrittenCobolStatement(testSourceOut);
initializeCobolStatement();
Expand All @@ -357,11 +362,13 @@ void parseTestSuite(BufferedReader testSuiteReader, Writer testSourceOut) throws
expectTestsuiteName = false;
currentTestSuiteName = testSuiteToken;
insertTestSuiteNameIntoTestSource(currentTestSuiteName, testSourceOut);
initializeCobolStatement();
}
if (expectTestcaseName) {
expectTestcaseName = false;
currentTestCaseName = testSuiteToken;
insertTestCaseNameIntoTestSource(currentTestCaseName, testSourceOut);
initializeCobolStatement();
}
if (toBeInProgress) {
if (testSuiteToken.startsWith(QUOTE) || testSuiteToken.startsWith(APOSTROPHE)) {
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/com/neopragma/cobolcheck/KeywordExtractor.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.neopragma.cobolcheck;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class KeywordExtractor implements TokenExtractor, Constants {

Expand Down Expand Up @@ -48,8 +45,8 @@ public List<String> extractTokensFrom(String sourceLine) {
if (openQuote) {
buffer.append(SPACE);
} else {
if (twoWordTokens.containsKey(buffer.toString())) {
nextExpectedToken = twoWordTokens.get(buffer.toString());
if (twoWordTokens.containsKey(buffer.toString().toUpperCase(Locale.ROOT))) {
nextExpectedToken = twoWordTokens.get(buffer.toString().toUpperCase(Locale.ROOT));
buffer.append(SPACE);

int startOfLookahead = tokenOffset + 1;
Expand Down
4 changes: 2 additions & 2 deletions src/test/cobol/GREETING/GreetingByType
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
TestCase "When message type is greeting it returns 'Hello, World!'"
SET MESSAGE-IS-GREETING TO TRUE
PERFORM 2000-SPEAK
Expect WS-GREETING To Be "Hello, World !"
EXPECT WS-GREETING TO BE "Hello, World !"

testCASE "When message type is farewell it returns See you later, alligator!"
SET MESSAGE-IS-FAREWELL TO TRUE
PERFORM 2000-SPEAK
expect WS-FAREWELL to be "See you later, alligator!"
Expect WS-FAREWELL To Be "See you later, alligator!"


Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void it_recognizes_the_end_of_a_user_written_cobol_statement_when_it_enco
@Test
public void it_inserts_cobol_statements_to_display_the_testsuite_name() throws IOException {
String expectedResult =
" DISPLAY TESTSUITE: " + NEWLINE
" DISPLAY \"TESTSUITE:\" " + NEWLINE
+ " DISPLAY \"Test Suite Name\" " + NEWLINE;
generator.insertTestSuiteNameIntoTestSource("\"Test Suite Name\"", testSourceOut);
assertEquals(expectedResult, testSourceOut.toString());
Expand Down

0 comments on commit 84789f4

Please sign in to comment.