MCPcopy Create free account
hub / github.com/Markonis/hndl / acceptPathTests

Function acceptPathTests

tests/accept-path.ts:4–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { deepStrictEqual } from "assert";
3
4export function acceptPathTests()
5{
6 { // MATCH: single slash
7 const params = parsePathWithParams("/", "/");
8 deepStrictEqual(params, {});
9 }
10
11 { // MATCH: simple path with no params
12 const params = parsePathWithParams("/simple/path", "/simple/path");
13 deepStrictEqual(params, {});
14 }
15
16 { // MATCH: simple path with no params with query string
17 const params = parsePathWithParams("/simple/path?a=1", "/simple/path");
18 deepStrictEqual(params, {});
19 }
20
21 { // FAIL: different at the end
22 const params = parsePathWithParams("/simple/path/fail", "/simple/path");
23 deepStrictEqual(params, undefined);
24 }
25
26 { // FAIL: different in the middle
27 const params = parsePathWithParams("/simple/fail/path", "/simple/correct/path");
28 deepStrictEqual(params, undefined);
29 }
30
31 { // MATCH: single param
32 const params = parsePathWithParams("/hello/world", "/hello/:greeting");
33 deepStrictEqual(params, { greeting: "world" });
34 }
35
36 { // FAIL: double slash
37 const params = parsePathWithParams("/hello//world", "/hello/:greeting");
38 deepStrictEqual(params, undefined);
39 }
40
41 { // MATCH: only one param
42 const params = parsePathWithParams("hello", ":greeting");
43 deepStrictEqual(params, { greeting: "hello" });
44 }
45
46 { // MATCH: single param with query string
47 const params = parsePathWithParams("/hello/world?a=1", "/hello/:greeting");
48 deepStrictEqual(params, { greeting: "world" });
49 }
50
51 { // MATCH: single param with trailing slash
52 const params = parsePathWithParams("/hello/world/", "/hello/:greeting/");
53 deepStrictEqual(params, { greeting: "world" });
54 }
55
56 { // FAIL: single param with trailing slash in URL only
57 const params = parsePathWithParams("/hello/world/", "/hello/:greeting");
58 deepStrictEqual(params, undefined);
59 }
60
61 { // FAIL: single param with trailing slash in pattern only

Callers 1

index.tsFile · 0.90

Calls 1

parsePathWithParamsFunction · 0.90

Tested by

no test coverage detected