Skip to content

Commit ecfa701

Browse files
Add tests of tryGetFilePath
1 parent a3a6784 commit ecfa701

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

extensions/ql-vscode/src/variant-analysis/sarif-processing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export function tryGetRule(
168168
return undefined;
169169
}
170170

171-
function tryGetFilePath(
171+
export function tryGetFilePath(
172172
physicalLocation: sarif.PhysicalLocation,
173173
): string | undefined {
174174
const filePath = physicalLocation.artifactLocation?.uri;

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as sarif from "sarif";
22
import {
33
extractAnalysisAlerts,
4+
tryGetFilePath,
45
tryGetRule,
56
tryGetSeverity,
67
} from "../../src/variant-analysis/sarif-processing";
@@ -288,6 +289,51 @@ describe("SARIF processing", () => {
288289
});
289290
});
290291

292+
describe("tryGetFilePath", () => {
293+
it("should return value when uri is a file path", () => {
294+
const physicalLocation: sarif.PhysicalLocation = {
295+
artifactLocation: {
296+
uri: "foo/bar",
297+
},
298+
};
299+
expect(tryGetFilePath(physicalLocation)).toBe("foo/bar");
300+
});
301+
302+
it("should return undefined when uri has a file scheme", () => {
303+
const physicalLocation: sarif.PhysicalLocation = {
304+
artifactLocation: {
305+
uri: "file:/",
306+
},
307+
};
308+
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
309+
});
310+
311+
it("should return undefined when uri is empty", () => {
312+
const physicalLocation: sarif.PhysicalLocation = {
313+
artifactLocation: {
314+
uri: "",
315+
},
316+
};
317+
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
318+
});
319+
320+
it("should return undefined if artifact location uri is undefined", () => {
321+
const physicalLocation: sarif.PhysicalLocation = {
322+
artifactLocation: {
323+
uri: undefined,
324+
},
325+
};
326+
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
327+
});
328+
329+
it("should return undefined if artifact location is undefined", () => {
330+
const physicalLocation: sarif.PhysicalLocation = {
331+
artifactLocation: undefined,
332+
};
333+
expect(tryGetFilePath(physicalLocation)).toBe(undefined);
334+
});
335+
});
336+
291337
describe("tryGetSeverity", () => {
292338
it("should return undefined if no rule set", () => {
293339
const result = {

0 commit comments

Comments
 (0)