Improved test coverage

This commit is contained in:
Eduard Urbach 2023-09-06 16:52:22 +02:00
parent 763686679f
commit 0323126f2c
Signed by: eduard
GPG key ID: 49226B848C78F6C8
5 changed files with 80 additions and 71 deletions

View file

@ -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
}