Skip to content

Commit

Permalink
Change how MD example DSL interpretator prints CheckHttp
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Shashev committed Jul 30, 2023
1 parent ee4a254 commit 0b2ff27
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MarkdownInterpretator[F[_]](printer: String => F[Any], host: String)(impli

def print(desc: ExampleDescription): F[Unit] =
for {
_ <- printer(s"# ${desc.name}\n\n")
_ <- printer(s"## ${desc.name}\n\n")
_ <- desc.steps.foldMap(stepsPrinter)
} yield ()

Expand All @@ -94,19 +94,17 @@ class MarkdownInterpretator[F[_]](printer: String => F[Any], host: String)(impli

case CheckHttp(_, HttpResponseExpected(code, body, headers), _) =>
for {
_ <- code.traverse(c => printer(s"Ответ: \n\n"))
_ <- code.traverse(c => printer(s"Код завершения: `${c.matcher.show}`\n\n"))
_ <- if (headers.isEmpty) M.unit else printer("""Заголовки в ответе:
|```
|""".stripMargin).as(())
_ <- code.traverse(c => printer(s"""Ответ:
|
|```\n""".stripMargin))
_ <- code.traverse(c => printer(s"Код ответа: ${c.matcher.show}\n\n"))
_ <- if (headers.isEmpty) M.unit else printer("Заголовки ответа:\n").as(())
_ <- headers.traverse { case (k, v) => printer(s"$k: '${v.matcher.show}'\n") }
_ <- if (headers.isEmpty) M.unit else printer("```\n\n").as(())
_ <- if (headers.isEmpty) M.unit else printer("\n").as(())
bodyStr = body.map(_.show)
_ <- if (bodyStr.isEmpty) M.unit else printer("""Тело ответа:
|```
|""".stripMargin).as(())
_ <- if (bodyStr.isEmpty) M.unit else printer("Тело ответа:\n").as(())
_ <- bodyStr.fold(M.unit)(s => printer(s ++ "\n").as(()))
_ <- if (bodyStr.isEmpty) M.unit else printer("```\n\n").as(())
_ <- printer("```\n\n").as(())
} yield HttpResponse(
code.fold(0L)(_.matcher.value).toInt,
bodyStr,
Expand Down

0 comments on commit 0b2ff27

Please sign in to comment.