Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwill90 committed Apr 3, 2023
1 parent bfd38bf commit 3832f51
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 411 deletions.
2 changes: 1 addition & 1 deletion error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type RouteConflictError struct {

func newConflictErr(method, path, catchAllKey string, matched []string) *RouteConflictError {
if catchAllKey != "" {
path += "*" + catchAllKey
path += "*{" + catchAllKey + "}"
}
return &RouteConflictError{
Method: method,
Expand Down
21 changes: 21 additions & 0 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,24 @@ func (n *node) string(space int) string {
}
return sb.String()
}

type skippedNodes []skippedNode

func (n *skippedNodes) free(t *Tree) {
if cap(*n) < int(t.maxDepth.Load()) {
return
}
*n = (*n)[:0]
t.np.Put(n)
}

func (n *skippedNodes) pop() skippedNode {
skipped := (*n)[len(*n)-1]
*n = (*n)[:len(*n)-1]
return skipped
}

type skippedNode struct {
node *node
pathIndex int
}
18 changes: 16 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (fox *Router) NewTree() *Tree {

tree.np = sync.Pool{
New: func() any {
skippedNodes := make([]skippedNode, 0, tree.maxDepth.Load())
return &skippedNodes
skpNds := make(skippedNodes, 0, tree.maxDepth.Load())
return &skpNds
},
}

Expand Down Expand Up @@ -518,8 +518,22 @@ func parseRoute(path string) (string, string, int, error) {
return path, "", paramCnt, nil
}

func getRouteNamedParameterConflict() {

}

func getRouteConflict(n *node) []string {
routes := make([]string, 0)

if n.isCatchAll() {
routes = append(routes, n.path)
return routes
}
// TODO panics ????
if n.paramChildIndex >= 0 {
n = n.children[n.paramChildIndex].Load()
}

it := newRawIterator(n)
for it.hasNext() {
routes = append(routes, it.current.path)
Expand Down
Loading

0 comments on commit 3832f51

Please sign in to comment.