-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
item #10 started to implement keyword parsing support for test suites
- Loading branch information
1 parent
74a8f80
commit bc04310
Showing
34 changed files
with
2,195 additions
and
21 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
# Pad all lines of a text file to 80 characters plus newline | ||
awk -F, '{printf("%80-s\n", $1)}' "$1" > "$2" | ||
paddir="$1" | ||
padsource="$2" | ||
padtarget="$3" | ||
awk -F, '{printf("%80-s\n", $1)}' "$paddir/$padsource" > "$paddir/$padtarget" |
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
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
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,33 @@ | ||
/* | ||
Copyright 2020 David Nicolette | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.neopragma.cobolcheck; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* This record encapsulates information about a cobol-check keyword. | ||
* | ||
* value = the value of the keyword as a string (note that some keywords have embedded spaces, like "TO BE") | ||
* validNextKey = list of keys in Keywords for tokens that may follow the current keyword in the test suite. | ||
* keywordAction = special handling for this keyword, if any. | ||
* | ||
* @author Dave Nicolette (neopragma) | ||
* @since 14 | ||
*/ | ||
public record Keyword( | ||
String value, | ||
List<String> validNextKey, | ||
KeywordAction keywordAction) { } |
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,39 @@ | ||
/* | ||
Copyright 2020 David Nicolette | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.neopragma.cobolcheck; | ||
|
||
/** | ||
* Special handling pertaining to a cobol-check keyword. Used when parsing a testsuite and inserting the | ||
* corresponding Cobol code into the program under test. KeywordAction is a member of record type Keyword. | ||
* | ||
* NONE - no special action is associated with this keyword | ||
* ACTUAL_FIELDNAME - the next token will be the fieldname of the actual (result) value for an EXPECT | ||
* EXPECTED_VALUE - the next token will be the expected value for an EXPECT | ||
* REVERSE_LOGIC - the comparison logic for this EXPECT is to be reversed (NOT logic) | ||
* IGNORE - the next token will be TESTCASE - bypass that test case | ||
* FIELDNAME - this token is the name of a field in the Data Division of the program under test | ||
* | ||
* @author Dave Nicolette (neopragma) | ||
* @since 14 | ||
*/ | ||
public enum KeywordAction { | ||
NONE, | ||
ACTUAL_FIELDNAME, | ||
EXPECTED_VALUE, | ||
REVERSE_LOGIC, | ||
IGNORE, | ||
FIELDNAME | ||
} |
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,72 @@ | ||
/* | ||
Copyright 2020 David Nicolette | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.neopragma.cobolcheck; | ||
|
||
import com.neopragma.cobolcheck.exceptions.UndefinedKeywordException; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This is a container for Keyword records. It is used when parsing test suites to identify cobol-check | ||
* keywords and handle them appropriately. | ||
* | ||
* @author Dave Nicolette (neopragma) | ||
* @since 14 | ||
*/ | ||
public class Keywords implements Constants { | ||
private static final Messages messages = new Messages(); | ||
private static final Map<String, Keyword> keywordInfo; | ||
|
||
static { | ||
keywordInfo = new HashMap<>(); | ||
keywordInfo.put(EXPECT_KEYWORD, | ||
new Keyword(EXPECT_KEYWORD, List.of(FIELDNAME_KEYWORD), | ||
KeywordAction.ACTUAL_FIELDNAME)); | ||
keywordInfo.put(FIELDNAME_KEYWORD, | ||
new Keyword(EMPTY_STRING, List.of(TO_BE_KEYWORD, NOT_KEYWORD), | ||
KeywordAction.FIELDNAME)); | ||
keywordInfo.put(NOT_KEYWORD, | ||
new Keyword(NOT_KEYWORD, List.of(TO_BE_KEYWORD), | ||
KeywordAction.REVERSE_LOGIC)); | ||
keywordInfo.put(TO_BE_KEYWORD, | ||
new Keyword(TO_BE_KEYWORD, | ||
List.of(FIELDNAME_KEYWORD, | ||
"alphanumeric-literal", | ||
"numeric-literal", | ||
TRUE, | ||
FALSE), | ||
KeywordAction.EXPECTED_VALUE)); | ||
keywordInfo.put("alphanumeric-literal", | ||
new Keyword(EMPTY_STRING, List.of(), | ||
KeywordAction.FIELDNAME)); | ||
keywordInfo.put("numeric-literal", | ||
new Keyword(EMPTY_STRING, List.of(), | ||
KeywordAction.FIELDNAME)); | ||
} | ||
|
||
public static Keyword getKeywordFor(String key) { | ||
Keyword result = keywordInfo.get(key); | ||
if (result == null) { | ||
throw new UndefinedKeywordException( | ||
messages.get("ERR009", | ||
key) | ||
); | ||
} | ||
return result; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/neopragma/cobolcheck/exceptions/UndefinedKeywordException.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,22 @@ | ||
/* | ||
Copyright 2020 David Nicolette | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package com.neopragma.cobolcheck.exceptions; | ||
|
||
public class UndefinedKeywordException extends RuntimeException { | ||
public UndefinedKeywordException(String message) { | ||
super(message); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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,48 @@ | ||
package com.neopragma.cobolcheck; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class KeywordsTest implements Constants { | ||
|
||
@ParameterizedTest | ||
@MethodSource("KeywordProvider") | ||
public void it_returns_the_keyword_record_for_a_given_key( | ||
String key, | ||
String expectedKeywordValue, | ||
List<String> expectedValidNextKey, | ||
KeywordAction expectedKeywordAction) { | ||
Keyword keyword = Keywords.getKeywordFor(key); | ||
assertEquals(expectedKeywordValue, keyword.value()); | ||
assertEquals(expectedKeywordAction, keyword.keywordAction()); | ||
assertEquals(expectedValidNextKey, keyword.validNextKey()); | ||
} | ||
|
||
private static Stream<Arguments> KeywordProvider() { | ||
return Stream.of( | ||
Arguments.of(EXPECT_KEYWORD, EXPECT_KEYWORD, | ||
List.of(FIELDNAME_KEYWORD), | ||
KeywordAction.ACTUAL_FIELDNAME), | ||
Arguments.of(FIELDNAME_KEYWORD, EMPTY_STRING, | ||
List.of(TO_BE_KEYWORD, NOT_KEYWORD), | ||
KeywordAction.FIELDNAME), | ||
Arguments.of(NOT_KEYWORD, NOT_KEYWORD, | ||
List.of(TO_BE_KEYWORD), | ||
KeywordAction.REVERSE_LOGIC), | ||
Arguments.of(TO_BE_KEYWORD, TO_BE_KEYWORD, | ||
List.of(FIELDNAME_KEYWORD, | ||
ALPHANUMERIC_LITERAL_KEYWORD, | ||
NUMERIC_LITERAL_KEYWORD, | ||
TRUE, | ||
FALSE), | ||
KeywordAction.EXPECTED_VALUE) | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.