Skip to content

Commit

Permalink
Add more Param tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noelwelsh committed Feb 12, 2024
1 parent f9eece8 commit a69882b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions core/jvm/src/test/scala/krop/route/ParamSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ class ParamSuite extends FunSuite {
) =
values.foreach { (str) => assert(param.parse(str).isLeft) }

def paramAllParsesValid[A](
param: Param.All[A],
values: Seq[(Seq[String], A)]
)(using
munit.Location
) =
values.foreach { case (strings, a) =>
assertEquals(param.parse(strings), Right(a))
}

test("Param.one parses valid parameter") {
paramOneParsesValid(
Param.int,
Expand All @@ -49,4 +59,19 @@ class ParamSuite extends FunSuite {
test("Param.one fails to parse invalid parameter") {
paramOneParsesInvalid(Param.int, Seq("a", " ", "xyz"))
}

test("Paral.all parses valid parameters") {
paramAllParsesValid(
Param.seq,
Seq(Seq() -> Seq(), Seq("a", "b", "c") -> Seq("a", "b", "c"))
)
paramAllParsesValid(
Param.mkString(","),
Seq(Seq() -> "", Seq("a") -> "a", Seq("a", "b", "c") -> "a,b,c")
)
paramAllParsesValid(
Param.lift(Param.int),
Seq(Seq() -> Seq(), Seq("1") -> Seq(1), Seq("1", "2", "3") -> Seq(1, 2, 3))
)
}
}

0 comments on commit a69882b

Please sign in to comment.