mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-08 00:45:54 +00:00
32 lines
1.6 KiB
TypeScript
32 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
import { isVirtualUri, virtualContainer, virtualName, virtualParent } from "./virtualDocs";
|
||
import { basename, dirname, relativeDir, relativePath } from "./project";
|
||
|
||
const JDT =
|
||
"jdt://contents/spring-boot-4.1.1.jar/org.springframework.boot/SpringApplication.class?=demo/%5C/m2%5C/spring-boot-4.1.1.jar%3Corg.springframework.boot%28SpringApplication.class";
|
||
|
||
describe("virtual document URIs", () => {
|
||
it("tells URIs from file paths", () => {
|
||
expect(isVirtualUri(JDT)).toBe(true);
|
||
expect(isVirtualUri("untitled:Untitled-1")).toBe(true);
|
||
expect(isVirtualUri("/Users/me/a.java")).toBe(false);
|
||
expect(isVirtualUri("C:\\src\\a.java")).toBe(false);
|
||
expect(isVirtualUri("file:///a.java")).toBe(false);
|
||
expect(isVirtualUri(null)).toBe(false);
|
||
});
|
||
|
||
it("names and locates library classes", () => {
|
||
expect(virtualName(JDT)).toBe("SpringApplication.class");
|
||
expect(virtualParent(JDT)).toBe("jdt://contents/spring-boot-4.1.1.jar/org.springframework.boot");
|
||
expect(virtualContainer(JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot");
|
||
});
|
||
|
||
it("makes path helpers URI-aware", () => {
|
||
expect(basename(JDT)).toBe("SpringApplication.class");
|
||
expect(basename(dirname(JDT))).toBe("org.springframework.boot");
|
||
expect(relativePath("/p", JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot › SpringApplication.class");
|
||
expect(relativeDir("/p", JDT)).toBe("spring-boot-4.1.1.jar › org.springframework.boot");
|
||
expect(relativePath("/p", "/p/src/A.java")).toBe("src/A.java");
|
||
});
|
||
});
|