Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scalafmt-core to 3.8.6 #1752

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# Scala Steward: Reformat with scalafmt 3.8.4
cc2327d46a560d51bfc6d0e417dacd42fe8a8578

# Scala Steward: Reformat with scalafmt 3.8.6
19f7c988f7aa16ab4154220681c654526116afa9
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.8.5
version = 3.8.6
maxColumn = 160
align.preset = some
runner.dialect = scala213
Expand Down
12 changes: 4 additions & 8 deletions core/src/test/scala/io/finch/BodySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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"))
Expand Down
12 changes: 4 additions & 8 deletions core/src/test/scala/io/finch/BootstrapSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ 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))
inside(bootstrap.serve[Text.Plain](ee).compile.apply(Request()).unsafeRunSync()) { case (_, Right(rep)) =>
rep.status === Status.BadRequest
}
}
}

it should "catch custom exceptions in attempt" in {
val exception = new IllegalStateException
Expand All @@ -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"))
Expand Down Expand Up @@ -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)
Expand All @@ -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 =>
Expand Down
6 changes: 2 additions & 4 deletions core/src/test/scala/io/finch/EncodeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
24 changes: 8 additions & 16 deletions core/src/test/scala/io/finch/EndToEndSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -103,27 +100,24 @@ 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)
val rep = Await.result(s(req))
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"
val rep = Await.result(s(req))
rep.contentType === Some("text/event-stream")
}
}
}

it should "return the exception occurred in endpoint's effect" in {
val endpoint = pathAny.mapAsync { _ =>
Expand All @@ -135,25 +129,23 @@ 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")
val rep = Await.result(s(req))
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"
val rep = Await.result(s(req))
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 =>
Expand Down
45 changes: 15 additions & 30 deletions core/src/test/scala/io/finch/EndpointSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand All @@ -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 =>
Expand All @@ -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 =>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand All @@ -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")
Expand Down Expand Up @@ -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]
Expand Down
Loading
Loading