2009-10-19 04:25:50 +02:00
|
|
|
package xsbt.boot
|
|
|
|
|
|
2010-02-05 00:56:07 +01:00
|
|
|
import java.io.File
|
2012-07-31 17:52:10 +02:00
|
|
|
import java.util.Arrays.equals
|
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 }
|
|
|
|
|
property("assert false") = Prop.throws(assert(false), classOf[AssertionError])
|
|
|
|
|
property("assert true with message") = Prop.forAll { (s: String) => assert(true, s); true }
|
|
|
|
|
property("assert false with message") = Prop.forAll( (s: String) => Prop.throws(assert(false, s), classOf[AssertionError] ) )
|
|
|
|
|
property("require false") = Prop.forAll( (s: String) => Prop.throws(require(false, s), classOf[IllegalArgumentException]) )
|
|
|
|
|
property("require true") = Prop.forAll { (s: String) => require(true, s); true }
|
|
|
|
|
property("error") = Prop.forAll( (s: String) => Prop.throws(error(s), classOf[BootException]) )
|
|
|
|
|
property("toBoolean") = Prop.forAll( (s: String) => trap(toBoolean(s)) == trap(java.lang.Boolean.parseBoolean(s)) )
|
2012-07-31 17:52:10 +02:00
|
|
|
property("toArray") = Prop.forAll( (list: List[Int]) => equals(list.toArray, toArray(list)) )
|
|
|
|
|
property("toArray") = Prop.forAll( (list: List[String]) => equals(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 }
|
|
|
|
|
}
|