-
Notifications
You must be signed in to change notification settings - Fork 0
/
route_parser_test.ts
43 lines (34 loc) · 1.2 KB
/
route_parser_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
35
36
37
38
39
40
41
42
43
import { assertEquals } from "./deps.ts";
import { test } from "./route_parser.ts";
Deno.test("[router_parser: normal mode]", async function parseTest(): Promise<
void
> {
const testRoute: string = "/categories/{category}/pages/{page}";
const testPath: string = "/categories/books/pages/10";
assertEquals(
test(testRoute, testPath),
{ "category": "books", "page": "10" },
);
const testRouteParam: string = "/categories/{category}/pages/{page}";
const testPathParam: string = "/categories/books/pages/10/?test";
assertEquals(
test(testRouteParam, testPathParam),
{ "category": "books", "page": "10" },
);
});
Deno.test("[router_parser: regex mode]", async function parseTest(): Promise<
void
> {
const testRoute: string = "/categories/{category}/pages/{page:([0-9]+)}";
const testPath: string = "/categories/books/pages/10";
assertEquals(
test(testRoute, testPath),
{ "category": "books", "page": "10" },
);
const testRouteParam: string = "/categories/{category}/pages/{page:([0-9]+)}";
const testPathParam: string = "/categories/books/pages/10?hello#world";
assertEquals(
test(testRouteParam, testPathParam),
{ "category": "books", "page": "10" },
);
});