diff --git a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSDocumentOptionsCheckUtility.java b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSDocumentOptionsCheckUtility.java index c43a02cf74..58ef8bc225 100644 --- a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSDocumentOptionsCheckUtility.java +++ b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSDocumentOptionsCheckUtility.java @@ -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()) { @@ -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()); diff --git a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSResetbrOptionsCheckUtility.java b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSResetbrOptionsCheckUtility.java index 5c50f846d4..a2c7770d5a 100644 --- a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSResetbrOptionsCheckUtility.java +++ b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSResetbrOptionsCheckUtility.java @@ -70,7 +70,7 @@ public 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"); } diff --git a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSWSAContextOptionsCheckUtility.java b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSWSAContextOptionsCheckUtility.java index 13f3b4fa79..7454538125 100644 --- a/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSWSAContextOptionsCheckUtility.java +++ b/server/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/cics/utility/CICSWSAContextOptionsCheckUtility.java @@ -89,8 +89,11 @@ public 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()); } diff --git a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSDocument.java b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSDocument.java index 1489324c53..2d443e732c 100644 --- a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSDocument.java +++ b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSDocument.java @@ -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})"; @@ -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_}"; @@ -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); @@ -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( diff --git a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSResetbr.java b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSResetbr.java index 08541e3542..a5784e53e9 100644 --- a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSResetbr.java +++ b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSResetbr.java @@ -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_}"; @@ -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( @@ -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()))); } diff --git a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSWSAContext.java b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSWSAContext.java index 36374f2867..c00b0f1401 100644 --- a/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSWSAContext.java +++ b/server/engine/src/test/java/org/eclipse/lsp/cobol/usecases/TestCICSWSAContext.java @@ -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})"; @@ -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()))); }