Skip to content

Commit

Permalink
Merge branch 'Developer' into 174-mocked-sections-and-paragraphs-cann…
Browse files Browse the repository at this point in the history
…ot-handle-periods-in-bodies

Signed-off-by: Issac To <[email protected]>
  • Loading branch information
issacto authored Aug 7, 2023
2 parents 25c0fc0 + 847d2c4 commit dd85b22
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/test/java/org/openmainframeproject/cobolcheck/MockIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ public void it_inserts_call_mocks_correctly() throws IOException {

assertEquals(getTrimmedList(expected4), actual);
}
<<<<<<< HEAD

@Test
public void it_inserts_call_mocks_without_commas_correctly() throws IOException {
Expand Down Expand Up @@ -257,9 +256,6 @@ public void it_inserts_call_mocks_without_commas_correctly() throws IOException
assertEquals(getTrimmedList(expected4), actual);
}

=======

>>>>>>> modify tests for when other section
private List<String> getTrimmedList(String text){
String[] lines = text.split(Constants.NEWLINE);
List<String> result = new ArrayList<>();
Expand Down
10 changes: 4 additions & 6 deletions vs code extension/client/src/test/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ suite('Should get diagnostics', () => {
await testDiagnostics(docUriEF, []);
});

test('Reports missing delimiters', async () => {
await testDiagnostics(docUriMD, [
{ message: 'Unclosed END BEFORE', range: toRange(3, 11, 3, 21), severity: vscode.DiagnosticSeverity.Error, source: 'cut' },
{ message: 'Unclosed MOCK', range: toRange(5, 11, 5, 15), severity: vscode.DiagnosticSeverity.Error, source: 'cut' }
]);
});
test('Reports no error in missing delimiters file', async () => {
//expectedDiagnostics empty since there are no errors
await testDiagnostics(docUriMD, []);
});

test('Reports general syntax error', async () => {
await testDiagnostics(docUriSE, [
Expand Down
10 changes: 10 additions & 0 deletions vs code extension/client/testFixture/errorfree.cut
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@
MOCK SECTION 911-PUT-HARD-ERROR
CONTINUE
END-MOCK

MOCK PARAGRAPH 300-CHANGE-1
EVALUATE VALUE-1
WHEN "Hello"
MOVE "MOCKED" TO VALUE-1
WHEN OTHER
MOVE "mocked" TO VALUE-1
END-EVALUATE
END-MOCK


23 changes: 17 additions & 6 deletions vs code extension/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,24 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
let text = textDocument.getText();
let m: RegExpExecArray | null;

// Find unclosed delimiters of each type.
//TODO: Make regex exclude keywords inside quotes.
//TODO: Make regex' more efficient. Somewhat slow on large files.
const delimiters =
[[/(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)BEFORE EACH/, /(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)END-BEFORE/],
[/(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)(?<!END-)MOCK/, /(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)END-MOCK/],
[/(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)AFTER EACH/, /(?<!^[0-9]{6}\* *)(?=([^']*'[^']*')*[^']*$)END-AFTER/]];
type RegexPair = [RegExp, RegExp];

const sixDigitsFollowedByAsterisk = "(?<!^[0-9]{6}\\* *)";
const notInSingleQuotes = "(?=([^']*'[^']*')*[^']*$)";
const notInDoubleQuotes = "(?=([^\"']*\"[^\"']*')*[^\"']*$)";

const createRegexPair = (start: string, end: string): RegexPair => [
new RegExp(`${sixDigitsFollowedByAsterisk}${notInSingleQuotes}${notInDoubleQuotes}${start}`),
new RegExp(`${sixDigitsFollowedByAsterisk}${notInSingleQuotes}${notInDoubleQuotes}${end}`)
];

const delimiters: RegexPair[] = [
createRegexPair("BEFORE(-| )EACH", "END-BEFORE"),
createRegexPair("(?<!END-)MOCK", "END-MOCK"),
createRegexPair("AFTER(-| )EACH", "END-AFTER")
];

const delimitererrors = [];
let error;

Expand Down
2 changes: 1 addition & 1 deletion vs code extension/syntaxes/cut.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"comment": "Description keywords in unit tests"
},
{
"begin": "(?i:mock|after\\ each|before\\ each)",
"begin": "(?i:mock|after\\ each|after\\-each|before\\ each|before\\-each)",
"name": "constant.character.escape",
"patterns": [
{
Expand Down

0 comments on commit dd85b22

Please sign in to comment.