|
| 1 | +/* |
| 2 | + * Copyright (c) 2023 Broadcom. |
| 3 | + * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. |
| 4 | + * |
| 5 | + * This program and the accompanying materials are made |
| 6 | + * available under the terms of the Eclipse Public License 2.0 |
| 7 | + * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Broadcom, Inc. - initial API and implementation |
| 13 | + * |
| 14 | + */ |
| 15 | +package org.eclipse.lsp.cobol.usecases; |
| 16 | + |
| 17 | +import com.google.common.collect.ImmutableList; |
| 18 | +import com.google.common.collect.ImmutableMap; |
| 19 | +import org.eclipse.lsp.cobol.common.error.ErrorSource; |
| 20 | +import org.eclipse.lsp.cobol.test.engine.UseCaseEngine; |
| 21 | +import org.eclipse.lsp4j.Diagnostic; |
| 22 | +import org.eclipse.lsp4j.DiagnosticSeverity; |
| 23 | +import org.eclipse.lsp4j.Range; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +/** Test that tokens are not skipped for embedded language. */ |
| 27 | +public class TestEmbeddedCodeWithIssueOnLastToken { |
| 28 | + private static final String ISSUE_1 = " :testing,{|1}\n" + " END-EXEC."; |
| 29 | + |
| 30 | + private static final String ISSUE_2 = " :{$testing}({|1}\n" + " END-EXEC."; |
| 31 | + |
| 32 | + private static final String NO_ISSUE = " :{$testing}\n" + " END-EXEC."; |
| 33 | + |
| 34 | + public static final String TEXT = |
| 35 | + " IDENTIFICATION DIVISION.\n" |
| 36 | + + " PROGRAM-ID. TEST12.\n" |
| 37 | + + " ENVIRONMENT DIVISION.\n" |
| 38 | + + " DATA DIVISION.\n" |
| 39 | + + " WORKING-STORAGE SECTION.\n" |
| 40 | + + " 01 {$*testing} pic x.\n" |
| 41 | + + " PROCEDURE DIVISION.\n" |
| 42 | + + " EXEC SQL \n" |
| 43 | + + " fetch abc \n" |
| 44 | + + " into \n" |
| 45 | + + " asas,\n" |
| 46 | + + " ajsjs, \n"; |
| 47 | + |
| 48 | + @Test |
| 49 | + void testCobolParserDontEatEmbeddedToken() { |
| 50 | + UseCaseEngine.runTest( |
| 51 | + TEXT + ISSUE_1, |
| 52 | + ImmutableList.of(), |
| 53 | + ImmutableMap.of( |
| 54 | + "1", |
| 55 | + new Diagnostic( |
| 56 | + new Range(), |
| 57 | + "No viable alternative at input abc\n into\n asas, \n ajsjs, \n :testing,", |
| 58 | + DiagnosticSeverity.Error, |
| 59 | + ErrorSource.PARSING.getText()))); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + void testEmbeddedTokensAreFullyMatchedAgainstEmbeddedParserRule() { |
| 64 | + UseCaseEngine.runTest( |
| 65 | + TEXT + ISSUE_2, |
| 66 | + ImmutableList.of(), |
| 67 | + ImmutableMap.of( |
| 68 | + "1", |
| 69 | + new Diagnostic( |
| 70 | + new Range(), |
| 71 | + "No viable alternative at input (", |
| 72 | + DiagnosticSeverity.Error, |
| 73 | + ErrorSource.PARSING.getText()))); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void testPositiveScenario() { |
| 78 | + UseCaseEngine.runTest(TEXT + NO_ISSUE, ImmutableList.of(), ImmutableMap.of()); |
| 79 | + } |
| 80 | +} |
0 commit comments