@@ -24,11 +24,13 @@ describe("UriTemplate", () => {
24
24
expect ( template . expand ( { username : "fred" } ) ) . toBe (
25
25
"http://example.com/users/fred" ,
26
26
) ;
27
+ expect ( template . variableNames ) . toEqual ( [ 'username' ] )
27
28
} ) ;
28
29
29
30
it ( "should handle multiple variables" , ( ) => {
30
31
const template = new UriTemplate ( "{x,y}" ) ;
31
32
expect ( template . expand ( { x : "1024" , y : "768" } ) ) . toBe ( "1024,768" ) ;
33
+ expect ( template . variableNames ) . toEqual ( [ 'x' , 'y' ] )
32
34
} ) ;
33
35
34
36
it ( "should encode reserved characters" , ( ) => {
@@ -43,41 +45,47 @@ describe("UriTemplate", () => {
43
45
it ( "should not encode reserved characters with + operator" , ( ) => {
44
46
const template = new UriTemplate ( "{+path}/here" ) ;
45
47
expect ( template . expand ( { path : "/foo/bar" } ) ) . toBe ( "/foo/bar/here" ) ;
48
+ expect ( template . variableNames ) . toEqual ( [ 'path' ] )
46
49
} ) ;
47
50
} ) ;
48
51
49
52
describe ( "fragment expansion" , ( ) => {
50
53
it ( "should add # prefix and not encode reserved chars" , ( ) => {
51
54
const template = new UriTemplate ( "X{#var}" ) ;
52
55
expect ( template . expand ( { var : "/test" } ) ) . toBe ( "X#/test" ) ;
56
+ expect ( template . variableNames ) . toEqual ( [ 'var' ] )
53
57
} ) ;
54
58
} ) ;
55
59
56
60
describe ( "label expansion" , ( ) => {
57
61
it ( "should add . prefix" , ( ) => {
58
62
const template = new UriTemplate ( "X{.var}" ) ;
59
63
expect ( template . expand ( { var : "test" } ) ) . toBe ( "X.test" ) ;
64
+ expect ( template . variableNames ) . toEqual ( [ 'var' ] )
60
65
} ) ;
61
66
} ) ;
62
67
63
68
describe ( "path expansion" , ( ) => {
64
69
it ( "should add / prefix" , ( ) => {
65
70
const template = new UriTemplate ( "X{/var}" ) ;
66
71
expect ( template . expand ( { var : "test" } ) ) . toBe ( "X/test" ) ;
72
+ expect ( template . variableNames ) . toEqual ( [ 'var' ] )
67
73
} ) ;
68
74
} ) ;
69
75
70
76
describe ( "query expansion" , ( ) => {
71
77
it ( "should add ? prefix and name=value format" , ( ) => {
72
78
const template = new UriTemplate ( "X{?var}" ) ;
73
79
expect ( template . expand ( { var : "test" } ) ) . toBe ( "X?var=test" ) ;
80
+ expect ( template . variableNames ) . toEqual ( [ 'var' ] )
74
81
} ) ;
75
82
} ) ;
76
83
77
84
describe ( "form continuation expansion" , ( ) => {
78
85
it ( "should add & prefix and name=value format" , ( ) => {
79
86
const template = new UriTemplate ( "X{&var}" ) ;
80
87
expect ( template . expand ( { var : "test" } ) ) . toBe ( "X&var=test" ) ;
88
+ expect ( template . variableNames ) . toEqual ( [ 'var' ] )
81
89
} ) ;
82
90
} ) ;
83
91
@@ -133,13 +141,15 @@ describe("UriTemplate", () => {
133
141
resource : "users" ,
134
142
id : "123"
135
143
} ) ) . toBe ( "/api/v1/users/123" ) ;
144
+ expect ( template . variableNames ) . toEqual ( [ 'version' , 'resource' , 'id' ] )
136
145
} ) ;
137
146
138
147
it ( "should handle query parameters with arrays" , ( ) => {
139
148
const template = new UriTemplate ( "/search{?tags*}" ) ;
140
149
expect ( template . expand ( {
141
150
tags : [ "nodejs" , "typescript" , "testing" ]
142
151
} ) ) . toBe ( "/search?tags=nodejs,typescript,testing" ) ;
152
+ expect ( template . variableNames ) . toEqual ( [ 'tags' ] )
143
153
} ) ;
144
154
145
155
it ( "should handle multiple query parameters" , ( ) => {
@@ -149,6 +159,7 @@ describe("UriTemplate", () => {
149
159
page : "1" ,
150
160
limit : "10"
151
161
} ) ) . toBe ( "/search?q=test&page=1&limit=10" ) ;
162
+ expect ( template . variableNames ) . toEqual ( [ 'q' , 'page' , 'limit' ] )
152
163
} ) ;
153
164
} ) ;
154
165
@@ -161,18 +172,21 @@ describe("UriTemplate", () => {
161
172
resource : "users" ,
162
173
id : "123"
163
174
} ) ;
175
+ expect ( template . variableNames ) . toEqual ( [ 'version' , 'resource' , 'id' ] )
164
176
} ) ;
165
177
166
178
it ( "should match query parameters" , ( ) => {
167
179
const template = new UriTemplate ( "/search{?q}" ) ;
168
180
const match = template . match ( "/search?q=test" ) ;
169
181
expect ( match ) . toEqual ( { q : "test" } ) ;
182
+ expect ( template . variableNames ) . toEqual ( [ 'q' ] )
170
183
} ) ;
171
184
172
185
it ( "should match multiple query parameters" , ( ) => {
173
186
const template = new UriTemplate ( "/search{?q,page}" ) ;
174
187
const match = template . match ( "/search?q=test&page=1" ) ;
175
188
expect ( match ) . toEqual ( { q : "test" , page : "1" } ) ;
189
+ expect ( template . variableNames ) . toEqual ( [ 'q' , 'page' ] )
176
190
} ) ;
177
191
178
192
it ( "should handle partial matches correctly" , ( ) => {
@@ -229,17 +243,20 @@ describe("UriTemplate", () => {
229
243
it ( "should handle repeated operators" , ( ) => {
230
244
const template = new UriTemplate ( "{?a}{?b}{?c}" ) ;
231
245
expect ( template . expand ( { a : "1" , b : "2" , c : "3" } ) ) . toBe ( "?a=1&b=2&c=3" ) ;
246
+ expect ( template . variableNames ) . toEqual ( [ 'a' , 'b' , 'c' ] )
232
247
} ) ;
233
248
234
249
it ( "should handle overlapping variable names" , ( ) => {
235
250
const template = new UriTemplate ( "{var}{vara}" ) ;
236
251
expect ( template . expand ( { var : "1" , vara : "2" } ) ) . toBe ( "12" ) ;
252
+ expect ( template . variableNames ) . toEqual ( [ 'var' , 'vara' ] )
237
253
} ) ;
238
254
239
255
it ( "should handle empty segments" , ( ) => {
240
256
const template = new UriTemplate ( "///{a}////{b}////" ) ;
241
257
expect ( template . expand ( { a : "1" , b : "2" } ) ) . toBe ( "///1////2////" ) ;
242
258
expect ( template . match ( "///1////2////" ) ) . toEqual ( { a : "1" , b : "2" } ) ;
259
+ expect ( template . variableNames ) . toEqual ( [ 'a' , 'b' ] )
243
260
} ) ;
244
261
245
262
it ( "should handle maximum template expression limit" , ( ) => {
0 commit comments