Skip to content
This repository has been archived by the owner on May 15, 2019. It is now read-only.

Commit

Permalink
Issue #13 - Added some repeated #collect specs
Browse files Browse the repository at this point in the history
* Group
* Zipper
  • Loading branch information
djspiewak committed May 13, 2011
1 parent 0e885a3 commit e95566e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
19 changes: 16 additions & 3 deletions src/test/scala/com/codecommit/antixml/GroupSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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: _*))
Expand Down
24 changes: 22 additions & 2 deletions src/test/scala/com/codecommit/antixml/ZipperSpecs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.