@@ -595,20 +595,41 @@ func TestRouterMatchAnyMultiLevel(t *testing.T) {
595
595
// Routes
596
596
r .Add (http .MethodGet , "/api/users/jack" , handler )
597
597
r .Add (http .MethodGet , "/api/users/jill" , handler )
598
+ r .Add (http .MethodGet , "/api/users/*" , handler )
599
+ r .Add (http .MethodGet , "/api/*" , handler )
600
+ r .Add (http .MethodGet , "/other/*" , handler )
598
601
r .Add (http .MethodGet , "/*" , handler )
599
602
600
603
c := e .NewContext (nil , nil ).(* context )
601
604
r .Find (http .MethodGet , "/api/users/jack" , c )
602
605
c .handler (c )
603
606
assert .Equal (t , "/api/users/jack" , c .Get ("path" ))
607
+ assert .Equal (t , "" , c .Param ("*" ))
604
608
605
609
r .Find (http .MethodGet , "/api/users/jill" , c )
606
610
c .handler (c )
607
611
assert .Equal (t , "/api/users/jill" , c .Get ("path" ))
612
+ assert .Equal (t , "" , c .Param ("*" ))
608
613
609
614
r .Find (http .MethodGet , "/api/users/joe" , c )
610
615
c .handler (c )
616
+ assert .Equal (t , "/api/users/*" , c .Get ("path" ))
617
+ assert .Equal (t , "joe" , c .Param ("*" ))
618
+
619
+ r .Find (http .MethodGet , "/api/nousers/joe" , c )
620
+ c .handler (c )
621
+ assert .Equal (t , "/api/*" , c .Get ("path" ))
622
+ assert .Equal (t , "nousers/joe" , c .Param ("*" ))
623
+
624
+ r .Find (http .MethodGet , "/api/none" , c )
625
+ c .handler (c )
626
+ assert .Equal (t , "/api/*" , c .Get ("path" ))
627
+ assert .Equal (t , "none" , c .Param ("*" ))
628
+
629
+ r .Find (http .MethodGet , "/noapi/users/jim" , c )
630
+ c .handler (c )
611
631
assert .Equal (t , "/*" , c .Get ("path" ))
632
+ assert .Equal (t , "noapi/users/jim" , c .Param ("*" ))
612
633
}
613
634
614
635
func TestRouterMicroParam (t * testing.T ) {
@@ -702,6 +723,15 @@ func TestRouterPriority(t *testing.T) {
702
723
c .Set ("g" , 7 )
703
724
return nil
704
725
})
726
+ r .Add (http .MethodGet , "/users/new/*" , func (c Context ) error {
727
+ c .Set ("h" , 8 )
728
+ return nil
729
+ })
730
+ r .Add (http .MethodGet , "/*" , func (c Context ) error {
731
+ c .Set ("i" , 9 )
732
+ return nil
733
+ })
734
+
705
735
c := e .NewContext (nil , nil ).(* context )
706
736
707
737
// Route > /users
@@ -734,11 +764,46 @@ func TestRouterPriority(t *testing.T) {
734
764
c .handler (c )
735
765
assert .Equal (t , 3 , c .Get ("c" ))
736
766
767
+ // Route > /users/newsee
768
+ r .Find (http .MethodGet , "/users/newsee" , c )
769
+ c .handler (c )
770
+ assert .Equal (t , 6 , c .Get ("f" ))
771
+
737
772
// Route > /users/*
738
773
r .Find (http .MethodGet , "/users/joe/books" , c )
739
774
c .handler (c )
740
775
assert .Equal (t , 7 , c .Get ("g" ))
741
776
assert .Equal (t , "joe/books" , c .Param ("*" ))
777
+
778
+ // Route > /users/new/* should be matched
779
+ r .Find (http .MethodGet , "/users/new/someone" , c )
780
+ c .handler (c )
781
+ assert .Equal (t , 8 , c .Get ("h" ))
782
+ assert .Equal (t , "someone" , c .Param ("*" ))
783
+
784
+ // Route > /users/* should be matched although /users/dew exists
785
+ r .Find (http .MethodGet , "/users/dew/someone" , c )
786
+ c .handler (c )
787
+ assert .Equal (t , 7 , c .Get ("g" ))
788
+ assert .Equal (t , "dew/someone" , c .Param ("*" ))
789
+
790
+ // Route > /users/* should be matched although /users/dew exists
791
+ r .Find (http .MethodGet , "/users/notexists/someone/else" , c )
792
+ c .handler (c )
793
+ assert .Equal (t , 7 , c .Get ("g" ))
794
+ assert .Equal (t , "notexists/someone/else" , c .Param ("*" ))
795
+
796
+ // Route > *
797
+ r .Find (http .MethodGet , "/nousers" , c )
798
+ c .handler (c )
799
+ assert .Equal (t , 9 , c .Get ("i" ))
800
+ assert .Equal (t , "nousers" , c .Param ("*" ))
801
+
802
+ // Route > *
803
+ r .Find (http .MethodGet , "/nousers/new" , c )
804
+ c .handler (c )
805
+ assert .Equal (t , 9 , c .Get ("i" ))
806
+ assert .Equal (t , "nousers/new" , c .Param ("*" ))
742
807
}
743
808
744
809
func TestRouterIssue1348 (t * testing.T ) {
0 commit comments