Skip to content

Commit

Permalink
Add parser setup functions and tests for source files
Browse files Browse the repository at this point in the history
Signed-off-by: worksofliam <[email protected]>
  • Loading branch information
worksofliam committed Dec 6, 2024
1 parent bda3061 commit b241c0c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/parserSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,15 @@ export default function setupParser(): Parser {
});

return parser;
}

export function getSourcesList(): string[] {
return glob.sync(`**/*.*`, {
cwd: path.join(includeDir, `sources`),
nocase: true,
});
}

export function getSourcesContent(name: string) {
return readFile(path.join(includeDir, `sources`, name), { encoding: `utf-8` });
}
1 change: 1 addition & 0 deletions tests/sources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p*.*
9 changes: 9 additions & 0 deletions tests/sources/hello.pgm.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
**free

dcl-s text char(20);

text = 'Hello, world!';

dsply text;

return;
32 changes: 32 additions & 0 deletions tests/suite/sources.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import setupParser, { getSourcesContent, getSourcesList } from "../parserSetup";
import { test, expect, describe } from "vitest";
import path from "path";

const parser = setupParser();

// The purpose of this file is to test the parser against all the sources in the sources directory to ensure it doesn't crash.

test("Source Directory Tests", async () => {
const list = await getSourcesList();

for (const source of list) {
const basename = path.basename(source);
const baseContent = await getSourcesContent(source);

// These are typing tests. Can the parser accept half documents without crashing?

let content = ``;

let baseContentSplitUpIntoPieces = [];
const pieceSize = Math.ceil(baseContent.length / 20);
for (let i = 0; i < baseContent.length; i += pieceSize) {
baseContentSplitUpIntoPieces.push(baseContent.slice(i, i + pieceSize));
}

for (let i = 0; i < baseContentSplitUpIntoPieces.length; i++) {
content += baseContentSplitUpIntoPieces[i];

await parser.getDocs(basename, content, {collectReferences: true, ignoreCache: true, withIncludes: true});
}
}
});

0 comments on commit b241c0c

Please sign in to comment.