aboutsummaryrefslogtreecommitdiff
path: root/test/js/node/path/path.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/node/path/path.test.js')
-rw-r--r--test/js/node/path/path.test.js66
1 files changed, 66 insertions, 0 deletions
diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js
index caaf12db0..94b0568f6 100644
--- a/test/js/node/path/path.test.js
+++ b/test/js/node/path/path.test.js
@@ -3,12 +3,18 @@ const { file } = import.meta;
import { describe, it, expect } from "bun:test";
import * as path from "node:path";
import assert from "assert";
+import { hideFromStackTrace } from "harness";
const strictEqual = (...args) => {
assert.strictEqual(...args);
expect(true).toBe(true);
};
+const expectStrictEqual = (actual, expected) => {
+ expect(actual).toBe(expected);
+};
+hideFromStackTrace(expectStrictEqual);
+
it("should not inherit Object.prototype", () => {
expect(path).not.toHaveProperty("toString");
});
@@ -35,6 +41,66 @@ it("path.dirname", () => {
}
});
+it("path.parse().name", () => {
+ expectStrictEqual(path.parse(file).name, "path.test");
+ expectStrictEqual(path.parse(".js").name, ".js");
+ expectStrictEqual(path.parse("..js").name, ".");
+ expectStrictEqual(path.parse("").name, "");
+ expectStrictEqual(path.parse(".").name, ".");
+ expectStrictEqual(path.parse("dir/name.ext").name, "name");
+ expectStrictEqual(path.parse("/dir/name.ext").name, "name");
+ expectStrictEqual(path.parse("/name.ext").name, "name");
+ expectStrictEqual(path.parse("name.ext").name, "name");
+ expectStrictEqual(path.parse("name.ext/").name, "name");
+ expectStrictEqual(path.parse("name.ext//").name, "name");
+ expectStrictEqual(path.parse("aaa/bbb").name, "bbb");
+ expectStrictEqual(path.parse("aaa/bbb/").name, "bbb");
+ expectStrictEqual(path.parse("aaa/bbb//").name, "bbb");
+ expectStrictEqual(path.parse("/aaa/bbb").name, "bbb");
+ expectStrictEqual(path.parse("/aaa/bbb/").name, "bbb");
+ expectStrictEqual(path.parse("/aaa/bbb//").name, "bbb");
+ expectStrictEqual(path.parse("//aaa/bbb").name, "bbb");
+ expectStrictEqual(path.parse("//aaa/bbb/").name, "bbb");
+ expectStrictEqual(path.parse("//aaa/bbb//").name, "bbb");
+ expectStrictEqual(path.parse("///aaa").name, "aaa");
+ expectStrictEqual(path.parse("//aaa").name, "aaa");
+ expectStrictEqual(path.parse("/aaa").name, "aaa");
+ expectStrictEqual(path.parse("aaa.").name, "aaa");
+
+ // On unix a backslash is just treated as any other character.
+ expectStrictEqual(path.posix.parse("\\dir\\name.ext").name, "\\dir\\name");
+ expectStrictEqual(path.posix.parse("\\name.ext").name, "\\name");
+ expectStrictEqual(path.posix.parse("name.ext").name, "name");
+ expectStrictEqual(path.posix.parse("name.ext\\").name, "name");
+ expectStrictEqual(path.posix.parse("name.ext\\\\").name, "name");
+});
+
+it("path.parse() windows edition", () => {
+ // On Windows a backslash acts as a path separator.
+ expectStrictEqual(path.win32.parse("\\dir\\name.ext").name, "name");
+ expectStrictEqual(path.win32.parse("\\name.ext").name, "name");
+ expectStrictEqual(path.win32.parse("name.ext").name, "name");
+ expectStrictEqual(path.win32.parse("name.ext\\").name, "name");
+ expectStrictEqual(path.win32.parse("name.ext\\\\").name, "name");
+ expectStrictEqual(path.win32.parse("name").name, "name");
+ expectStrictEqual(path.win32.parse(".name").name, ".name");
+ expectStrictEqual(path.win32.parse("file:stream").name, "file:stream");
+});
+
+it.todo("path.parse() windows edition - drive letter", () => {
+ expectStrictEqual(path.win32.parse("C:").name, "");
+ expectStrictEqual(path.win32.parse("C:.").name, ".");
+ expectStrictEqual(path.win32.parse("C:\\").name, "");
+ expectStrictEqual(path.win32.parse("C:\\.").name, ".");
+ expectStrictEqual(path.win32.parse("C:\\.ext").name, ".ext");
+ expectStrictEqual(path.win32.parse("C:\\dir\\name.ext").name, "name");
+ expectStrictEqual(path.win32.parse("C:name.ext").name, "name");
+ expectStrictEqual(path.win32.parse("C:name.ext\\").name, "name");
+ expectStrictEqual(path.win32.parse("C:name.ext\\\\").name, "name");
+ expectStrictEqual(path.win32.parse("C:foo").name, "foo");
+ expectStrictEqual(path.win32.parse("C:.foo").name, ".foo");
+});
+
it("path.basename", () => {
strictEqual(path.basename(file), "path.test.js");
strictEqual(path.basename(file, ".js"), "path.test");