-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
router_util_test.ts
34 lines (31 loc) 路 1.37 KB
/
router_util_test.ts
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
34
// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { findLongestAndNearestMatch, resolveIndexPath } from "./router_util.ts";
import { runIfMain, test } from "./vendor/https/deno.land/std/testing/mod.ts";
import { assertEquals } from "./vendor/https/deno.land/std/testing/asserts.ts";
([
["/foo", ["/foo", "/bar", "/f"], 0],
["/foo", ["/foo", "/foo/bar"], 0],
["/foo/bar", ["/", "/foo", "/hoo", "/hoo/foo/bar", "/foo/bar"], 4],
["/foo/bar/foo", ["/foo", "/foo/bar", "/bar/foo", "/foo/bar/foo"], 3],
["/foo", ["/", "/hoo", "/hoo/foo"], -1],
["/deno/land", [/d(.+?)o/, /d(.+?)d/], 1],
["/foo", ["/", "/a/foo", "/foo"], 2],
["/foo", [/\/foo/, /\/bar\/foo/], 0],
["/foo", [/\/a\/foo/, /\/foo/], 1]
] as [string, (string | RegExp)[], number][]).forEach(([path, pat, idx]) => {
test("findLongestAndNearestMatch:" + path, () => {
assertEquals(findLongestAndNearestMatch(path, pat).index, idx);
});
});
test("resolveIndexPath", async () => {
for (const [dir, fp, exp] of [
[".", "/README.md", "README.md"],
["./fixtures/public", "/", "fixtures/public/index.html"],
["./fixtures/public", "/index", "fixtures/public/index.html"],
["./fixtures/public", "/index.html", "fixtures/public/index.html"],
["./fixtures/public", "/nofile", undefined]
]) {
assertEquals(await resolveIndexPath(dir, fp), exp);
}
});
runIfMain(import.meta);