Improved test coverage
This commit is contained in:
parent
763686679f
commit
0323126f2c
5 changed files with 80 additions and 71 deletions
46
treeNode.go
46
treeNode.go
|
@ -1,8 +1,6 @@
|
|||
package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -283,47 +281,3 @@ func (node *treeNode[T]) each(callback func(*treeNode[T])) {
|
|||
node.wildcard.each(callback)
|
||||
}
|
||||
}
|
||||
|
||||
// PrettyPrint prints a human-readable form of the tree to the given writer.
|
||||
func (node *treeNode[T]) PrettyPrint(writer io.Writer) {
|
||||
node.prettyPrint(writer, -1)
|
||||
}
|
||||
|
||||
// prettyPrint is the underlying pretty printer.
|
||||
func (node *treeNode[T]) prettyPrint(writer io.Writer, level int) {
|
||||
prefix := ""
|
||||
|
||||
if level >= 0 {
|
||||
prefix = strings.Repeat(" ", level) + "|_ "
|
||||
}
|
||||
|
||||
switch node.kind {
|
||||
case ':':
|
||||
prefix += ":"
|
||||
case '*':
|
||||
prefix += "*"
|
||||
}
|
||||
|
||||
fmt.Fprintf(writer, "%s%s [%v]\n", prefix, node.prefix, node.data)
|
||||
|
||||
for _, child := range node.children {
|
||||
if child == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
child.prettyPrint(writer, level+1)
|
||||
}
|
||||
|
||||
if node.parameter != nil {
|
||||
node.parameter.prettyPrint(writer, level+1)
|
||||
}
|
||||
|
||||
if node.wildcard != nil {
|
||||
node.wildcard.prettyPrint(writer, level+1)
|
||||
}
|
||||
}
|
||||
|
||||
// String returns the node prefix.
|
||||
func (node *treeNode[T]) String() string {
|
||||
return node.prefix
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue