Skip to content

Commit 633edff

Browse files
committed
fix: test (path convert)
1 parent 6840575 commit 633edff

File tree

1 file changed

+81
-9
lines changed

1 file changed

+81
-9
lines changed

test/adapters/call-hierarchy-adapter.test.ts

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { createSpyConnection, createFakeEditor } from "../helpers.js"
44
import { Point, Range } from "atom"
55
import type { TextEditor } from "atom"
66

7+
const setProcessPlatform = (platform: any) => {
8+
Object.defineProperty(process, "platform", { value: platform })
9+
}
10+
711
const callHierarchyItem: ls.CallHierarchyItem = {
812
name: "hello",
913
kind: 12,
1014
detail: "",
11-
uri: "file:///C:/path/to/file.ts",
15+
uri: "file:///path/to/file.ts",
1216
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 1 } },
1317
selectionRange: { start: { line: 0, character: 24 }, end: { line: 0, character: 29 } },
1418
}
@@ -17,6 +21,14 @@ const callHierarchyItemWithTags: ls.CallHierarchyItem = {
1721
kind: 12,
1822
tags: [1],
1923
detail: "",
24+
uri: "file:///path/to/file.ts",
25+
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 1 } },
26+
selectionRange: { start: { line: 0, character: 24 }, end: { line: 0, character: 29 } },
27+
}
28+
const callHierarchyItemInWin32: ls.CallHierarchyItem = {
29+
name: "hello",
30+
kind: 12,
31+
detail: "",
2032
uri: "file:///C:/path/to/file.ts",
2133
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 1 } },
2234
selectionRange: { start: { line: 0, character: 24 }, end: { line: 0, character: 29 } },
@@ -52,7 +64,7 @@ describe("OutlineViewAdapter", () => {
5264
expect(result.type).toEqual("incoming")
5365
expect(result.data).toEqual([
5466
{
55-
path: "C:\\path\\to\\file.ts",
67+
path: jasmine.anything(),
5668
name: "hello",
5769
icon: "type-function",
5870
tags: [],
@@ -71,7 +83,7 @@ describe("OutlineViewAdapter", () => {
7183
expect(result.type).toEqual("incoming")
7284
expect(result.data).toEqual([
7385
{
74-
path: "C:\\path\\to\\file.ts",
86+
path: jasmine.anything(),
7587
name: "hello",
7688
icon: "type-function",
7789
tags: ["deprecated"],
@@ -112,7 +124,7 @@ describe("OutlineViewAdapter", () => {
112124
expect((await result.itemAt(0)).type).toEqual("incoming")
113125
expect((await result.itemAt(0)).data).toEqual([
114126
{
115-
path: "C:\\path\\to\\file.ts",
127+
path: jasmine.anything(),
116128
name: "hello",
117129
icon: "type-function",
118130
tags: [],
@@ -125,7 +137,7 @@ describe("OutlineViewAdapter", () => {
125137
expect((await (await result.itemAt(0)).itemAt(0)).type).toEqual("incoming")
126138
expect((await (await result.itemAt(0)).itemAt(0)).data).toEqual([
127139
{
128-
path: "C:\\path\\to\\file.ts",
140+
path: jasmine.anything(),
129141
name: "hello",
130142
icon: "type-function",
131143
tags: [],
@@ -150,7 +162,7 @@ describe("OutlineViewAdapter", () => {
150162
expect((await result.itemAt(0)).type).toEqual("outgoing")
151163
expect((await result.itemAt(0)).data).toEqual([
152164
{
153-
path: "C:\\path\\to\\file.ts",
165+
path: jasmine.anything(),
154166
name: "hello",
155167
icon: "type-function",
156168
tags: [],
@@ -163,7 +175,7 @@ describe("OutlineViewAdapter", () => {
163175
expect((await (await result.itemAt(0)).itemAt(0)).type).toEqual("outgoing")
164176
expect((await (await result.itemAt(0)).itemAt(0)).data).toEqual([
165177
{
166-
path: "C:\\path\\to\\file.ts",
178+
path: jasmine.anything(),
167179
name: "hello",
168180
icon: "type-function",
169181
tags: [],
@@ -174,6 +186,22 @@ describe("OutlineViewAdapter", () => {
174186
},
175187
])
176188
})
189+
it("convert paths in darwin", async () => {
190+
setProcessPlatform("darwin")
191+
spyOn(connection, "prepareCallHierarchy").and.resolveTo([callHierarchyItem])
192+
const result = <any>(
193+
await new CallHierarchyAdapter().getCallHierarchy(connection, fakeEditor, new Point(0, 0), "outgoing")
194+
)
195+
expect(result.data[0].path).toEqual("/path/to/file.ts")
196+
})
197+
it("convert paths in win32", async () => {
198+
setProcessPlatform("win32")
199+
spyOn(connection, "prepareCallHierarchy").and.resolveTo([callHierarchyItemInWin32])
200+
const result = <any>(
201+
await new CallHierarchyAdapter().getCallHierarchy(connection, fakeEditor, new Point(0, 0), "outgoing")
202+
)
203+
expect(result.data[0].path).toEqual("C:\\path\\to\\file.ts")
204+
})
177205
})
178206

179207
describe("getIncoming", () => {
@@ -188,7 +216,7 @@ describe("OutlineViewAdapter", () => {
188216
expect(result.type).toEqual("incoming")
189217
expect(result.data).toEqual([
190218
{
191-
path: "C:\\path\\to\\file.ts",
219+
path: jasmine.anything(),
192220
name: "hello",
193221
icon: "type-function",
194222
tags: [],
@@ -211,6 +239,28 @@ describe("OutlineViewAdapter", () => {
211239
expect(result.type).toEqual("incoming")
212240
expect(result.data).toEqual([])
213241
})
242+
it("convert paths in darwin", async () => {
243+
setProcessPlatform("darwin")
244+
spyOn(connection, "callHierarchyIncomingCalls").and.resolveTo([
245+
{
246+
from: callHierarchyItem,
247+
fromRanges: [],
248+
},
249+
])
250+
const result = <any>await new CallHierarchyAdapter().getIncoming(connection, callHierarchyItem)
251+
expect(result.data[0].path).toEqual("/path/to/file.ts")
252+
})
253+
it("convert paths in win32", async () => {
254+
setProcessPlatform("win32")
255+
spyOn(connection, "callHierarchyIncomingCalls").and.resolveTo([
256+
{
257+
from: callHierarchyItemInWin32,
258+
fromRanges: [],
259+
},
260+
])
261+
const result = <any>await new CallHierarchyAdapter().getIncoming(connection, callHierarchyItem)
262+
expect(result.data[0].path).toEqual("C:\\path\\to\\file.ts")
263+
})
214264
})
215265

216266
describe("getOutgoing", () => {
@@ -225,7 +275,7 @@ describe("OutlineViewAdapter", () => {
225275
expect(result.type).toEqual("outgoing")
226276
expect(result.data).toEqual([
227277
{
228-
path: "C:\\path\\to\\file.ts",
278+
path: jasmine.anything(),
229279
name: "hello",
230280
icon: "type-function",
231281
tags: [],
@@ -248,5 +298,27 @@ describe("OutlineViewAdapter", () => {
248298
expect(result.type).toEqual("outgoing")
249299
expect(result.data).toEqual([])
250300
})
301+
it("convert paths in darwin", async () => {
302+
setProcessPlatform("darwin")
303+
spyOn(connection, "callHierarchyOutgoingCalls").and.resolveTo([
304+
{
305+
to: callHierarchyItem,
306+
fromRanges: [],
307+
},
308+
])
309+
const result = <any>await new CallHierarchyAdapter().getOutgoing(connection, callHierarchyItem)
310+
expect(result.data[0].path).toEqual("/path/to/file.ts")
311+
})
312+
it("convert paths in win32", async () => {
313+
setProcessPlatform("win32")
314+
spyOn(connection, "callHierarchyOutgoingCalls").and.resolveTo([
315+
{
316+
to: callHierarchyItemInWin32,
317+
fromRanges: [],
318+
},
319+
])
320+
const result = <any>await new CallHierarchyAdapter().getOutgoing(connection, callHierarchyItem)
321+
expect(result.data[0].path).toEqual("C:\\path\\to\\file.ts")
322+
})
251323
})
252324
})

0 commit comments

Comments
 (0)