@@ -1318,6 +1318,44 @@ func Test_Ctx_Params(t *testing.T) {
1318
1318
utils .AssertEqual (t , StatusOK , resp .StatusCode , "Status code" )
1319
1319
}
1320
1320
1321
+ // go test -race -run Test_Ctx_AllParams
1322
+ func Test_Ctx_AllParams (t * testing.T ) {
1323
+ t .Parallel ()
1324
+ app := New ()
1325
+ app .Get ("/test/:user" , func (c * Ctx ) error {
1326
+ utils .AssertEqual (t , map [string ]string {"user" : "john" }, c .AllParams ())
1327
+ return nil
1328
+ })
1329
+ app .Get ("/test2/*" , func (c * Ctx ) error {
1330
+ utils .AssertEqual (t , map [string ]string {"*1" : "im/a/cookie" }, c .AllParams ())
1331
+ return nil
1332
+ })
1333
+ app .Get ("/test3/*/blafasel/*" , func (c * Ctx ) error {
1334
+ utils .AssertEqual (t , map [string ]string {"*1" : "1111" , "*2" : "2222" }, c .AllParams ())
1335
+ return nil
1336
+ })
1337
+ app .Get ("/test4/:optional?" , func (c * Ctx ) error {
1338
+ utils .AssertEqual (t , map [string ]string {"optional" : "" }, c .AllParams ())
1339
+ return nil
1340
+ })
1341
+
1342
+ resp , err := app .Test (httptest .NewRequest (MethodGet , "/test/john" , nil ))
1343
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
1344
+ utils .AssertEqual (t , StatusOK , resp .StatusCode , "Status code" )
1345
+
1346
+ resp , err = app .Test (httptest .NewRequest (MethodGet , "/test2/im/a/cookie" , nil ))
1347
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
1348
+ utils .AssertEqual (t , StatusOK , resp .StatusCode , "Status code" )
1349
+
1350
+ resp , err = app .Test (httptest .NewRequest (MethodGet , "/test3/1111/blafasel/2222" , nil ))
1351
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
1352
+ utils .AssertEqual (t , StatusOK , resp .StatusCode , "Status code" )
1353
+
1354
+ resp , err = app .Test (httptest .NewRequest (MethodGet , "/test4" , nil ))
1355
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
1356
+ utils .AssertEqual (t , StatusOK , resp .StatusCode , "Status code" )
1357
+ }
1358
+
1321
1359
// go test -v -run=^$ -bench=Benchmark_Ctx_Params -benchmem -count=4
1322
1360
func Benchmark_Ctx_Params (b * testing.B ) {
1323
1361
app := New ()
@@ -1343,6 +1381,32 @@ func Benchmark_Ctx_Params(b *testing.B) {
1343
1381
utils .AssertEqual (b , "awesome" , res )
1344
1382
}
1345
1383
1384
+ // go test -v -run=^$ -bench=Benchmark_Ctx_AllParams -benchmem -count=4
1385
+ func Benchmark_Ctx_AllParams (b * testing.B ) {
1386
+ app := New ()
1387
+ c := app .AcquireCtx (& fasthttp.RequestCtx {})
1388
+ defer app .ReleaseCtx (c )
1389
+ c .route = & Route {
1390
+ Params : []string {
1391
+ "param1" , "param2" , "param3" , "param4" ,
1392
+ },
1393
+ }
1394
+ c .values = [maxParams ]string {
1395
+ "john" , "doe" , "is" , "awesome" ,
1396
+ }
1397
+ var res map [string ]string
1398
+ b .ReportAllocs ()
1399
+ b .ResetTimer ()
1400
+ for n := 0 ; n < b .N ; n ++ {
1401
+ res = c .AllParams ()
1402
+ }
1403
+ utils .AssertEqual (b , map [string ]string {"param1" : "john" ,
1404
+ "param2" : "doe" ,
1405
+ "param3" : "is" ,
1406
+ "param4" : "awesome" },
1407
+ res )
1408
+ }
1409
+
1346
1410
// go test -run Test_Ctx_Path
1347
1411
func Test_Ctx_Path (t * testing.T ) {
1348
1412
t .Parallel ()
0 commit comments