go test -run Test_Ctx_Path
(t *testing.T)
| 4809 | |
| 4810 | // go test -run Test_Ctx_Path |
| 4811 | func Test_Ctx_Path(t *testing.T) { |
| 4812 | t.Parallel() |
| 4813 | app := New(Config{UnescapePath: true}) |
| 4814 | app.Get("/test/:user", func(c Ctx) error { |
| 4815 | require.Equal(t, "/Test/John", c.Path()) |
| 4816 | require.Equal(t, "/Test/John", string(c.Request().URI().Path())) |
| 4817 | // not strict && case-insensitive |
| 4818 | require.Equal(t, "/ABC/", c.Path("/ABC/")) |
| 4819 | require.Equal(t, "/ABC/", string(c.Request().URI().Path())) |
| 4820 | require.Equal(t, "/test/john/", c.Path("/test/john/")) |
| 4821 | require.Equal(t, "/test/john/", string(c.Request().URI().Path())) |
| 4822 | return nil |
| 4823 | }) |
| 4824 | |
| 4825 | // test with special chars |
| 4826 | app.Get("/specialChars/:name", func(c Ctx) error { |
| 4827 | require.Equal(t, "/specialChars/créer", c.Path()) |
| 4828 | // unescape is also working if you set the path afterwards |
| 4829 | require.Equal(t, "/اختبار/", c.Path("/%D8%A7%D8%AE%D8%AA%D8%A8%D8%A7%D8%B1/")) |
| 4830 | require.Equal(t, "/اختبار/", string(c.Request().URI().Path())) |
| 4831 | return nil |
| 4832 | }) |
| 4833 | resp, err := app.Test(httptest.NewRequest(MethodGet, "/specialChars/cr%C3%A9er", http.NoBody)) |
| 4834 | require.NoError(t, err, "app.Test(req)") |
| 4835 | require.Equal(t, StatusOK, resp.StatusCode, "Status code") |
| 4836 | } |
| 4837 | |
| 4838 | // go test -run Test_Ctx_Protocol |
| 4839 | func Test_Ctx_Protocol(t *testing.T) { |