Permalink
Browse files

Issue #13 - Added some repeated #collect specs

* Group
* Zipper
  • Loading branch information...
djspiewak committed May 10, 2011
1 parent 0e885a3 commit e95566e44434edf38d3d16331980794b4f29f879
@@ -35,10 +35,11 @@ import org.scalacheck._
class GroupSpecs extends Specification with ScalaCheck with XMLGenerators with UtilGenerators {
import Prop._
import XML._
lazy val numProcessors = Runtime.getRuntime.availableProcessors()
implicit val params = set(workers -> numProcessors)
implicit val params = set(workers -> numProcessors, maxSize -> 15) // doesn't need to be so large
"shallow selector" should {
"shallow selection on Group" should {
"find an immediate descendant" in {
val ns = fromString("<parent><parent/></parent>")
ns \ "parent" mustEqual Group(elem("parent"))
@@ -73,7 +74,7 @@ class GroupSpecs extends Specification with ScalaCheck with XMLGenerators with U
}
}
"deep selector" should {
"deep selection on Group" should {
"find an immediate descendant" in {
val ns = fromString("<parent><parent/></parent>")
ns \\ "parent" mustEqual Group(elem("parent"))
@@ -119,6 +120,18 @@ class GroupSpecs extends Specification with ScalaCheck with XMLGenerators with U
}
}
"utility methods on Group" >> {
implicit val arbInt = Arbitrary(Gen.choose(0, 10))
"identity collect should return self" in check { (xml: Group[Node], n: Int) =>
val func = (0 until n).foldLeft(identity: Group[Node] => Group[Node]) { (g, _) =>
g andThen { _ collect { case e => e } }
}
func(xml) mustEqual xml
}
}
def elem(name: String, children: Node*) = Elem(None, name, Attributes(), Map(), Group(children: _*))
def elem(qname : QName, children: Node*) = Elem(qname.prefix, qname.name, Attributes(), Map(), Group(children: _*))
@@ -29,10 +29,18 @@
package com.codecommit.antixml
import org.specs2.mutable._
import scala.io.Source
import org.specs2.ScalaCheck
import org.specs2.matcher.MustExpectable._
import org.scalacheck._
import scala.io.Source
class ZipperSpecs extends Specification {
class ZipperSpecs extends Specification with ScalaCheck with XMLGenerators {
import Prop._
lazy val numProcessors = Runtime.getRuntime.availableProcessors()
implicit val params = set(workers -> numProcessors, maxSize -> 15) // doesn't need to be that large
val bookstore = resource("bookstore.xml")
"Zipper#stripZipper" should {
@@ -156,6 +164,18 @@ class ZipperSpecs extends Specification {
}
}
"utility methods on Zipper" >> {
implicit val arbInt = Arbitrary(Gen.choose(0, 10))
"identity collect should return self" in check { (xml: Group[Node], n: Int) =>
val func = (0 until n).foldLeft(identity: Zipper[Node] => Zipper[Node]) { (g, _) =>
g andThen { _ collect { case e => e } }
}
func(xml.toZipper) mustEqual xml
}
}
def resource(filename: String) =
XML fromSource (Source fromURL (getClass getResource ("/" + filename))) // oooh, lispy!
}

0 comments on commit e95566e

Please sign in to comment.