6
6
type CompileOptions ,
7
7
type ParamData ,
8
8
TokenData ,
9
+ Path ,
9
10
} from "./index.js" ;
10
11
11
12
export interface ParserTestSet {
@@ -21,7 +22,7 @@ export interface StringifyTestSet {
21
22
}
22
23
23
24
export interface CompileTestSet {
24
- path : string ;
25
+ path : Path ;
25
26
options ?: CompileOptions & ParseOptions ;
26
27
tests : Array < {
27
28
input : ParamData | undefined ;
@@ -30,7 +31,7 @@ export interface CompileTestSet {
30
31
}
31
32
32
33
export interface MatchTestSet {
33
- path : string ;
34
+ path : Path | Path [ ] ;
34
35
options ?: MatchOptions & ParseOptions ;
35
36
tests : Array < {
36
37
input : string ;
@@ -41,64 +42,99 @@ export interface MatchTestSet {
41
42
export const PARSER_TESTS : ParserTestSet [ ] = [
42
43
{
43
44
path : "/" ,
44
- expected : new TokenData ( [ { type : "text" , value : "/" } ] ) ,
45
+ expected : new TokenData ( [ { type : "text" , value : "/" } ] , "/" ) ,
45
46
} ,
46
47
{
47
48
path : "/:test" ,
48
- expected : new TokenData ( [
49
- { type : "text" , value : "/" } ,
50
- { type : "param" , name : "test" } ,
51
- ] ) ,
49
+ expected : new TokenData (
50
+ [
51
+ { type : "text" , value : "/" } ,
52
+ { type : "param" , name : "test" } ,
53
+ ] ,
54
+ "/:test" ,
55
+ ) ,
56
+ } ,
57
+ {
58
+ path : "/:a:b" ,
59
+ expected : new TokenData (
60
+ [
61
+ { type : "text" , value : "/" } ,
62
+ { type : "param" , name : "a" } ,
63
+ { type : "param" , name : "b" } ,
64
+ ] ,
65
+ "/:a:b" ,
66
+ ) ,
52
67
} ,
53
68
{
54
69
path : '/:"0"' ,
55
- expected : new TokenData ( [
56
- { type : "text" , value : "/" } ,
57
- { type : "param" , name : "0" } ,
58
- ] ) ,
70
+ expected : new TokenData (
71
+ [
72
+ { type : "text" , value : "/" } ,
73
+ { type : "param" , name : "0" } ,
74
+ ] ,
75
+ '/:"0"' ,
76
+ ) ,
59
77
} ,
60
78
{
61
79
path : "/:_" ,
62
- expected : new TokenData ( [
63
- { type : "text" , value : "/" } ,
64
- { type : "param" , name : "_" } ,
65
- ] ) ,
80
+ expected : new TokenData (
81
+ [
82
+ { type : "text" , value : "/" } ,
83
+ { type : "param" , name : "_" } ,
84
+ ] ,
85
+ "/:_" ,
86
+ ) ,
66
87
} ,
67
88
{
68
89
path : "/:café" ,
69
- expected : new TokenData ( [
70
- { type : "text" , value : "/" } ,
71
- { type : "param" , name : "café" } ,
72
- ] ) ,
90
+ expected : new TokenData (
91
+ [
92
+ { type : "text" , value : "/" } ,
93
+ { type : "param" , name : "café" } ,
94
+ ] ,
95
+ "/:café" ,
96
+ ) ,
73
97
} ,
74
98
{
75
99
path : '/:"123"' ,
76
- expected : new TokenData ( [
77
- { type : "text" , value : "/" } ,
78
- { type : "param" , name : "123" } ,
79
- ] ) ,
100
+ expected : new TokenData (
101
+ [
102
+ { type : "text" , value : "/" } ,
103
+ { type : "param" , name : "123" } ,
104
+ ] ,
105
+ '/:"123"' ,
106
+ ) ,
80
107
} ,
81
108
{
82
109
path : '/:"1\\"\\2\\"3"' ,
83
- expected : new TokenData ( [
84
- { type : "text" , value : "/" } ,
85
- { type : "param" , name : '1"2"3' } ,
86
- ] ) ,
110
+ expected : new TokenData (
111
+ [
112
+ { type : "text" , value : "/" } ,
113
+ { type : "param" , name : '1"2"3' } ,
114
+ ] ,
115
+ '/:"1\\"\\2\\"3"' ,
116
+ ) ,
87
117
} ,
88
118
{
89
119
path : "/*path" ,
90
- expected : new TokenData ( [
91
- { type : "text" , value : "/" } ,
92
- { type : "wildcard" , name : "path" } ,
93
- ] ) ,
120
+ expected : new TokenData (
121
+ [
122
+ { type : "text" , value : "/" } ,
123
+ { type : "wildcard" , name : "path" } ,
124
+ ] ,
125
+ "/*path" ,
126
+ ) ,
94
127
} ,
95
128
{
96
129
path : '/:"test"stuff' ,
97
- expected : new TokenData ( [
98
- { type : "text" , value : "/" } ,
99
- { type : "param" , name : "test" } ,
100
- { type : "text" , value : "stuff" } ,
101
- ] ) ,
130
+ expected : new TokenData (
131
+ [
132
+ { type : "text" , value : "/" } ,
133
+ { type : "param" , name : "test" } ,
134
+ { type : "text" , value : "stuff" } ,
135
+ ] ,
136
+ '/:"test"stuff' ,
137
+ ) ,
102
138
} ,
103
139
] ;
104
140
@@ -1609,4 +1645,20 @@ export const MATCH_TESTS: MatchTestSet[] = [
1609
1645
} ,
1610
1646
] ,
1611
1647
} ,
1648
+
1649
+ /**
1650
+ * Array input is normalized.
1651
+ */
1652
+ {
1653
+ path : [ "/:foo/:bar" , "/:foo/:baz" ] ,
1654
+ tests : [
1655
+ {
1656
+ input : "/hello/world" ,
1657
+ expected : {
1658
+ path : "/hello/world" ,
1659
+ params : { foo : "hello" , bar : "world" } ,
1660
+ } ,
1661
+ } ,
1662
+ ] ,
1663
+ } ,
1612
1664
] ;
0 commit comments