Skip to content

Commit

Permalink
fix: CICS commands defects (eclipse-che4z#2700)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilidio-lopes authored Jan 24, 2025
1 parent 44a8e38 commit 9c2a4a4
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ private void checkDocumentCreate(CICSParser.Cics_document_createContext ctx) {
if (!ctx.LENGTH().isEmpty()) {
checkHasExactlyOneOption("FROM, TEXT or BINARY", ctx, ctx.FROM(), ctx.TEXT(), ctx.BINARY());
}
if (!ctx.FROM().isEmpty() || !ctx.TEXT().isEmpty() || !ctx.BINARY().isEmpty()) {
checkHasMandatoryOptions(ctx.LENGTH(), ctx, "LENGTH");
}
checkHasMutuallyExclusiveOptions("LENGTH, FROMDOC or TEMPLATE",
ctx.LENGTH(), ctx.FROMDOC(), ctx.TEMPLATE());
if (!ctx.DELIMITER().isEmpty() || !ctx.UNESCAPED().isEmpty()) {
Expand All @@ -125,6 +128,9 @@ private void checkDocumentInsert(CICSParser.Cics_document_insertContext ctx) {
if (!ctx.FROM().isEmpty() || !ctx.TEXT().isEmpty() || !ctx.BINARY().isEmpty()) {
checkHasMandatoryOptions(ctx.LENGTH(), ctx, "LENGTH");
}
if (!ctx.LENGTH().isEmpty()) {
checkHasExactlyOneOption("FROM, TEXT or BINARY", ctx, ctx.FROM(), ctx.TEXT(), ctx.BINARY());
}
checkHasMutuallyExclusiveOptions("FROM, TEXT or BINARY", ctx.FROM(), ctx.TEXT(), ctx.BINARY());
checkHasExactlyOneOption("LENGTH, SYMBOL, TEMPLATE, FROMDOC or BOOKMARK", ctx,
ctx.LENGTH(), ctx.SYMBOL(), ctx.TEMPLATE(), ctx.FROMDOC(), ctx.BOOKMARK());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public <E extends ParserRuleContext> void checkOptions(E ctx) {
private void checkResetbr(CICSParser.Cics_resetbr_optionsContext ctx) {
checkHasExactlyOneOption("FILE or DATASET", ctx, ctx.FILE(), ctx.DATASET());
checkHasMandatoryOptions(ctx.RIDFLD(), ctx, "RIDFLD");
checkHasMutuallyExclusiveOptions("RBA, RRN, or XRBA", ctx.RBA(), ctx.RRN(), ctx.XRBA());
checkHasMutuallyExclusiveOptions("RBA, RRN, XRBA or KEYLENGTH", ctx.RBA(), ctx.RRN(), ctx.XRBA(), ctx.KEYLENGTH());
checkHasMutuallyExclusiveOptions("GTEQ or EQUAL", ctx.GTEQ(), ctx.EQUAL());
checkPrerequisiteIsMet(ctx.KEYLENGTH(), ctx.GENERIC(), ctx, "GENERIC");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ public <E extends ParserRuleContext> void checkOptions(E ctx) {
private void checkWSAContextBuild(CICSParser.Cics_wsacontext_buildContext ctx) {
checkHasMandatoryOptions(ctx.BUILD(), ctx, "BUILD");
checkPrerequisiteIsMet(ctx.RELATESURI(), ctx.RELATESTYPE(), ctx, "RELATESTYPE");
checkAllOptionsArePresentOrAbsent("EPRTYPE, EPRFIELD, EPRFROM and EPRLENGTH", ctx,
ctx.EPRTYPE(), ctx.EPRFIELD(), ctx.EPRFROM(), ctx.EPRLENGTH());
checkAllOptionsArePresentOrAbsent("EPRTYPE, EPRFIELD and EPRFROM", ctx,
ctx.EPRTYPE(), ctx.EPRFIELD(), ctx.EPRFROM());
if (!ctx.EPRLENGTH().isEmpty()) {
checkHasMandatoryOptions(ctx.EPRTYPE(), ctx, "EPRTYPE");
}
checkHasMutuallyExclusiveOptions("FROMCCSID or FROMCODEPAGE", ctx.FROMCCSID(), ctx.FROMCODEPAGE());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class TestCICSDocument {
private static final String DOCUMENT_CREATE_INVALID_MULTIPLE_SOURCES =
"DOCUMENT CREATE DOCTOKEN({$varOne}) {FROM|errorOne}({$varTwo}) {TEXT|errorTwo}({$varThree}) LENGTH({$varFour})";

private static final String DOCUMENT_CREATE_INVALID_NO_LENGTH =
"DOCUMENT {_CREATE DOCTOKEN({$varOne}) FROM({$varTwo})|errorOne_}";

private static final String DOCUMENT_DELETE_VALID =
"DOCUMENT DELETE DOCTOKEN({$varOne})";

Expand All @@ -47,6 +50,9 @@ public class TestCICSDocument {
private static final String DOCUMENT_INSERT_VALID =
"DOCUMENT INSERT DOCTOKEN({$varOne}) TEXT({$varTwo}) LENGTH({$varThree})";

private static final String DOCUMENT_INSERT_INVALID =
"DOCUMENT {_INSERT DOCTOKEN({$varOne}) LENGTH({$varTwo})|errorOne_}";

private static final String DOCUMENT_INSERT_INVALID_NO_DOCTOKEN =
"DOCUMENT {_INSERT TEXT({$varTwo}) LENGTH(123)|errorOne_}";

Expand Down Expand Up @@ -108,6 +114,19 @@ void testDocumentCreateInvalidMultipleSources() {
ErrorSource.PARSING.getText())));
}

@Test
void testDocumentCreateInvalidNoLength() {
CICSTestUtils.errorTest(
DOCUMENT_CREATE_INVALID_NO_LENGTH,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Missing required option: LENGTH",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testDocumentDeleteValid() {
CICSTestUtils.noErrorTest(DOCUMENT_DELETE_VALID);
Expand All @@ -131,6 +150,19 @@ void testDocumentInsertValid() {
CICSTestUtils.noErrorTest(DOCUMENT_INSERT_VALID);
}

@Test
void testDocumentInsertInvalid() {
CICSTestUtils.errorTest(
DOCUMENT_INSERT_INVALID,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Exactly one option required, none provided: FROM, TEXT or BINARY",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testDocumentInsertInvalidNoDoctoken() {
CICSTestUtils.errorTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class TestCICSResetbr {
"RESETBR FILE({$varOne}) RIDFLD({$varTwo})";

private static final String RESETBR_VALID_FULL =
"RESETBR FILE({$varOne}) RIDFLD({$varTwo}) KEYLENGTH({$varThree}) GENERIC REQID({$varFour}) SYSID({$varFive}) GTEQ RBA";
"RESETBR FILE({$varOne}) RIDFLD({$varTwo}) KEYLENGTH({$varThree}) GENERIC REQID({$varFour}) SYSID({$varFive}) GTEQ";

private static final String RESETBR_INVALID_FULL =
"RESETBR FILE({$varOne}) RIDFLD({$varTwo}) {KEYLENGTH|errorOne}({$varThree}) GENERIC REQID({$varFour}) SYSID({$varFive}) GTEQ {RBA|errorTwo}";

private static final String RESETBR_INVALID_NO_FILE =
"RESETBR {_RIDFLD({$varOne}) REQID({$varTwo}) EQUAL|errorOne_}";
Expand All @@ -60,6 +63,25 @@ void testResetbrValidFull() {
CICSTestUtils.noErrorTest(RESETBR_VALID_FULL);
}

@Test
void testResetbrInvalidFull() {
CICSTestUtils.errorTest(
RESETBR_INVALID_FULL,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Exactly one option required, options are mutually exclusive: RBA, RRN, XRBA or KEYLENGTH",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()),
"errorTwo",
new Diagnostic(
new Range(),
"Exactly one option required, options are mutually exclusive: RBA, RRN, XRBA or KEYLENGTH",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testResetbrInvalidNoFile() {
CICSTestUtils.errorTest(
Expand Down Expand Up @@ -107,13 +129,13 @@ void testResetbrInvalidMultipleRbaRrn() {
"errorOne",
new Diagnostic(
new Range(),
"Exactly one option required, options are mutually exclusive: RBA, RRN, or XRBA",
"Exactly one option required, options are mutually exclusive: RBA, RRN, XRBA or KEYLENGTH",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()),
"errorTwo",
new Diagnostic(
new Range(),
"Exactly one option required, options are mutually exclusive: RBA, RRN, or XRBA",
"Exactly one option required, options are mutually exclusive: RBA, RRN, XRBA or KEYLENGTH",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public class TestCICSWSAContext {
"WSACONTEXT BUILD RELATESURI({$varOne}) RELATESTYPE({$varTwo}) {FROMCCSID|errorOne}({$varOne}) {FROMCODEPAGE|errorTwo}({$varTwo})";

private static final String WSACONTEXT_BUILD_INVALID_TWO =
"WSACONTEXT {_BUILD EPRTYPE({$varOne}) EPRFIELD({$varTwo}) EPRFROM({123})|errorOne_}";
"WSACONTEXT {_BUILD EPRTYPE({$varOne}) EPRFIELD({$varTwo})|errorOne_}";

private static final String WSACONTEXT_BUILD_INVALID_THREE =
"WSACONTEXT {_BUILD EPRLENGTH({$varTwo})|errorOne_}";

private static final String WSACONTEXT_DELETE_VALID =
"WSACONTEXT DELETE CHANNEL({$varOne})";
Expand Down Expand Up @@ -105,7 +108,20 @@ void testWSAContextBuildInvalidTwo() {
"errorOne",
new Diagnostic(
new Range(),
"If one option is specified, all options must be present: EPRTYPE, EPRFIELD, EPRFROM and EPRLENGTH",
"If one option is specified, all options must be present: EPRTYPE, EPRFIELD and EPRFROM",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testWSAContextBuildInvalidThree() {
CICSTestUtils.errorTest(
WSACONTEXT_BUILD_INVALID_THREE,
ImmutableMap.of(
"errorOne",
new Diagnostic(
new Range(),
"Missing required option: EPRTYPE",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}
Expand Down

0 comments on commit 9c2a4a4

Please sign in to comment.