From 215b1548aff85e2e59b4905f8552e306e50fc03b Mon Sep 17 00:00:00 2001 From: Matt Farmer Date: Sat, 17 Aug 2024 22:13:43 -0400 Subject: [PATCH] Iterating on tests --- core/src/test/scala/iterable.scala | 5 +++-- core/src/test/scala/retry.scala | 12 ++++++------ json4sjackson/src/test/scala/json.scala | 7 +++++-- json4snative/src/test/scala/json.scala | 8 ++++++-- jsoup/src/test/scala/soup.scala | 2 +- project/common.scala | 2 +- tagsoup/src/test/scala/soup.scala | 2 +- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/core/src/test/scala/iterable.scala b/core/src/test/scala/iterable.scala index 1f002baf..512f609d 100644 --- a/core/src/test/scala/iterable.scala +++ b/core/src/test/scala/iterable.scala @@ -47,13 +47,14 @@ with DispatchCleanup { property("iterable future values") = forAll(Gen.alphaStr) { (sampleL: String) => - val sample = sampleL.take(10) // n^2 concurrent requests + val sample: String = sampleL.take(10) // n^2 concurrent requests val values: Future[Iterable[(Int,Int)]] = for { chr1 <- split(sample).values.flatten chr2 <- split(sample.reverse).values c1 <- value(chr1) c2 <- value(chr2) } yield (c1, c2) + values() ?= (for { c1 <- sample c2 <- sample.reverse @@ -67,7 +68,7 @@ with DispatchCleanup { chr1 <- split(sample).either.right.values c1 <- value(chr1) } yield Right(c1) - values().right.get ?= (for { + values().toOption.get ?= (for { c1 <- sample } yield c1.toInt) } diff --git a/core/src/test/scala/retry.scala b/core/src/test/scala/retry.scala index c3640937..f6b166b4 100644 --- a/core/src/test/scala/retry.scala +++ b/core/src/test/scala/retry.scala @@ -42,7 +42,7 @@ with DispatchCleanup { def succeedOn(successRetry: Int)() = { Http.default(localhost << Map("echo" -> retried.getAndIncrement.toString) OK as.String).either.map { eth => - eth.right.flatMap { numstr => + eth.flatMap { numstr => val num = numstr.toInt if (num == successRetry) Right(num) @@ -55,19 +55,19 @@ with DispatchCleanup { property("succeed on the first request") = forAll(smallNums) { maxRetries => val rc = new RetryCounter - val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0)) + val p = retry.Backoff(maxRetries)(() => rc.succeedOn(0)()) p() ?= Right(0) } property("succeed on the max retry") = forAll(smallNums) { maxRetries => val rc = new RetryCounter - val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries)) + val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries)()) p() ?= Right(maxRetries) } property("fail after max retries") = forAll(smallNums) { maxRetries => val rc = new RetryCounter - val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1)) + val p = retry.Directly(maxRetries)(() => rc.succeedOn(maxRetries + 1)()) p() ?= Left(maxRetries) } @@ -76,7 +76,7 @@ with DispatchCleanup { val p = retry.Backoff( max, Duration(2, TimeUnit.MICROSECONDS) - )(() => rc.succeedOn(max)) + )(() => rc.succeedOn(max)()) p() ?= Right(max) } @@ -85,7 +85,7 @@ with DispatchCleanup { val p = retry.Pause( max, Duration(500, TimeUnit.MICROSECONDS) - )(() => rc.succeedOn(max + 1)) + )(() => rc.succeedOn(max + 1)()) p() ?= Left(max) } } diff --git a/json4sjackson/src/test/scala/json.scala b/json4sjackson/src/test/scala/json.scala index 7df34cc3..29db43e1 100644 --- a/json4sjackson/src/test/scala/json.scala +++ b/json4sjackson/src/test/scala/json.scala @@ -30,7 +30,7 @@ with DispatchCleanup { object In extends Params.Extract("in", Params.first) netty.Server.local(port).handler(netty.cycle.Planify { - case Params(In(in)) => Json(("out" -> in)) + case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]] }).start() } @@ -42,6 +42,9 @@ with DispatchCleanup { val res = Http.default( localhost <:< Map("Accept" -> "application/json") < sample) > as.json4s.Json ) - sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head + sample == (for { + case JObject(fields) <- res() + case JField("out", JString(o)) <- fields + } yield o).head } } diff --git a/json4snative/src/test/scala/json.scala b/json4snative/src/test/scala/json.scala index d364078d..f808c0e8 100644 --- a/json4snative/src/test/scala/json.scala +++ b/json4snative/src/test/scala/json.scala @@ -1,6 +1,7 @@ package dispatch.spec import org.scalacheck._ +import org.scalacheck.util.Pretty.prettyAny object BasicSpecification extends Properties("Json4s Native Json") @@ -30,7 +31,7 @@ with DispatchCleanup { object In extends Params.Extract("in", Params.first) netty.Server.local(port).handler(netty.cycle.Planify { - case Params(In(in)) => Json(("out" -> in)) + case Params(In(in)) => Json(("out" -> in)).asInstanceOf[ComposeResponse[io.netty.handler.codec.http.HttpResponse]] }).start() } @@ -42,6 +43,9 @@ with DispatchCleanup { val res = Http.default( localhost <:< Map("Accept" -> "application/json") < sample) > as.json4s.Json ) - sample == (for { JObject(fields) <- res(); JField("out", JString(o)) <- fields } yield o).head + sample == (for { + case JObject(fields) <- res() + case JField("out", JString(o)) <- fields + } yield o).head } } diff --git a/jsoup/src/test/scala/soup.scala b/jsoup/src/test/scala/soup.scala index 98de7e5e..6041abd5 100644 --- a/jsoup/src/test/scala/soup.scala +++ b/jsoup/src/test/scala/soup.scala @@ -25,7 +25,7 @@ with DispatchCleanup { object Echo extends Params.Extract("echo", Params.first) netty.Server.local(port).handler(netty.cycle.Planify { case Path("/echo") & Params(Echo(echo)) => - Html(
{echo}
) + ResponseString(Html(
{echo}
).toString()) case Path("/unclean") & Params(Echo(echo)) => HtmlContent ~> ResponseString(UnsafeFormat format echo) case Path("/relative") & Params(Echo(echo)) => diff --git a/project/common.scala b/project/common.scala index 40af07f8..fcfc8ab1 100644 --- a/project/common.scala +++ b/project/common.scala @@ -3,7 +3,7 @@ import sbt._ object Common { import Keys._ - val defaultScalaVersion = "2.13.14" + val defaultScalaVersion = "3.4.2" val testSettings:Seq[Setting[_]] = Seq( Test / testOptions += Tests.Cleanup { loader => diff --git a/tagsoup/src/test/scala/soup.scala b/tagsoup/src/test/scala/soup.scala index e3907ce7..b2010fdf 100644 --- a/tagsoup/src/test/scala/soup.scala +++ b/tagsoup/src/test/scala/soup.scala @@ -15,7 +15,7 @@ with DispatchCleanup { object Echo extends Params.Extract("echo", Params.first) netty.Server.local(port).handler(netty.cycle.Planify { case Path("/echo") & Params(Echo(echo)) => - Html(
{echo}
) + ResponseString(Html(
{echo}
).toString()) }).start() }