Do not use mocked URI in locations test

This commit is contained in:
Koen Vlaswinkel
2023-07-27 09:40:37 +02:00
parent db065584fa
commit bebe130fb0

View File

@@ -3,23 +3,29 @@ import { mockDatabaseItem } from "../../../utils/mocking.helpers";
import { tryResolveLocation } from "../../../../../src/databases/local-databases/locations";
describe("tryResolveLocation", () => {
const resolveSourceFile = jest.fn();
const databaseItem = mockDatabaseItem({
resolveSourceFile,
});
beforeEach(() => {
resolveSourceFile.mockReturnValue(Uri.file("abc"));
});
it("should resolve a whole file location", () => {
const databaseItem = mockDatabaseItem();
expect(tryResolveLocation("file://hucairz:0:0:0:0", databaseItem)).toEqual(
new Location(Uri.file("abc"), new Range(0, 0, 0, 0)),
);
});
it("should resolve a five-part location edge case", () => {
const databaseItem = mockDatabaseItem();
expect(tryResolveLocation("file://hucairz:1:1:1:1", databaseItem)).toEqual(
new Location(Uri.file("abc"), new Range(0, 0, 0, 1)),
);
});
it("should resolve a five-part location", () => {
const databaseItem = mockDatabaseItem();
expect(
tryResolveLocation(
{
@@ -33,7 +39,7 @@ describe("tryResolveLocation", () => {
),
).toEqual(
new Location(
Uri.parse("abc"),
Uri.file("abc"),
new Range(new Position(4, 3), new Position(3, 0)),
),
);
@@ -42,8 +48,6 @@ describe("tryResolveLocation", () => {
});
it("should resolve a five-part location with an empty path", () => {
const databaseItem = mockDatabaseItem();
expect(
tryResolveLocation(
{
@@ -59,21 +63,17 @@ describe("tryResolveLocation", () => {
});
it("should resolve a string location for whole file", () => {
const databaseItem = mockDatabaseItem();
expect(tryResolveLocation("file://hucairz:0:0:0:0", databaseItem)).toEqual(
new Location(Uri.parse("abc"), new Range(0, 0, 0, 0)),
new Location(Uri.file("abc"), new Range(0, 0, 0, 0)),
);
expect(databaseItem.resolveSourceFile).toHaveBeenCalledTimes(1);
expect(databaseItem.resolveSourceFile).toHaveBeenCalledWith("hucairz");
});
it("should resolve a string location for five-part location", () => {
const databaseItem = mockDatabaseItem();
expect(tryResolveLocation("file://hucairz:5:4:3:2", databaseItem)).toEqual(
new Location(
Uri.parse("abc"),
Uri.file("abc"),
new Range(new Position(4, 3), new Position(2, 2)),
),
);
@@ -82,8 +82,6 @@ describe("tryResolveLocation", () => {
});
it("should resolve a string location for invalid string", () => {
const databaseItem = mockDatabaseItem();
expect(
tryResolveLocation("file://hucairz:x:y:z:a", databaseItem),
).toBeUndefined();