Skip to content

Commit

Permalink
make ExplicitImplicitsSpec require a type error for all missing impli…
Browse files Browse the repository at this point in the history
…cits
  • Loading branch information
drxcc committed Oct 1, 2018
1 parent 879bb48 commit c0e3cdb
Showing 1 changed file with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,39 @@ class ExplcitImplicitsSpec extends FunSpec with Matchers {
val hist = Histogram(Seq(1, 2, 2))
hist.render().extent shouldBe Plot.defaultExtent
}
it("still provides a mechansim to catch accidental default themes at compile time"){
assertDoesNotCompile("""

it("Provides a mechansim to *require* explicit themes at compile time"){
import com.cibo.evilplot.plot.aesthetics.Theme
object CustomHistogram extends ExplicitImplicits{
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs)(theme).render()(theme)
}
CustomHistogram.hist( Seq(1,2,2) ).extent shouldBe Plot.defaultExtent
}

it("still provides a mechansim to catch accidental default themes at compile time with a type Error"){

assertTypeError("""
import com.cibo.evilplot.plot.aesthetics.Theme
object CustomHistogram extends ExplicitImplicits{
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs).render() // both implicit
}
""")
assertTypeError("""
import com.cibo.evilplot.plot.aesthetics.Theme
object CustomHistogram extends ExplicitImplicits{
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs)(theme).render() // first explicit
}
""")
assertTypeError("""
import com.cibo.evilplot.plot.aesthetics.Theme
object CustomHistogram extends ExplicitImplicits{
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs)().render()(theme) //second explicit
}
""")
assertCompiles("""
import com.cibo.evilplot.plot.aesthetics.Theme
object CustomHistogram extends ExplicitImplicits{
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs).render()(theme)
def hist(xs:Seq[Double])(implicit theme:Theme) = Histogram(xs)(theme).render()(theme) //both explicit
}
""")
}
Expand Down

0 comments on commit c0e3cdb

Please sign in to comment.