1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
import org.scalacheck._, Prop._, Gen._, Arbitrary._
import scala.reflect.runtime.universe._, Flag._
object RuntimeErrorProps extends QuasiquoteProperties("errors") {
def testFails[T](block: =>T) = test {
assertThrows[IllegalArgumentException] {
block
}
}
property("default param anon function") = testFails {
val param = q"val x: Int = 1"
q"{ $param => x + 1 }"
}
property("non-casedef case") = testFails {
val x = q"x"
q"foo match { case $x }"
}
property("non-new annotation") = testFails {
val annot = q"foo"
q"@$annot def foo"
}
property("non-valdef param") = testFails {
val param = q"foo"
q"def foo($param)"
}
property("non-valdef class param") = testFails {
val param = q"foo"
q"class Foo($param)"
}
property("non-typedef type param") = testFails {
val tparam = tq"T"
q"class C[$tparam]"
}
property("non-definition refine stat") = testFails {
val stat = q"foo"
tq"Foo { $stat }"
}
property("non-definition early def") = testFails {
val stat = q"foo"
q"class Foo extends { $stat } with Bar"
}
property("type apply for definition") = testFails {
val defn = q"def foo"
q"$defn[foo]"
}
property("non-val selftype") = testFails {
val foo = q"foo"
q"class Foo { $foo => }"
}
property("for empty enums") = testFails {
val enums = List.empty[Tree]
q"for(..$enums) 0"
}
property("for starts with non-from enum") = testFails {
val enums = fq"foo = bar" :: Nil
q"for(..$enums) 0"
}
property("for invalid enum") = testFails {
val enums = q"foo" :: Nil
q"for(..$enums) 0"
}
}
|