Coverage Summary for Class: RouteReceiver (kweb.routing)
Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
RouteReceiver |
100%
(3/3)
|
|
100%
(6/6)
|
100%
(47/47)
|
RouteReceiver$notFoundReceiver$1 |
0%
(0/1)
|
|
0%
(0/1)
|
0%
(0/10)
|
RouteReceiver$path$1 |
100%
(1/1)
|
|
100%
(1/1)
|
100%
(4/4)
|
Total |
80%
(4/5)
|
|
87.5%
(7/8)
|
83.6%
(51/61)
|
package kweb.routing
import io.ktor.server.routing.RoutingPath
import kweb.h1
class RouteReceiver internal constructor() {
internal val templatesByLength = HashMap<Int, MutableMap<PathTemplate, PathReceiver>>()
internal var notFoundReceiver: NotFoundReceiver = { path ->
h1().text("Not Found: $path")
}
fun path(template: String, pathReceiver: PathReceiver) {
val routingPath = RoutingPath.parse(template).parts
templatesByLength.computeIfAbsent(routingPath.size) { HashMap() }[routingPath] = pathReceiver
}
fun notFound(receiver: NotFoundReceiver) {
notFoundReceiver = receiver
}
}