Skip to content

Commit

Permalink
fix(tests): added unit test for splitePattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Dec 25, 2024
1 parent eeb94dd commit 3dc3026
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 37 additions & 0 deletions pattern_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package htmx

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestPattern(t *testing.T) {
tests := []struct {
pattern string
method string
host string
path string
}{
{"", "", "", ""},

{"/", "", "", ""},
{"/abc", "", "", "abc"},

{"GET /abc", "GET", "", "abc"},
{"GET /abc/", "GET", "", "abc/"},

{"GET abc.com/", "GET", "abc.com", ""},
{"GET abc.com/abc", "GET", "abc.com", "abc"},
{"GET abc.com/abc/", "GET", "abc.com", "abc/"},
}

for _, test := range tests {
method, host, path := splitPattern(test.pattern)

require.Equal(t, test.method, method, test.pattern)
require.Equal(t, test.host, host, test.pattern)
require.Equal(t, test.path, path, test.pattern)

}
}
3 changes: 1 addition & 2 deletions routing_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func TestRoutingOption(t *testing.T) {
}

return c.View(data)
}, WithMetadata("s1", time.Now()), WithMetadata("i1", "v100"),
WithNavigation("admin", "ha-dash", "admin:view"))
}, WithMetadata("s1", time.Now()), WithMetadata("i1", "v100"))

app.Start()
defer app.Close()
Expand Down

0 comments on commit 3dc3026

Please sign in to comment.