Skip to content

Commit

Permalink
Fix unparsing of root path
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Jul 18, 2024
1 parent ac39fce commit eceae42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion core/jvm/src/test/scala/krop/route/PathUnparseSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,28 @@ import org.http4s.Uri
import org.http4s.implicits.*

class PathUnparseSuite extends FunSuite {
val rootPath = Path.root
val nonCapturingPath = Path / "user" / "create"
val nonCapturingAllPath = Path / "assets" / "html" / Segment.all
val capturingAllPath = Path / "assets" / "html" / Param.seq
val simplePath = Path / "user" / Param.int.withName("<userId>") / "view"
val pathWithQuery = Path / "user" / "view" :? Query("id", Param.int)

test("Root path unparses to expected Uri") {
assertEquals(
rootPath.unparse(EmptyTuple),
Uri(path = Uri.Path.Root)
)
}

test("Non-capturing path unparses to expected Uri") {
assertEquals(
nonCapturingPath.unparse(EmptyTuple),
Uri(path = Uri.Path.Root / "user" / "create")
)
}

test("Non-capturing all path unparses to expected Uri") {
test("Non-capturing all path unparses to expected Uri"){
assertEquals(
nonCapturingAllPath.unparse(EmptyTuple),
Uri(path = (Uri.Path.Root / "assets" / "html").addEndsWithSlash)
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala/krop/route/Path.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ final class Path[P <: Tuple, Q <: Tuple] private (
}
}

val uriPath = loop(0, segments, Uri.Path.empty)
val uriPath = loop(0, segments, Uri.Path.Root)
Uri(path = uriPath, query = uriQuery)
}

Expand Down

0 comments on commit eceae42

Please sign in to comment.