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

Rudimentary XML generator and round-trip test #30

Merged
merged 2 commits into from
Jun 16, 2022
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
17 changes: 11 additions & 6 deletions scala-xml/src/test/scala/org/http4s/scalaxml/ScalaXmlSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ import fs2.Stream
import fs2.text.decodeWithCharset
import fs2.text.utf8
import munit.CatsEffectSuite
import munit.ScalaCheckSuite
import munit.ScalaCheckEffectSuite
import org.http4s.Status.Ok
import org.http4s.headers.`Content-Type`
import org.http4s.laws.discipline.arbitrary._
import org.http4s.scalaxml.generators._
import org.scalacheck.Prop._
import org.scalacheck.effect.PropF._
import org.typelevel.ci._

import java.nio.charset.StandardCharsets
import scala.xml.Elem

class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckEffectSuite {
def getBody(body: EntityBody[IO]): IO[String] =
body.through(utf8.decode).foldMonoid.compile.lastOrError

Expand All @@ -56,10 +58,13 @@ class ScalaXmlSuite extends CatsEffectSuite with ScalaCheckSuite {
}
}

test("xml should parse the XML") {
server(Request[IO](body = strBody("<html><h1>h1</h1></html>")))
.flatMap(r => getBody(r.body))
.assertEquals("html")
test("round trips utf-8") {
forAllF(genXml) { (elem: Elem) =>
Request[IO]()
.withEntity(elem)
.as[Elem]
.assertEquals(elem)
}
}

test("parse XML in parallel") {
Expand Down
Loading