Skip to content

Commit

Permalink
feat(iter): improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Oct 7, 2024
1 parent 55cb06d commit 27a3eb6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@ func TestIter_All(t *testing.T) {
}
}

func TestIter_AllBreak(t *testing.T) {
tree := New().Tree()
for _, rte := range routesCases {
require.NoError(t, tree.Handle(http.MethodGet, rte, emptyHandler))
require.NoError(t, tree.Handle(http.MethodPost, rte, emptyHandler))
require.NoError(t, tree.Handle(http.MethodHead, rte, emptyHandler))
}

var (
lastMethod string
lastRoute *Route
)
it := tree.Iter()
for method, route := range it.All() {
lastMethod = method
lastRoute = route
break
}
assert.Equal(t, "GET", lastMethod)
assert.Equal(t, "/foo/bar/{baz}", lastRoute.Path())
}

func TestIter_RootPrefixOneMethod(t *testing.T) {
tree := New().Tree()
for _, rte := range routesCases {
Expand Down Expand Up @@ -99,6 +121,18 @@ func TestIter_Prefix(t *testing.T) {
}
}

func TestIter_EdgeCase(t *testing.T) {
tree := New().Tree()
it := tree.Iter()

assert.Empty(t, slices.Collect(left(it.Prefix(seqOf("GET"), "/"))))
assert.Empty(t, slices.Collect(left(it.Prefix(seqOf("CONNECT"), "/"))))
assert.Empty(t, slices.Collect(left(it.Reverse(seqOf("GET"), "/"))))
assert.Empty(t, slices.Collect(left(it.Reverse(seqOf("CONNECT"), "/"))))
assert.Empty(t, slices.Collect(left(it.Routes(seqOf("GET"), "/"))))
assert.Empty(t, slices.Collect(left(it.Routes(seqOf("CONNECT"), "/"))))
}

func TestIter_PrefixWithMethod(t *testing.T) {
tree := New().Tree()
for _, rte := range routesCases {
Expand Down

0 comments on commit 27a3eb6

Please sign in to comment.