aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/path/path.test.js
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-05-31 16:07:52 -0300
committerGravatar GitHub <noreply@github.com> 2023-05-31 12:07:52 -0700
commit58fcb60831f346a7f07a258f67bdf40e55e094d2 (patch)
tree5894a003bcde916f3857985917de4b36c4b1294c /test/js/node/path/path.test.js
parent557aac6a34bcd06bba98060f67bb7295d6c462d9 (diff)
downloadbun-58fcb60831f346a7f07a258f67bdf40e55e094d2.tar.gz
bun-58fcb60831f346a7f07a258f67bdf40e55e094d2.tar.zst
bun-58fcb60831f346a7f07a258f67bdf40e55e094d2.zip
fix(path) fix parse behavior (#3134)
Diffstat (limited to 'test/js/node/path/path.test.js')
-rw-r--r--test/js/node/path/path.test.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js
index d2880f124..caaf12db0 100644
--- a/test/js/node/path/path.test.js
+++ b/test/js/node/path/path.test.js
@@ -450,3 +450,73 @@ it("path.resolve", () => {
});
strictEqual(failures.length, 0, failures.join("\n"));
});
+
+it("path.parse", () => {
+ expect(path.parse("/tmp")).toStrictEqual({ root: "/", dir: "/", base: "tmp", ext: "", name: "tmp" });
+
+ expect(path.parse("/tmp/test.txt")).toStrictEqual({
+ root: "/",
+ dir: "/tmp",
+ base: "test.txt",
+ ext: ".txt",
+ name: "test",
+ });
+
+ expect(path.parse("/tmp/test/file.txt")).toStrictEqual({
+ root: "/",
+ dir: "/tmp/test",
+ base: "file.txt",
+ ext: ".txt",
+ name: "file",
+ });
+
+ expect(path.parse("/tmp/test/dir")).toStrictEqual({ root: "/", dir: "/tmp/test", base: "dir", ext: "", name: "dir" });
+ expect(path.parse("/tmp/test/dir/")).toStrictEqual({
+ root: "/",
+ dir: "/tmp/test",
+ base: "dir",
+ ext: "",
+ name: "dir",
+ });
+
+ expect(path.parse(".")).toStrictEqual({ root: "", dir: "", base: ".", ext: "", name: "." });
+ expect(path.parse("./")).toStrictEqual({ root: "", dir: "", base: ".", ext: "", name: "." });
+ expect(path.parse("/.")).toStrictEqual({ root: "/", dir: "/", base: ".", ext: "", name: "." });
+ expect(path.parse("/../")).toStrictEqual({ root: "/", dir: "/", base: "..", ext: ".", name: "." });
+
+ expect(path.parse("./file.txt")).toStrictEqual({ root: "", dir: ".", base: "file.txt", ext: ".txt", name: "file" });
+ expect(path.parse("../file.txt")).toStrictEqual({ root: "", dir: "..", base: "file.txt", ext: ".txt", name: "file" });
+ expect(path.parse("../test/file.txt")).toStrictEqual({
+ root: "",
+ dir: "../test",
+ base: "file.txt",
+ ext: ".txt",
+ name: "file",
+ });
+ expect(path.parse("test/file.txt")).toStrictEqual({
+ root: "",
+ dir: "test",
+ base: "file.txt",
+ ext: ".txt",
+ name: "file",
+ });
+
+ expect(path.parse("test/dir")).toStrictEqual({ root: "", dir: "test", base: "dir", ext: "", name: "dir" });
+ expect(path.parse("test/dir/another_dir")).toStrictEqual({
+ root: "",
+ dir: "test/dir",
+ base: "another_dir",
+ ext: "",
+ name: "another_dir",
+ });
+
+ expect(path.parse("./dir")).toStrictEqual({ root: "", dir: ".", base: "dir", ext: "", name: "dir" });
+ expect(path.parse("../dir")).toStrictEqual({ root: "", dir: "..", base: "dir", ext: "", name: "dir" });
+ expect(path.parse("../dir/another_dir")).toStrictEqual({
+ root: "",
+ dir: "../dir",
+ base: "another_dir",
+ ext: "",
+ name: "another_dir",
+ });
+});