Created
September 25, 2019 07:28
-
-
Save kryptt/f638af08f4bc0e79e8bff4eaf833f99a to your computer and use it in GitHub Desktop.
SVN XML Parser Property Based Test Specification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package industrious | |
import io.dylemma.spac.xml._ | |
import org.specs2.{ScalaCheck, Specification} | |
import org.scalacheck.{Gen, Prop} | |
class SvnXmlParserSpec extends Specification with ScalaCheck { | |
def is = s2""" | |
SVN XML Parser can | |
parse entries $parseEntries | |
parse authors $parseAuthors | |
parse logs $parseLogs | |
""" | |
def parseEntries = checkParse(entryGen, SvnXmlParser.changeEntryParser) | |
def parseAuthors = checkParse(authorGen, SvnXmlParser.authorParser) | |
def parseLogs = checkParse(changeLogGen, SvnXmlParser.changeLogParser.map(_.get)) | |
val authorGen = for { | |
elem <- Gen.alphaStr.suchThat(!_.isBlank) | |
name <- Gen.alphaNumStr | |
} yield s"<$elem>$name</$elem>" -> Author(name, name) | |
val entryGen = for { | |
action <- Gen.oneOf('M', 'A', 'D') | |
path <- Gen.alphaNumStr.suchThat(!_.isBlank) | |
} yield s"""<path action="$action">$path</path>""" -> ChangeEntry[Char](action, path) | |
val changeLogGen = for { | |
revision <- Gen.chooseNum(0L, Long.MaxValue) | |
author <- authorGen | |
message <- Gen.alphaStr | |
date <- DateGenerator.genZonedDateTime | |
paths <- Gen.listOf(entryGen) | |
} yield s"""<logentry revision="$revision"> | |
<author>${author._2.name}</author> | |
<msg>$message</msg> | |
<date>${date.toString}</date> | |
<paths>${paths.map(_._1).mkString}</paths> | |
</logentry>""" -> ChangeLog(author._2, revision, message, date, paths.map(_._2)) | |
def checkParse[T](gen: Gen[(String, T)], parser: XMLParser[T]) = Prop.forAllNoShrink(gen) { | |
case (xml, t) => parser.parse(xml) must_== t | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment