Skip to content

Commit 402b338

Browse files
committed
Add tests for excluded snippets
1 parent 735372e commit 402b338

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

extensions/ql-vscode/test/pure-tests/sarif-processing.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,43 @@ describe("SARIF processing", () => {
637637
expect(message.tokens[2].t).toBe("text");
638638
expect(message.tokens[2].text).toBe(".");
639639
});
640+
641+
it("should not include snippets for large snippets", () => {
642+
const sarif = buildValidSarifLog();
643+
// Build string of 10 kilobytes
644+
const snippet = new Array(10 * 1024).fill("a").join("");
645+
sarif.runs![0]!.results![0]!.locations![0]!.physicalLocation!.contextRegion!.snippet =
646+
{
647+
text: snippet,
648+
};
649+
650+
const result = extractAnalysisAlerts(sarif, fakefileLinkPrefix);
651+
652+
const actualCodeSnippet = result.alerts[0].codeSnippet;
653+
654+
expect(result).toBeTruthy();
655+
expectNoParsingError(result);
656+
expect(actualCodeSnippet).toBeUndefined();
657+
});
658+
659+
it("should include snippets for large snippets which are relevant", () => {
660+
const sarif = buildValidSarifLog();
661+
// Build string of 10 kilobytes
662+
const snippet = new Array(10 * 1024).fill("a").join("");
663+
sarif.runs![0]!.results![0]!.locations![0]!.physicalLocation!.contextRegion!.snippet =
664+
{
665+
text: snippet,
666+
};
667+
sarif.runs![0]!.results![0]!.locations![0]!.physicalLocation!.region!.endColumn = 1000;
668+
669+
const result = extractAnalysisAlerts(sarif, fakefileLinkPrefix);
670+
671+
const actualCodeSnippet = result.alerts[0].codeSnippet;
672+
673+
expect(result).toBeTruthy();
674+
expectNoParsingError(result);
675+
expect(actualCodeSnippet).not.toBeUndefined();
676+
});
640677
});
641678

642679
function expectResultParsingError(msg: string) {

0 commit comments

Comments
 (0)