diff options
| author | Eltrac <hi@guhub.cn> | 2025-12-03 15:46:30 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-03 15:46:30 +0800 |
| commit | 264ab718015da27d97a7f7ac4132b1e061f9d8d9 (patch) | |
| tree | 9653faea7dd4e742c2d65fb7f758f3ebf9239a67 /parser_test.go | |
| parent | a206d80e51372dffcb86b6fcd2be3c8e24517c5c (diff) | |
| parent | f2103d4182acde938572c16753f8752c1f811fbf (diff) | |
Merge pull request #1 from BigCoke233/fix-empty-params
refactor, fix: use vanilla `request.URL.Query()` instead of a custom parser
Diffstat (limited to 'parser_test.go')
| -rw-r--r-- | parser_test.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/parser_test.go b/parser_test.go deleted file mode 100644 index cf00017..0000000 --- a/parser_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package growel - -import ( - "fmt" - "reflect" - "testing" -) - -func TestRouterSplitPath(t *testing.T) { - tests := []struct { - input string - want []string - }{ - {"/", []string{""}}, - {"/hello", []string{"hello"}}, - {"/hello/world", []string{"hello", "world"}}, - {"//hello//world//", []string{"hello", "", "world"}}, - {"/hello?world=true", []string{"hello?world=true"}}, - } - - for _, tt := range tests { - got := 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) - } - } - } -} - -func TestExtractQueryStr(t *testing.T) { - tests := []struct { - input string - want1 string - want2 string - }{ - {"", "", ""}, - {"hello", "hello", ""}, - {"user/23/", "user/23/", ""}, - {"api?str=123&yrs=23", "api", "str=123&yrs=23"}, - {"w?st?r", "w", "st"}, - {"w?str", "w", "str"}, - } - - for _, tt := range tests { - got1, got2 := extractQueryStr(tt.input) - if got1 != tt.want1 && got2 != tt.want2 { - fmt.Printf("want1: %s, got1: %s\n", tt.want1, got1) - fmt.Printf("want2: %s, got2: %s\n", tt.want2, got2) - t.Fail() - } - } -} - -func TestParseQueryStr(t *testing.T) { - tests := []struct { - input string - want map[string]string - }{ - {"str=123&yrs=23", map[string]string{ - "str": "123", - "yrs": "23", - }}, - {"str=abc", map[string]string{ - "str": "abc", - }}, - } - - for _, tt := range tests { - got := parseQueryStr(tt.input) - if !reflect.DeepEqual(got, tt.want) { - fmt.Printf("want: %s, got: %s\n", tt.want, got) - t.Fail() - } - } -} |
