-
-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathPathPrefixer.js
33 lines (29 loc) · 1.45 KB
/
PathPrefixer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import test from "ava";
import path from "path";
import PathPrefixer from "../src/Util/PathPrefixer.js";
test("joinUrlParts", (t) => {
t.is(PathPrefixer.joinUrlParts("a"), "a");
t.is(PathPrefixer.joinUrlParts("a", "b"), "a/b");
t.is(PathPrefixer.joinUrlParts("", "a", "b"), "a/b");
t.is(PathPrefixer.joinUrlParts("/a", "b"), "/a/b");
t.is(PathPrefixer.joinUrlParts("a", "b", "c"), "a/b/c");
t.is(PathPrefixer.joinUrlParts("a/b", "c/"), "a/b/c/");
});
test("joinUrlParts (Windows)", (t) => {
// The replace calls are needed, since "\" is a valid path char on unix
t.is(PathPrefixer.joinUrlParts("a"), "a");
t.is(PathPrefixer.joinUrlParts("a\\b".replace(/\\/g, path.sep)), "a/b");
t.is(PathPrefixer.joinUrlParts("\\a\\b".replace(/\\/g, path.sep)), "/a/b");
t.is(PathPrefixer.joinUrlParts("a\\b\\c".replace(/\\/g, path.sep)), "a/b/c");
t.is(PathPrefixer.joinUrlParts("a\\b".replace(/\\/g, path.sep), "c"), "a/b/c");
t.is(PathPrefixer.joinUrlParts("a\\b\\c\\".replace(/\\/g, path.sep)), "a/b/c/");
t.is(PathPrefixer.joinUrlParts("a\\b/c\\".replace(/\\/g, path.sep)), "a/b/c/");
});
test("normalizePathPrefix", (t) => {
t.is(PathPrefixer.normalizePathPrefix("a"), "/a");
t.is(PathPrefixer.normalizePathPrefix("a/b"), "/a/b");
t.is(PathPrefixer.normalizePathPrefix("/a/b"), "/a/b");
t.is(PathPrefixer.normalizePathPrefix("/"), "/");
t.is(PathPrefixer.normalizePathPrefix(""), "/");
t.is(PathPrefixer.normalizePathPrefix(undefined), "/");
});