mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-10 07:18:10 -05:00
Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isLikelyDirectory } from "#/components/features/chat/path-component";
|
||||
|
||||
describe("isLikelyDirectory", () => {
|
||||
it("should return false for empty path", () => {
|
||||
expect(isLikelyDirectory("")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return true for paths ending with forward slash", () => {
|
||||
expect(isLikelyDirectory("/path/to/dir/")).toBe(true);
|
||||
expect(isLikelyDirectory("dir/")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for paths ending with backslash", () => {
|
||||
expect(isLikelyDirectory("C:\\path\\to\\dir\\")).toBe(true);
|
||||
expect(isLikelyDirectory("dir\\")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return true for paths without extension", () => {
|
||||
expect(isLikelyDirectory("/path/to/dir")).toBe(true);
|
||||
expect(isLikelyDirectory("dir")).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for paths ending with dot", () => {
|
||||
expect(isLikelyDirectory("/path/to/dir.")).toBe(false);
|
||||
expect(isLikelyDirectory("dir.")).toBe(false);
|
||||
});
|
||||
|
||||
it("should return false for paths with file extensions", () => {
|
||||
expect(isLikelyDirectory("/path/to/file.txt")).toBe(false);
|
||||
expect(isLikelyDirectory("file.js")).toBe(false);
|
||||
expect(isLikelyDirectory("script.test.ts")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -23,8 +23,8 @@ const isLikelyDirectory = (path: string): boolean => {
|
||||
if (path.endsWith("/") || path.endsWith("\\")) return true;
|
||||
// Check if path has no extension (simple heuristic)
|
||||
const lastPart = path.split(/[/\\]/).pop() || "";
|
||||
// If the last part has no dots or ends with a dot, it's likely a directory
|
||||
return !lastPart.includes(".") || lastPart.endsWith(".");
|
||||
// If the last part has no dots, it's likely a directory
|
||||
return !lastPart.includes(".");
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -86,4 +86,4 @@ function PathComponent(props: { children?: ReactNode }) {
|
||||
return <strong className="font-mono">{children}</strong>;
|
||||
}
|
||||
|
||||
export { PathComponent };
|
||||
export { PathComponent, isLikelyDirectory };
|
||||
|
||||
Reference in New Issue
Block a user