-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathfile-range-from-uri.test.ts
More file actions
102 lines (94 loc) · 2.63 KB
/
file-range-from-uri.test.ts
File metadata and controls
102 lines (94 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { Uri, Range } from "vscode";
import type { DatabaseItem } from "../../../../../src/databases/local-databases";
import type {
BqrsWholeFileLocation,
BqrsLineColumnLocation,
} from "../../../../../src/common/bqrs-cli-types";
import { mockDatabaseItem } from "../../../utils/mocking.helpers";
import { fileRangeFromURI } from "../../../../../src/language-support";
describe("fileRangeFromURI", () => {
it("should return undefined when value is not a file URI", () => {
expect(
fileRangeFromURI("hucairz", createMockDatabaseItem()),
).toBeUndefined();
});
it("should fail to find a location when not a file URI and a full 5 part location", () => {
expect(
fileRangeFromURI(
{
uri: "https://yahoo.com",
startLine: 1,
startColumn: 2,
endLine: 3,
endColumn: 4,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
});
it("should fail to find a location when there is a silly protocol", () => {
expect(
fileRangeFromURI(
{
uri: "filesilly://yahoo.com",
startLine: 1,
startColumn: 2,
endLine: 3,
endColumn: 4,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
});
it("should return undefined when value is an empty uri", () => {
for (const fileUri of ["file:/", "file:///"]) {
expect(
fileRangeFromURI(
{
uri: fileUri,
startLine: 1,
startColumn: 2,
endLine: 3,
endColumn: 4,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toBeUndefined();
}
});
it("should return a range for a WholeFileLocation", () => {
expect(
fileRangeFromURI(
{
uri: "file:///hucairz",
} as BqrsWholeFileLocation,
createMockDatabaseItem(),
),
).toEqual({
uri: Uri.parse("file:///hucairz", true),
range: new Range(0, 0, 0, 0),
});
});
it("should return a range for a LineColumnLocation", () => {
expect(
fileRangeFromURI(
{
uri: "file:///hucairz",
startLine: 1,
startColumn: 2,
endLine: 3,
endColumn: 4,
} as BqrsLineColumnLocation,
createMockDatabaseItem(),
),
).toEqual({
uri: Uri.parse("file:///hucairz", true),
range: new Range(0, 1, 2, 4),
});
});
function createMockDatabaseItem(): DatabaseItem {
return mockDatabaseItem({
resolveSourceFile: (file: string) => Uri.parse(file),
});
}
});