Added wildcard test

This commit is contained in:
Eduard Urbach 2023-07-10 11:59:21 +02:00
parent 8ae4bc1a0e
commit e8b332c90a
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -34,7 +34,7 @@ func TestHello(t *testing.T) {
assert.Equal(t, data, "")
}
func TestParams(t *testing.T) {
func TestParam(t *testing.T) {
router := router.New[string]()
router.Add("GET", "/blog/:slug", "Blog post")
@ -55,6 +55,23 @@ func TestParams(t *testing.T) {
assert.Equal(t, data, "Comment")
}
func TestWildcard(t *testing.T) {
router := router.New[string]()
router.Add("GET", "/", "Front page")
router.Add("GET", "/images/*path", "Wildcard")
data, params := router.Lookup("GET", "/")
assert.Equal(t, len(params), 0)
assert.Equal(t, data, "Front page")
data, params = router.Lookup("GET", "/images/favicon/256.png")
assert.Equal(t, len(params), 1)
assert.Equal(t, params[0].Key, "path")
assert.Equal(t, params[0].Value, "favicon/256.png")
assert.Equal(t, data, "Wildcard")
}
func TestGitHub(t *testing.T) {
tree := router.New[string]()
routes := loadRoutes("testdata/github.txt")