Skip to content

fix: TEST EVENT options #2624

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
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -145,8 +145,11 @@ public CICSOptionsCheckUtility(DialectProcessingContext context, List<SyntaxErro
CICSWSAEPRUtility.RULE_INDEX,
new CICSWSAEPRUtility(context, errors));
optionsMap.put(
CICSWaitCicsOptionsUtility.RULE_INDEX,
new CICSWaitCicsOptionsUtility(context, errors));
CICSWaitCicsOptionsUtility.RULE_INDEX,
new CICSWaitCicsOptionsUtility(context, errors));
optionsMap.put(
CICSTestOptionsUtility.RULE_INDEX,
new CICSTestOptionsUtility(context, errors));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2024 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 org.eclipse.lsp.cobol.implicitDialects.cics.utility;

import org.antlr.v4.runtime.ParserRuleContext;
import org.eclipse.lsp.cobol.common.dialects.DialectProcessingContext;
import org.eclipse.lsp.cobol.common.error.ErrorSeverity;
import org.eclipse.lsp.cobol.common.error.SyntaxError;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSLexer;
import org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser;

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

import static org.eclipse.lsp.cobol.implicitDialects.cics.CICSParser.RULE_cics_test;

/** Checks CICS TEST EVENT rules for required and invalid options */
public class CICSTestOptionsUtility extends CICSOptionsCheckBaseUtility {

public static final int RULE_INDEX = RULE_cics_test;

private static final Map<Integer, ErrorSeverity> DUPLICATE_CHECK_OPTIONS =
new HashMap<Integer, ErrorSeverity>() {
{
put(CICSLexer.TEST, ErrorSeverity.ERROR);
put(CICSLexer.EVENT, ErrorSeverity.ERROR);
put(CICSLexer.FIRESTATUS, ErrorSeverity.ERROR);
}
};

public CICSTestOptionsUtility(DialectProcessingContext context, List<SyntaxError> errors) {
super(context, errors, DUPLICATE_CHECK_OPTIONS);
}

/**
* Entrypoint to check CICS TEST EVENT rule options
*
* @param ctx ParserRuleContext subclass containing options
* @param <E> A subclass of ParserRuleContext
*/
public <E extends ParserRuleContext> void checkOptions(E ctx) {
if (ctx.getParent().getRuleIndex() == CICSParser.RULE_cics_test) {
checkTestEvent((CICSParser.Cics_testContext) ctx.getParent());
}
checkDuplicates(ctx.getParent());
}

private void checkTestEvent(CICSParser.Cics_testContext ctx) {
checkHasMandatoryOptions(ctx.EVENT(), ctx, "EVENT");
checkHasMandatoryOptions(ctx.FIRESTATUS(), ctx, "FIRESTATUS");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2024 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 org.eclipse.lsp.cobol.usecases;

import com.google.common.collect.ImmutableMap;
import org.eclipse.lsp.cobol.common.error.ErrorSource;
import org.eclipse.lsp.cobol.usecases.common.CICSTestUtils;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.junit.jupiter.api.Test;

/**
* Test CICS TEST EVENT command. Documentation link: <a
* href="https://www.ibm.com/docs/en/cics-ts/6.x?topic=summary-test-event">TEST EVENT
* Command</a>
*
* <p>This class tests all variations of the TEST EVENT command found in the link above.
*/
public class TestCicsTest {
private static final String TEST_EVENT_VALID_ONE = "TEST EVENT({$varOne}) FIRESTATUS({$varTwo})";
private static final String TEST_EVENT_VALID_TWO = "TEST FIRESTATUS({$varTwo}) EVENT({$varOne})";

private static final String TEST_EVENT_INVALID_ONE = "TEST {EVENT|error1}({$varOne})";
private static final String TEST_EVENT_INVALID_TWO = "TEST {FIRESTATUS|error1}({$varTwo})";


@Test
void testCicsTestValidOne() {
CICSTestUtils.noErrorTest(TEST_EVENT_VALID_ONE);
}

@Test
void testCicsTestValidTwo() {
CICSTestUtils.noErrorTest(TEST_EVENT_VALID_TWO);
}

@Test
void testCicsTestInvalidOne() {
CICSTestUtils.errorTest(TEST_EVENT_INVALID_ONE,
ImmutableMap.of(
"error1",
new Diagnostic(
new Range(new Position(12, 12), new Position(13, 25)),
"Missing required option: FIRESTATUS",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}

@Test
void testCicsTestInvalidTwo() {
CICSTestUtils.errorTest(TEST_EVENT_INVALID_TWO,
ImmutableMap.of(
"error1",
new Diagnostic(
new Range(new Position(12, 12), new Position(13, 30)),
"Missing required option: EVENT",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText())));
}
}
Loading