2009-10-19 04:25:50 +02:00
|
|
|
package xsbt.boot
|
|
|
|
|
|
2010-02-05 00:56:07 +01:00
|
|
|
import java.io.File
|
2012-12-05 03:08:38 +01:00
|
|
|
import java.util.Arrays.{equals => arrEquals}
|
2009-10-19 04:25:50 +02:00
|
|
|
import org.scalacheck._
|
|
|
|
|
|
|
|
|
|
object PreTest extends Properties("Pre")
|
|
|
|
|
{
|
|
|
|
|
import Pre._
|
|
|
|
|
property("isEmpty") = Prop.forAll( (s: String) => (s.isEmpty == isEmpty(s)) )
|
|
|
|
|
property("isNonEmpty") = Prop.forAll( (s: String) => (isEmpty(s) != isNonEmpty(s)) )
|
|
|
|
|
property("assert true") = { assert(true); true }
|
2013-11-04 17:27:46 +01:00
|
|
|
property("assert false") = Prop.throws(classOf[AssertionError])(assert(false))
|
2009-10-19 04:25:50 +02:00
|
|
|
property("assert true with message") = Prop.forAll { (s: String) => assert(true, s); true }
|
2013-11-04 17:27:46 +01:00
|
|
|
property("assert false with message") = Prop.forAll( (s: String) => Prop.throws(classOf[AssertionError] )(assert(false, s)) )
|
|
|
|
|
property("require false") = Prop.forAll( (s: String) => Prop.throws(classOf[IllegalArgumentException])(require(false, s)) )
|
2009-10-19 04:25:50 +02:00
|
|
|
property("require true") = Prop.forAll { (s: String) => require(true, s); true }
|
2013-11-04 17:27:46 +01:00
|
|
|
property("error") = Prop.forAll( (s: String) => Prop.throws(classOf[BootException])(error(s)) )
|
2009-10-19 04:25:50 +02:00
|
|
|
property("toBoolean") = Prop.forAll( (s: String) => trap(toBoolean(s)) == trap(java.lang.Boolean.parseBoolean(s)) )
|
2012-12-05 03:08:38 +01:00
|
|
|
property("toArray") = Prop.forAll( (list: List[Int]) => arrEquals(list.toArray, toArray(list)) )
|
|
|
|
|
property("toArray") = Prop.forAll( (list: List[String]) => objArrEquals(list.toArray, toArray(list)) )
|
2010-02-05 00:56:07 +01:00
|
|
|
property("concat") = Prop.forAll(genFiles, genFiles) { (a: Array[File], b: Array[File]) => (a ++ b) sameElements concat(a, b) }
|
|
|
|
|
property("array") = Prop.forAll(genFiles) { (a: Array[File]) => array(a.toList : _*) sameElements Array(a: _*) }
|
|
|
|
|
|
|
|
|
|
implicit lazy val arbFile: Arbitrary[File] = Arbitrary { for(i <- Arbitrary.arbitrary[Int] ) yield new File(i.toString) }
|
|
|
|
|
implicit lazy val genFiles: Gen[Array[File]] = Arbitrary.arbitrary[Array[File]]
|
2009-10-19 04:25:50 +02:00
|
|
|
|
|
|
|
|
def trap[T](t: => T): Option[T] = try { Some(t) } catch { case e: Exception => None }
|
2012-12-05 03:08:38 +01:00
|
|
|
|
|
|
|
|
private[this] def objArrEquals[T <: AnyRef](a: Array[T], b: Array[T]): Boolean =
|
|
|
|
|
arrEquals(a.asInstanceOf[Array[AnyRef]], b.asInstanceOf[Array[AnyRef]])
|
2009-10-19 04:25:50 +02:00
|
|
|
}
|