diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-28 23:13:23 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-28 23:13:23 +0800 |
| commit | 3f53ba50f2e562b5a2bc97442266b5e7acd585eb (patch) | |
| tree | ab29b0db71bb1661af0502b3b3442fb0f84a0590 /router_test.go | |
| parent | accb1bae86a3547f16dcc448f92ec73a493dfd85 (diff) | |
feat(router, context)!: support query string also move path split logic to
parser.go
Diffstat (limited to 'router_test.go')
| -rw-r--r-- | router_test.go | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/router_test.go b/router_test.go index 24a2faa..e03d16f 100644 --- a/router_test.go +++ b/router_test.go @@ -10,7 +10,7 @@ func TestRouterStaticMatch(t *testing.T) { r := NewRouter() r.Add("GET", "/hello", dummy) - h, params := r.Find("GET", "/hello") + h, params, _ := r.Find("GET", "/hello") if h == nil { t.Fatal("expected handler, got nil") } @@ -23,7 +23,7 @@ func TestRouterStaticNoMatch(t *testing.T) { r := NewRouter() r.Add("GET", "/hello", dummy) - h, _ := r.Find("GET", "/nothello") + h, _, _ := r.Find("GET", "/nothello") if h != nil { t.Fatal("expected nil handler, got non-nil") } @@ -33,7 +33,7 @@ func TestRouterParamMatch(t *testing.T) { r := NewRouter() r.Add("GET", "/user/:id", dummy) - h, params := r.Find("GET", "/user/42") + h, params, _ := r.Find("GET", "/user/42") if h == nil { t.Fatal("expected handler, got nil") } @@ -46,34 +46,21 @@ func TestRouterParamMismatch(t *testing.T) { r := NewRouter() r.Add("GET", "/user/:id", dummy) - h, _ := r.Find("GET", "/user") + h, _, _ := r.Find("GET", "/user") if h != nil { t.Fatal("expected nil handler, got non-nil") } } -func TestRouterSplitPath(t *testing.T) { +func TestRouterQueryMatch(t *testing.T) { r := NewRouter() + r.Add("GET", "/user", dummy) - tests := []struct { - input string - want []string - }{ - {"/", []string{""}}, - {"/hello", []string{"hello"}}, - {"/hello/world", []string{"hello", "world"}}, - {"//hello//world//", []string{"hello", "", "world"}}, + h, _, query := r.Find("GET", "/user?id=42") + if h == nil { + t.Fatal("expected handler, got nil") } - - for _, tt := range tests { - got := r.splitPath(tt.input) - if len(got) != len(tt.want) { - t.Fatalf("splitPath(%q) length mismatch: got %v want %v", tt.input, got, tt.want) - } - for i := range got { - if got[i] != tt.want[i] { - t.Fatalf("splitPath(%q) mismatch: got %v want %v", tt.input, got, tt.want) - } - } + if query["id"] != "42" { + t.Fatalf("expected id=42, got %v", query) } } |
