Skip to content

Commit

Permalink
Added implicit conversion from Unit to Html
Browse files Browse the repository at this point in the history
  • Loading branch information
nartamonov committed Apr 13, 2022
1 parent 0d840bb commit 4da0615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions zio-http/src/main/scala/zhttp/html/Html.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package zhttp.html

import scala.annotation.nowarn
import scala.language.implicitConversions

/**
Expand All @@ -22,6 +23,8 @@ object Html {

implicit def fromDomElement(element: Dom): Html = Html.Single(element)

implicit def fromUnit(@nowarn unit: Unit): Html = Html.Empty

private[zhttp] case class Single(element: Dom) extends Html

private[zhttp] final case class Multiple(children: Seq[Dom]) extends Html
Expand Down
8 changes: 7 additions & 1 deletion zio-http/src/test/scala/zhttp/html/HtmlSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ case object HtmlSpec extends DefaultRunnableSpec {
val view = div("Hello!", css := "container" :: Nil)
val expected = """<div class="container">Hello!</div>"""
assert(view.encode)(equalTo(expected.stripMargin))
},
} +
suite("implicit conversions")(
test("from unit") {
val view: Html = {}
assert(view.encode)(equalTo(""))
},
),
)
}
}

0 comments on commit 4da0615

Please sign in to comment.