From e95566e44434edf38d3d16331980794b4f29f879 Mon Sep 17 00:00:00 2001 From: Daniel Spiewak Date: Tue, 10 May 2011 14:20:05 -0500 Subject: [PATCH] Issue #13 - Added some repeated #collect specs * Group * Zipper --- .../com/codecommit/antixml/GroupSpecs.scala | 19 ++++++++++++--- .../com/codecommit/antixml/ZipperSpecs.scala | 24 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/test/scala/com/codecommit/antixml/GroupSpecs.scala b/src/test/scala/com/codecommit/antixml/GroupSpecs.scala index a745b5e..53e3c0b 100644 --- a/src/test/scala/com/codecommit/antixml/GroupSpecs.scala +++ b/src/test/scala/com/codecommit/antixml/GroupSpecs.scala @@ -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("") 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("") 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: _*)) diff --git a/src/test/scala/com/codecommit/antixml/ZipperSpecs.scala b/src/test/scala/com/codecommit/antixml/ZipperSpecs.scala index 27555d1..9b9bc62 100644 --- a/src/test/scala/com/codecommit/antixml/ZipperSpecs.scala +++ b/src/test/scala/com/codecommit/antixml/ZipperSpecs.scala @@ -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! }