From 70162cda762a6037f7c0f85042b78df05d641d5a Mon Sep 17 00:00:00 2001 From: Scala Steward <43047562+scala-steward@users.noreply.github.com> Date: Fri, 24 Jan 2025 22:25:42 +0100 Subject: [PATCH] Update scalafmt-core to 3.8.6 (#1752) * Update scalafmt-core to 3.8.6 * Reformat with scalafmt 3.8.6 Executed command: scalafmt --non-interactive * Add 'Reformat with scalafmt 3.8.6' to .git-blame-ignore-revs --- .git-blame-ignore-revs | 3 ++ .scalafmt.conf | 2 +- core/src/test/scala/io/finch/BodySpec.scala | 12 ++--- .../test/scala/io/finch/BootstrapSpec.scala | 12 ++--- core/src/test/scala/io/finch/EncodeSpec.scala | 6 +-- .../test/scala/io/finch/EndToEndSpec.scala | 24 ++++------ .../test/scala/io/finch/EndpointSpec.scala | 45 +++++++------------ core/src/test/scala/io/finch/InputSpec.scala | 12 ++--- core/src/test/scala/io/finch/MethodSpec.scala | 33 +++++--------- .../test/scala/io/finch/MultipartSpec.scala | 6 +-- core/src/test/scala/io/finch/OutputSpec.scala | 42 ++++++----------- core/src/test/scala/io/finch/TraceSpec.scala | 6 +-- .../io/finch/internal/HttpContentSpec.scala | 9 ++-- .../test/scala/io/finch/todo/TodoSpec.scala | 3 +- 14 files changed, 74 insertions(+), 141 deletions(-) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 2ecef8b76..f46864d6b 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -3,3 +3,6 @@ # Scala Steward: Reformat with scalafmt 3.8.4 cc2327d46a560d51bfc6d0e417dacd42fe8a8578 + +# Scala Steward: Reformat with scalafmt 3.8.6 +19f7c988f7aa16ab4154220681c654526116afa9 diff --git a/.scalafmt.conf b/.scalafmt.conf index c0859142e..36e94c4ab 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.8.5 +version = 3.8.6 maxColumn = 160 align.preset = some runner.dialect = scala213 diff --git a/core/src/test/scala/io/finch/BodySpec.scala b/core/src/test/scala/io/finch/BodySpec.scala index 2ee7e4c2f..78b8d4ab0 100644 --- a/core/src/test/scala/io/finch/BodySpec.scala +++ b/core/src/test/scala/io/finch/BodySpec.scala @@ -40,19 +40,17 @@ class BodySpec extends FinchSpec[SyncIO] { body[Foo, Text.Plain].apply(Input.fromRequest(req)).isMatched shouldBe false } - it should "respond with a value when present and required" in { + it should "respond with a value when present and required" in check { f: Foo => val i = Input.post("/").withBody[Text.Plain](f) body[Foo, Text.Plain].apply(i).value.unsafeRunSync() === f } - } - it should "respond with Some(value) when it'ss present and optional" in { + it should "respond with Some(value) when it'ss present and optional" in check { f: Foo => val i = Input.post("/").withBody[Text.Plain](f) bodyOption[Foo, Text.Plain].apply(i).value.unsafeRunSync() === Some(f) } - } it should "treat 0-length bodies as empty" in { val i = Input.post("/").withHeaders("Content-Length" -> "0") @@ -62,23 +60,21 @@ class BodySpec extends FinchSpec[SyncIO] { binaryBodyOption.apply(i).value.unsafeRunSync() shouldBe None } - it should "never evaluate until run" in { + it should "never evaluate until run" in check { f: Foo => val i = Input.post("/").withBody[Text.Plain](f) implicit val ed = new EvalDecode[Foo](Decode[Foo, Text.Plain]) textBody[Foo].apply(i) !ed.evaluated } - } - it should "respect Content-Type header and pick corresponding decoder for coproduct" in { + it should "respect Content-Type header and pick corresponding decoder for coproduct" in check { f: Foo => val plain = Input.post("/").withBody[Text.Plain](f) val csv = Input.post("/").withBody[Application.Csv](f) val endpoint = body[Foo, Text.Plain :+: Application.Csv :+: CNil] endpoint(plain).value.unsafeRunSync() === f && endpoint(csv).value.unsafeRunSync() === f } - } it should "resolve into NotParsed(Decode.UMTE) if Content-Type does not match" in { val i = Input.post("/").withBody[Application.Xml](Buf.Utf8("foo")) diff --git a/core/src/test/scala/io/finch/BootstrapSpec.scala b/core/src/test/scala/io/finch/BootstrapSpec.scala index db6a4b6c0..edb158f7d 100644 --- a/core/src/test/scala/io/finch/BootstrapSpec.scala +++ b/core/src/test/scala/io/finch/BootstrapSpec.scala @@ -15,7 +15,7 @@ class BootstrapSpec extends FinchSpec[SyncIO] { private val bootstrap = Bootstrap[SyncIO] - it should "handle both Error and Errors" in { + it should "handle both Error and Errors" in check { e: Either[Error, Errors] => val exception = e.fold[Exception](identity, identity) val ee = liftAsync[Unit](SyncIO.raiseError(exception)) @@ -23,7 +23,6 @@ class BootstrapSpec extends FinchSpec[SyncIO] { rep.status === Status.BadRequest } } - } it should "catch custom exceptions in attempt" in { val exception = new IllegalStateException @@ -33,14 +32,13 @@ class BootstrapSpec extends FinchSpec[SyncIO] { } } - it should "respond 404 if endpoint is not matched" in { + it should "respond 404 if endpoint is not matched" in check { req: Request => val s = bootstrap.serve[Text.Plain](Endpoint[SyncIO].empty[Unit]).compile inside(s(req).unsafeRunSync()) { case (_, Right(rep)) => rep.status === Status.NotFound } } - } it should "respond 405 if method not allowed" in { val a = get("foo")(Ok("get foo")) @@ -76,14 +74,13 @@ class BootstrapSpec extends FinchSpec[SyncIO] { } } - it should "match the request version" in { + it should "match the request version" in check { req: Request => val s = bootstrap.serve[Text.Plain](const(())).compile inside(s(req).unsafeRunSync()) { case (_, Right(rep)) => rep.version === req.version } } - } it should "include Date header" in { val formatter = DateTimeFormatter.RFC_1123_DATE_TIME.withZone(ZoneOffset.UTC) @@ -98,14 +95,13 @@ class BootstrapSpec extends FinchSpec[SyncIO] { } } - it should "include Server header" in { + it should "include Server header" in check { (req: Request, include: Boolean) => val s = bootstrap.configure(includeServerHeader = include).serve[Text.Plain](const(())).compile inside(s(req).unsafeRunSync()) { case (_, Right(rep)) => (include && rep.server === Some("Finch")) || (!include && rep.server.isEmpty) } } - } it should "capture Trace for failures and successes" in check { req: Request => diff --git a/core/src/test/scala/io/finch/EncodeSpec.scala b/core/src/test/scala/io/finch/EncodeSpec.scala index 3c3cf0b3f..b188e9d90 100644 --- a/core/src/test/scala/io/finch/EncodeSpec.scala +++ b/core/src/test/scala/io/finch/EncodeSpec.scala @@ -14,17 +14,15 @@ class EncodeSpec extends FinchSpec[Id] { checkAll("Encode.Text[List[Long]]", EncodeLaws.text[List[Long]].all) checkAll("Encode.Text[Either[UUID, Float]]", EncodeLaws.text[Either[UUID, Float]].all) - it should "round trip Unit" in { + it should "round trip Unit" in check { cs: Charset => implicitly[Encode[Unit]].apply((), cs) === Buf.Empty } - } - it should "round trip Buf" in { + it should "round trip Buf" in check { (cs: Charset, buf: Buf) => implicitly[Encode[Buf]].apply(buf, cs) === buf } - } it should "encode exceptions" in check { (s: String, cs: Charset) => diff --git a/core/src/test/scala/io/finch/EndToEndSpec.scala b/core/src/test/scala/io/finch/EndToEndSpec.scala index 38782a95c..e3f5f58ab 100644 --- a/core/src/test/scala/io/finch/EndToEndSpec.scala +++ b/core/src/test/scala/io/finch/EndToEndSpec.scala @@ -65,33 +65,30 @@ class EndToEndSpec extends FinchSpec[IO] { } } - it should "convert value Endpoints into Services" in { + it should "convert value Endpoints into Services" in testService[Text.Plain](get("foo")(Created("bar"))) { s => val rep = Await.result(s(Request("/foo"))) rep.contentString shouldBe "bar" rep.status shouldBe Status.Created } - } - it should "ignore Accept header when single type is used for serve" in { + it should "ignore Accept header when single type is used for serve" in testService[Text.Plain](pathAny) { service => check { req: Request => val rep = Await.result(service(req)) rep.contentType === Some("text/plain") } } - } - it should "respect Accept header when coproduct type is used for serve" in { + it should "respect Accept header when coproduct type is used for serve" in testService[AllContentTypes](pathAny) { s => check { req: Request => val rep = Await.result(s(req)) rep.contentType === req.accept.headOption } } - } - it should "ignore order of values in Accept header and use first appropriate encoder in coproduct" in { + it should "ignore order of values in Accept header and use first appropriate encoder in coproduct" in testService[AllContentTypes](pathAny) { s => check { (req: Request, accept: Accept) => val a = s"${accept.primary}/${accept.sub}" @@ -103,9 +100,8 @@ class EndToEndSpec extends FinchSpec[IO] { rep.contentType === first } } - } - it should "select last encoder when Accept header is missing/empty" in { + it should "select last encoder when Accept header is missing/empty" in testService[AllContentTypes](pathAny) { s => check { req: Request => req.headerMap.remove(Fields.Accept) @@ -113,9 +109,8 @@ class EndToEndSpec extends FinchSpec[IO] { rep.contentType === Some("text/event-stream") } } - } - it should "select last encoder when Accept header value doesn't match any existing encoder" in { + it should "select last encoder when Accept header value doesn't match any existing encoder" in testService[AllContentTypes](pathAny) { s => check { (req: Request, accept: Accept) => req.accept = s"${accept.primary}/foo" @@ -123,7 +118,6 @@ class EndToEndSpec extends FinchSpec[IO] { rep.contentType === Some("text/event-stream") } } - } it should "return the exception occurred in endpoint's effect" in { val endpoint = pathAny.mapAsync { _ => @@ -135,7 +129,7 @@ class EndToEndSpec extends FinchSpec[IO] { } } - it should "fail with 406 Not Acceptable on Content-Type negotiation failure when enabled" in { + it should "fail with 406 Not Acceptable on Content-Type negotiation failure when enabled" in testService[AllContentTypes](pathAny, _.configure(enableNotAcceptable = true)) { s => check { (req: Request, accept: List[Accept]) => req.accept = accept.map(_.primary + "/foo") @@ -143,9 +137,8 @@ class EndToEndSpec extends FinchSpec[IO] { rep.status === Status.NotAcceptable } } - } - it should "fail with 406 Not Acceptable on Content-Type mismatch when enabled" in { + it should "fail with 406 Not Acceptable on Content-Type mismatch when enabled" in testService[Text.Plain](pathAny, _.configure(enableNotAcceptable = true)) { s => check { (req: Request, accept: Accept) => req.accept = accept.primary + "/foo" @@ -153,7 +146,6 @@ class EndToEndSpec extends FinchSpec[IO] { rep.status === Status.NotAcceptable } } - } it should "succeed when there is no Accept header even though Not Acceptable is enabled" in testService[Text.Plain](pathAny, _.configure(enableNotAcceptable = true)) { s => diff --git a/core/src/test/scala/io/finch/EndpointSpec.scala b/core/src/test/scala/io/finch/EndpointSpec.scala index 651d0243e..2ab001fc5 100644 --- a/core/src/test/scala/io/finch/EndpointSpec.scala +++ b/core/src/test/scala/io/finch/EndpointSpec.scala @@ -36,39 +36,34 @@ class EndpointSpec extends FinchSpec[SyncIO] { private[this] val emptyRequest = Request() - it should "support very basic map" in { + it should "support very basic map" in check { i: Input => path[String].map(_ * 2).apply(i).valueOption.unsafeRunSync() === i.route.headOption.map(_ * 2) } - } - it should "correctly run transform" in { + it should "correctly run transform" in check { e: EndpointIO[String] => val fn: String => Int = _.length e.transform(_.map(fn)) <-> e.map(fn) } - } - it should "support transformOutput" in { + it should "support transformOutput" in check { i: Input => val fn = (fs: SyncIO[Output[String]]) => fs.map(_.map(_ * 2)) path[String].transformOutput(fn).apply(i).valueOption.unsafeRunSync() === i.route.headOption.map(_ * 2) } - } - it should "propagate the default (Ok) output" in { + it should "propagate the default (Ok) output" in check { i: Input => path[String].apply(i).outputOption.unsafeRunSync() === i.route.headOption.map(Ok) } - } - it should "propagate the default (Ok) output through its map'd/mapAsync'd version" in { + it should "propagate the default (Ok) output through its map'd/mapAsync'd version" in check { i: Input => val expected = i.route.headOption.map(s => Ok(s.length)) path[String].map(s => s.length).apply(i).outputOption.unsafeRunSync() === expected && path[String].mapAsync(s => SyncIO.pure(s.length)).apply(i).outputOption.unsafeRunSync() === expected } - } it should "propagate the output through mapOutputAsync and /" in { def expected(i: Int): Output[Int] = @@ -86,25 +81,22 @@ class EndpointSpec extends FinchSpec[SyncIO] { } } - it should "match one patch segment" in { + it should "match one patch segment" in check { i: Input => val v = i.route.headOption.flatMap(s => path(s).apply(i).remainder) v.isEmpty || v === Some(i.withRoute(i.route.tail)) } - } - it should "always match the entire input with *" in { + it should "always match the entire input with *" in check { i: Input => pathAny.apply(i).remainder === Some(i.copy(route = Nil)) } - } - it should "match empty path" in { + it should "match empty path" in check { i: Input => (i.route.isEmpty && pathEmpty.apply(i).isMatched) || (i.route.nonEmpty && !pathEmpty.apply(i).isMatched) } - } it should "match the HTTP method" in { def matchMethod(m: Method, f: EndpointIO[HNil] => EndpointIO[HNil]): Input => Boolean = { i: Input => @@ -123,24 +115,21 @@ class EndpointSpec extends FinchSpec[SyncIO] { check(matchMethod(Method.Delete, delete)) } - it should "always match the identity instance" in { + it should "always match the identity instance" in check { i: Input => zero.apply(i).remainder === Some(i) } - } - it should "match the entire input" in { + it should "match the entire input" in check { i: Input => val e = i.route.map(s => path(s)).foldLeft[EndpointIO[HNil]](zero)((acc, e) => acc :: e) e(i).remainder === Some(i.copy(route = Nil)) } - } - it should "not match the entire input if one of the underlying endpoints is failed" in { + it should "not match the entire input if one of the underlying endpoints is failed" in check { (i: Input, s: String) => (pathAny :: s).apply(i).remainder === None } - } it should "match the input if one of the endpoints succeed" in { def matchOneOfTwo(f: String => EndpointIO[HNil]): Input => Boolean = { i: Input => @@ -223,11 +212,10 @@ class EndpointSpec extends FinchSpec[SyncIO] { } } - it should "rescue the exception occurred in it" in { + it should "rescue the exception occurred in it" in check { (i: Input, s: String, e: Exception) => liftAsync[String](SyncIO.raiseError(e)).handle { case _ => Created(s) }.apply(i).outputAttempt.unsafeRunSync() === Right(Created(s)) } - } it should "re-raise the exception if it wasn't handled" in { case object CustomException extends Exception @@ -301,7 +289,7 @@ class EndpointSpec extends FinchSpec[SyncIO] { e2(b).remainder shouldBe Some(b.withRoute(b.route.drop(2))) } - it should "accumulate errors on its product" in { + it should "accumulate errors on its product" in check { (a: Either[Error, Errors], b: Either[Error, Errors]) => val aa = a.fold[Exception](identity, identity) val bb = b.fold[Exception](identity, identity) @@ -323,9 +311,8 @@ class EndpointSpec extends FinchSpec[SyncIO] { second.asInstanceOf[Errors].errors.iterator.toSet === all } } - } - it should "fail-fast with the first non-error observed" in { + it should "fail-fast with the first non-error observed" in check { (a: Error, b: Errors, e: Exception) => val aa = liftAsync[Unit](SyncIO.raiseError(a)) val bb = liftAsync[Unit](SyncIO.raiseError(b)) @@ -342,7 +329,6 @@ class EndpointSpec extends FinchSpec[SyncIO] { bbee(Input.get("/")).valueAttempt.unsafeRunSync() === Left(e) && eebb(Input.get("/")).valueAttempt.unsafeRunSync() === Left(e) } - } it should "accumulate EndpointResult.NotMatched in its | compositor" in { val a = get("foo") @@ -396,13 +382,12 @@ class EndpointSpec extends FinchSpec[SyncIO] { r(Input.get("/test.txt")).value.unsafeRunSync() shouldBe Buf.Utf8("foo bar baz\n") } - it should "wrap up an exception thrown inside mapOutputs function" in { + it should "wrap up an exception thrown inside mapOutputs function" in check { (ep: EndpointIO[Int], p: Output.Payload[Int], e: Exception) => val mappedEndpoint = ep.mapOutput[Int](_ => throw e) val asFunction = mappedEndpoint.asInstanceOf[Output[Int] => SyncIO[Output[Int]]] asFunction.apply(p).attempt.unsafeRunSync() === Left(e) } - } it should "transform F[_] to G[_] effect" in { type W[A] = WriterT[SyncIO, List[String], A] diff --git a/core/src/test/scala/io/finch/InputSpec.scala b/core/src/test/scala/io/finch/InputSpec.scala index 5c9c96985..b4c32bdc4 100644 --- a/core/src/test/scala/io/finch/InputSpec.scala +++ b/core/src/test/scala/io/finch/InputSpec.scala @@ -37,11 +37,10 @@ class InputSpec extends FinchSpec[IO] { } } - it should "add fully-buffered content via withBody" in { + it should "add fully-buffered content via withBody" in check { (i: Input, b: Buf) => i.withBody[Text.Plain](b).request.content === b } - } it should "add chunked content via withBody" in { type ListStream[F[_], A] = List[A] @@ -69,23 +68,21 @@ class InputSpec extends FinchSpec[IO] { } } - it should "add content corresponding to a class through withBody[JSON]" in { + it should "add content corresponding to a class through withBody[JSON]" in check { (i: Input, f: Foo, cs: Charset) => val input = i.withBody[Application.Json](f, cs) input.request.content.asString(cs) === s"""{s:"${f.s}"""" && input.request.contentType === Some(s"application/json;charset=${cs.displayName.toLowerCase}") } - } - it should "add headers through withHeaders" in { + it should "add headers through withHeaders" in check { (i: Input, hs: Headers) => val hm = i.withHeaders(hs.m.toSeq: _*).request.headerMap hs.m.forall { case (k, v) => hm.contains(k) && hm(k) === v } } - } - it should "add form elements through withForm" in { + it should "add form elements through withForm" in check { (i: Input, ps: Params) => ps.p.isEmpty || { val input = i.withForm(ps.p.toSeq: _*) @@ -94,7 +91,6 @@ class InputSpec extends FinchSpec[IO] { input.request.contentType === Some("application/x-www-form-urlencoded;charset=utf-8") } } - } it should "parse route correctly" in check { i: Input => diff --git a/core/src/test/scala/io/finch/MethodSpec.scala b/core/src/test/scala/io/finch/MethodSpec.scala index 5aa060268..fadfe44af 100644 --- a/core/src/test/scala/io/finch/MethodSpec.scala +++ b/core/src/test/scala/io/finch/MethodSpec.scala @@ -12,49 +12,38 @@ class MethodSpec extends FinchSpec[SyncIO] { implicit val arbResponse: Arbitrary[Response] = Arbitrary(genOutput[String].map(_.toResponse[Id, Text.Plain])) - it should "map Output value to endpoint" in { + it should "map Output value to endpoint" in checkValue((i: String) => get(zero)(Ok(i))) - } - it should "map Response value to endpoint" in { + it should "map Response value to endpoint" in checkValue((i: Response) => get(zero)(i)) - } - it should "map F[Output[A]] value to endpoint" in { + it should "map F[Output[A]] value to endpoint" in checkValue((i: String) => get(zero)(SyncIO.pure(Ok(i)))) - } - it should "map F[Response] value to endpoint" in { + it should "map F[Response] value to endpoint" in checkValue((i: Response) => get(zero)(SyncIO.pure(Ok(i).toResponse[Id, Text.Plain]))) - } - it should "map A => Output function to endpoint" in { + it should "map A => Output function to endpoint" in checkFunction(get(path[Int]) { i: Int => Ok(i) }) - } - it should "map A => Response function to endpoint" in { + it should "map A => Response function to endpoint" in checkFunction(get(path[Int]) { i: Int => Ok(i).toResponse[Id, Text.Plain] }) - } - it should "map A => F[Output[A]] function to endpoint" in { + it should "map A => F[Output[A]] function to endpoint" in checkFunction(get(path[Int]) { i: Int => SyncIO.pure(i).map(Ok) }) - } - it should "map A => F[Response] function to endpoint" in { + it should "map A => F[Response] function to endpoint" in checkFunction(get(path[Int]) { i: Int => SyncIO.pure(i).map(Ok(_).toResponse[Id, Text.Plain]) }) - } - it should "map (A, B) => Output function to endpoint" in { + it should "map (A, B) => Output function to endpoint" in checkFunction2(get(path[Int] :: path[Int])((x: Int, y: Int) => Ok(s"$x$y"))) - } - it should "map (A, B) => Response function to endpoint" in { + it should "map (A, B) => Response function to endpoint" in checkFunction2(get(path[Int] :: path[Int])((x: Int, y: Int) => Ok(s"$x$y").toResponse[Id, Text.Plain])) - } - it should "map (A, B) => F[Output[String]] function to endpoint" in { + it should "map (A, B) => F[Output[String]] function to endpoint" in checkFunction2(get(path[Int] :: path[Int])((x: Int, y: Int) => SyncIO.pure(Ok(s"$x$y")))) - } it should "map (A, B) => F[Response] function to endpoint" in checkFunction2(get(path[Int] :: path[Int]) { (x: Int, y: Int) => diff --git a/core/src/test/scala/io/finch/MultipartSpec.scala b/core/src/test/scala/io/finch/MultipartSpec.scala index adf17ab91..6296966fb 100644 --- a/core/src/test/scala/io/finch/MultipartSpec.scala +++ b/core/src/test/scala/io/finch/MultipartSpec.scala @@ -43,7 +43,7 @@ class MultipartSpec extends FinchSpec[SyncIO] { EvaluatingEndpointLaws[SyncIO, String](implicit de => multipartAttribute("foo")).all ) - it should "file upload (single)" in { + it should "file upload (single)" in check { b: Buf => val i = withFileUpload("foo", b) val fu = multipartFileUpload("foo").apply(i).valueOption.unsafeRunSync() @@ -52,7 +52,6 @@ class MultipartSpec extends FinchSpec[SyncIO] { fu.map(_.asInstanceOf[Multipart.InMemoryFileUpload].content) === Some(b) && fuo.map(_.asInstanceOf[Multipart.InMemoryFileUpload].content) === Some(b) } - } it should "fail when attribute is missing" in { an[Error.NotPresent] should be thrownBy @@ -68,9 +67,8 @@ class MultipartSpec extends FinchSpec[SyncIO] { multipartAttributesNel("foo").apply(Input.get("/")).value.unsafeRunSync() } - it should "return empty sequence when attributes are missing for seq endpoint" in { + it should "return empty sequence when attributes are missing for seq endpoint" in multipartAttributes("foo").apply(Input.get("/")).valueOption.unsafeRunSync() === Some(Seq()) - } it should "fail when attribute is malformed" in { an[Error.NotParsed] should be thrownBy diff --git a/core/src/test/scala/io/finch/OutputSpec.scala b/core/src/test/scala/io/finch/OutputSpec.scala index f3615c78a..9af1facbc 100644 --- a/core/src/test/scala/io/finch/OutputSpec.scala +++ b/core/src/test/scala/io/finch/OutputSpec.scala @@ -11,36 +11,31 @@ class OutputSpec extends FinchSpec[Id] { behavior of "Output" - it should "propagate status to response" in { + it should "propagate status to response" in check { o: Output[String] => o.toResponse[Id, Text.Plain].status == o.status } - } - it should "propagate overridden status to response" in { + it should "propagate overridden status to response" in check { (o: Output[String], s: Status) => o.withStatus(s).toResponse[Id, Text.Plain].status === s } - } - it should "propagate charset to response" in { + it should "propagate charset to response" in check { (o: Output[String], cs: Charset) => val rep = o.withCharset(cs).toResponse[Id, Text.Plain] (rep.content.isEmpty && !rep.isChunked) || Some(cs.displayName.toLowerCase) === rep.charset } - } - it should "propagate headers to response" in { + it should "propagate headers to response" in check { (o: Output[String], headers: Headers) => val rep = headers.m.foldLeft(o)((acc, h) => acc.withHeader(h._1 -> h._2)).toResponse[Id, Text.Plain] headers.m.forall(h => rep.headerMap(h._1) === h._2) } - } - it should "propagate cookies to response" in { + it should "propagate cookies to response" in check { (o: Output[String], cookies: Cookies) => val rep = cookies.c.foldLeft(o)((acc, c) => acc.withCookie(c)).toResponse[Id, Text.Plain] cookies.c.forall(c => rep.cookies(c.name) === c) } - } it should "set the corresponding status while predefined smart constructors are used" in { val cause = new Exception @@ -73,67 +68,58 @@ class OutputSpec extends FinchSpec[Id] { InsufficientStorage(cause).status shouldBe Status.InsufficientStorage } - it should "propagate cause to response" in { + it should "propagate cause to response" in check { of: Output.Failure => (of: Output[Unit]).toResponse[Id, Text.Plain].content === Encode[Exception, Text.Plain].apply(of.cause, of.charset.getOrElse(StandardCharsets.UTF_8)) } - } - it should "propagate empytiness to response" in { + it should "propagate empytiness to response" in check { of: Output.Empty => (of: Output[Unit]).toResponse[Id, Text.Plain].content === Buf.Empty } - } - it should "propagate payload to response" in { + it should "propagate payload to response" in check { op: Output.Payload[String] => op.toResponse[Id, Text.Plain].content === Encode[String, Text.Plain].apply(op.value, op.charset.getOrElse(StandardCharsets.UTF_8)) } - } - it should "create an empty endpoint with given status when calling unit" in { + it should "create an empty endpoint with given status when calling unit" in check { s: Status => Output.unit(s).toResponse[Id, Text.Plain].status === s } - } - it should "throw an exception on calling value on an Empty output" in { + it should "throw an exception on calling value on an Empty output" in check { e: Output.Empty => Try(e.value) match { case Failure(f) => f.getMessage === "empty output" case _ => false } } - } - it should "throw an exception on calling value on a Failure output" in { + it should "throw an exception on calling value on a Failure output" in check { f: Output.Failure => Try(f.value) match { case Failure(ex) => ex.getMessage === f.cause.getMessage case _ => false } } - } - it should "check equivalences of arbitrary string outputs" in { + it should "check equivalences of arbitrary string outputs" in check { (oa: Output[String], ob: Output[String]) => Output.outputEq[String].eqv(oa, ob) === (oa == ob) } - } - it should "check equivalences of empty outputs" in { + it should "check equivalences of empty outputs" in check { (ea: Output.Empty, eb: Output.Empty) => Output.outputEq[String].eqv(ea, eb) === (ea == eb) } - } - it should "check equivalences of failure outputs" in { + it should "check equivalences of failure outputs" in check { (fa: Output.Failure, fb: Output.Failure) => Output.outputEq[String].eqv(fa, fb) === (fa == fb) } - } it should "traverse arbitrary outputs" in check { oa: Output[String] => diff --git a/core/src/test/scala/io/finch/TraceSpec.scala b/core/src/test/scala/io/finch/TraceSpec.scala index 2d3b76cb5..dd6786410 100644 --- a/core/src/test/scala/io/finch/TraceSpec.scala +++ b/core/src/test/scala/io/finch/TraceSpec.scala @@ -6,18 +6,16 @@ class TraceSpec extends FinchSpec[Id] { behavior of "Trace" - it should "round-trip concat/toList" in { + it should "round-trip concat/toList" in check { l: List[String] => val trace = l.foldLeft(Trace.empty)((t, s) => t.concat(Trace.segment(s))) trace.toList === l } - } - it should "concat two non-empty segments correctly" in { + it should "concat two non-empty segments correctly" in check { (a: Trace, b: Trace) => a.concat(b).toList === (a.toList ++ b.toList) } - } it should "create fromRoute" in check { l: List[String] => diff --git a/core/src/test/scala/io/finch/internal/HttpContentSpec.scala b/core/src/test/scala/io/finch/internal/HttpContentSpec.scala index ae241985f..d846c56d1 100644 --- a/core/src/test/scala/io/finch/internal/HttpContentSpec.scala +++ b/core/src/test/scala/io/finch/internal/HttpContentSpec.scala @@ -10,24 +10,21 @@ class HttpContentSpec extends FinchSpec[Id] { behavior of "HttpContet" - it should "asByteArrayWithBeginAndEnd" in { + it should "asByteArrayWithBeginAndEnd" in check { b: Buf => val (array, begin, end) = b.asByteArrayWithBeginAndEnd Buf.ByteArray.Owned.extract(b) === array.slice(begin, end) } - } - it should "asByteBuffer" in { + it should "asByteBuffer" in check { b: Buf => b.asByteBuffer === Buf.ByteBuffer.Owned.extract(b) } - } - it should "asByteArray" in { + it should "asByteArray" in check { b: Buf => b.asByteArray === Buf.ByteArray.Owned.extract(b) } - } it should "asString" in check { (b: Buf, cs: Charset) => diff --git a/examples/src/test/scala/io/finch/todo/TodoSpec.scala b/examples/src/test/scala/io/finch/todo/TodoSpec.scala index b234d9ae5..c04f2d546 100644 --- a/examples/src/test/scala/io/finch/todo/TodoSpec.scala +++ b/examples/src/test/scala/io/finch/todo/TodoSpec.scala @@ -49,7 +49,7 @@ class TodoSpec extends AnyFlatSpec with Matchers with Checkers { implicit def arbitraryTodoCompleted: Arbitrary[TodoCompleted] = Arbitrary(Arbitrary.arbBool.arbitrary.map(TodoCompleted)) - it should "post a todo" in { + it should "post a todo" in check { (app: TestApp, todo: TodoTitle) => val input = Input.post("/todos").withBody[Application.Json](todo) @@ -63,7 +63,6 @@ class TodoSpec extends AnyFlatSpec with Matchers with Checkers { shouldBeTrue.unsafeRunSync() } - } it should "patch a todo" in check { (app: TestApp, todo: TodoCompleted) =>