Skip to content

Commit

Permalink
Use illTyped in tests where appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
milessabin committed Aug 15, 2013
1 parent 6380a31 commit 0a9abd5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 14 deletions.
27 changes: 21 additions & 6 deletions core/src/test/scala/shapeless/hlistconstraints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package shapeless
import org.junit.Test
import org.junit.Assert._

import shapeless.test.illTyped

class HListConstraintsTests {
@Test
def testUnaryTCConstraint {
Expand All @@ -31,7 +33,10 @@ class HListConstraintsTests {
val l2 = Option(23) :: true :: Option("foo") :: HNil

acceptOption(l1) // Compiles
//acceptOption(l2) // Does not compile

illTyped("""
acceptOption(l2)
""")

val l3 = 23 :: true :: "foo" :: HNil

Expand All @@ -45,7 +50,9 @@ class HListConstraintsTests {
def acceptConst[L <: HList : *->*[Const[String]#λ]#λ](l : L) = true

acceptConst(l4) // Compiles
//acceptConst(l5) // Does not compile
illTyped("""
acceptConst(l5)
""")
}

@Test
Expand All @@ -60,7 +67,9 @@ class HListConstraintsTests {
val l2 = 23 :: true :: 13 :: 7 :: 5 :: 2.0 :: "foo" :: "bar" :: HNil

acceptBasis(l1) // Compiles
//acceptBasis(l2) // Does not compile
illTyped("""
acceptBasis(l2)
""")
}

@Test
Expand All @@ -77,7 +86,9 @@ class HListConstraintsTests {
val l2 = Apple :: 23 :: "foo" :: Pear :: HNil

acceptLUB(l1) // Compiles
//acceptLUB(l2) // Does not compile
illTyped("""
acceptLUB(l2)
""")
}

@Test
Expand Down Expand Up @@ -107,11 +118,15 @@ class HListConstraintsTests {
def acceptKeys[R <: HList : Keys[author.type :: title.type :: id.type :: HNil]#λ](r : R) = true

acceptKeys(summary) // Compiles
//acceptKeys(book) // Does not compile
illTyped("""
acceptKeys(book)
""")

def acceptValues[R <: HList : Values[Int :: String :: HNil]#λ](r : R) = true

acceptValues(summary) // Compiles
//acceptValues(book) // Does not compile
illTyped("""
acceptValues(book)
""")
}
}
40 changes: 32 additions & 8 deletions core/src/test/scala/shapeless/sized.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package shapeless
import org.junit.Test
import org.junit.Assert._

import shapeless.test.illTyped

class SizedTests {
import nat._
import Sized._
Expand All @@ -41,8 +43,12 @@ class SizedTests {
val nl0d = l0.sized(3)
assertTrue(nl0d.isEmpty)

//val h0 = nl0.get.head // Does not compile
//val t0 = nl0.get.tail // Does not compile
illTyped("""
val h0 = nl0.get.head
""")
illTyped("""
val t0 = nl0.get.tail
""")

val nl1 = l1.sized(0)
assertTrue(nl1.isEmpty)
Expand All @@ -55,7 +61,10 @@ class SizedTests {

val h1 = nl1b.get.head
val t1 = nl1b.get.tail
//val t1b = nl1b.get.tail.tail // Does not compile

illTyped("""
val t1b = nl1b.get.tail.tail
""")

val nl2 = l2.sized(0)
assertTrue(nl2.isEmpty)
Expand All @@ -69,7 +78,10 @@ class SizedTests {
val h2 = nl2c.get.head
val t2 = nl2c.get.tail
val t2b = nl2c.get.tail.tail
//val t2c = nl1c.get.tail.tail.tail // Does not compile

illTyped("""
val t2c = nl1c.get.tail.tail.tail
""")

val nl3 = l3.sized(0)
assertTrue(nl3.isEmpty)
Expand All @@ -84,7 +96,10 @@ class SizedTests {
val t3 = nl3d.get.tail
val t3b = nl3d.get.tail.tail
val t3c = nl3d.get.tail.tail.tail
//val t3d = nl1d.get.tail.tail.tail.tail // Does not compile

illTyped("""
val t3d = nl1d.get.tail.tail.tail.tail
""")

val rs = "foo".sized(3).get.unsized

Expand Down Expand Up @@ -138,15 +153,24 @@ class SizedTests {

val tk1 = cl.get.take(1)
val tk4 = cl.get.take(4)
//val tk7 = cl.get.take(7) // Does not compile

illTyped("""
val tk7 = cl.get.take(7)
""")

val dr1 = cl.get.drop(1)
val dr4 = cl.get.drop(4)
//val dr7 = cl.get.drop(7) // Does not compile

illTyped("""
val dr7 = cl.get.drop(7)
""")

val (pr1, sf1) = cl.get.splitAt(1)
val (pr4, sf4) = cl.get.splitAt(4)
//val (pr7, sf7) = cl.get.splitAt(7) // Does not compile

illTyped("""
val (pr7, sf7) = cl.get.splitAt(7)
""")

val ml = cl.get map (_.toString)
typed[Sized[List[String], _6]](ml)
Expand Down

0 comments on commit 0a9abd5

Please sign in to comment.