本文整理汇总了Scala中org.specs2.matcher.MatchResult类的典型用法代码示例。如果您正苦于以下问题:Scala MatchResult类的具体用法?Scala MatchResult怎么用?Scala MatchResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MatchResult类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ArgParserSpec
//设置package包名称以及导入依赖的类
package net.white_azalea.models.parsers.arguments
import net.white_azalea.datas.arguments.Config
import org.specs2.Specification
import org.specs2.matcher.MatchResult
class ArgParserSpec extends Specification {
def is =
s2"""
This specification check argument parser.
The 'parse' method should
parse 2 arguments as File[file] and File[dir]: $simple
javadoc file arg must be exists: $arg1exists
javadoc file arg must be file: $arg1dir
javadoc file arg must be xml extension: $arg1txt
junitDir arg must not be empty: $arg2empty
junitDir arg must be exists: $arg2exists
junitDir arg must be directory: $arg2file
default template option is null: $defaultTemplate
"""
def parse(args: Seq[String]) =
new ArgParser().parse(args, Config(null, null, null))
val testJavadocXmlFile = "src/test/resources/javadoc/javadoc.xml"
val testUtResultDir = "src/test/resources/ut"
val dummyTextFile = "src/test/resources/javadoc/not_xml.txt"
def simple: MatchResult[Any] =
parse(Seq(testJavadocXmlFile, testUtResultDir))
.map(v => v.javaDocXml.exists() && v.junitResultDir.exists()) must_== Some(true)
def arg1exists = parse(Seq("nothing/file/path.xml", testUtResultDir)) must_== None
def arg1dir = parse(Seq(testUtResultDir, testUtResultDir)) must_== None
def arg1txt = parse(Seq(dummyTextFile, testUtResultDir)) must_== None
def arg2empty = parse(Seq(dummyTextFile)) must_== None
def arg2exists = parse(Seq(testJavadocXmlFile, "nothing/dir")) must_== None
def arg2file = parse(Seq(testJavadocXmlFile, dummyTextFile)) must_== None
def defaultTemplate = parse(Seq("-t", "src/main/resources/template.mustache", testJavadocXmlFile, testUtResultDir))
.map(_.template != null) must_== Some(true)
}
示例2: SimpleHttpRequestMatcher
//设置package包名称以及导入依赖的类
package com.dwolla.testutils.httpclient
import org.apache.http.client.methods.HttpRequestBase
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
case class SimpleHttpRequestMatcher(req: HttpRequestBase) extends Matcher[HttpRequestBase] {
override def apply[S <: HttpRequestBase](t: Expectable[S]): MatchResult[S] = {
val actualValue = t.value
val test = actualValue != null && req.getMethod == actualValue.getMethod && req.getURI == actualValue.getURI
result(test, s"${t.description} is the same as ${req.toString}", s"${t.description} is not the same as ${req.toString}", t)
}
}
object SimpleHttpRequestMatcher {
def http(req: HttpRequestBase) = SimpleHttpRequestMatcher(req)
}
示例3: TrieSpec
//设置package包名称以及导入依赖的类
package eu.shiftforward.apso.collection
import org.specs2.mutable._
import org.specs2.matcher.MatchResult
class TrieSpec extends Specification {
"A Trie" should {
def checkTree[A, B](input: Seq[A], v: B, trie: Trie[A, B]): MatchResult[_] = {
input match {
case Seq(h, t @ _*) =>
trie.nodes.get(h) must beLike {
case Some(trie) =>
checkTree(t, v, trie)
}
case _ =>
trie.value === Some(v)
}
}
"support sets" in {
val t = Trie[Char, Int]()
val t1 = t.set("hello", 1)
checkTree("hello", 1, t1)
val t2 = t1.set("hell", 2)
checkTree("hello", 1, t2)
checkTree("hell", 2, t2)
val t3 = t2.set("hello", 3)
checkTree("hello", 3, t3)
checkTree("hell", 2, t3)
}
"support gets" in {
val t = Trie[Char, Int]()
.set("hello", 1)
.set("hell", 2)
.set("hellos", 3)
t.get("hello") === Some(1)
t.get("hell") === Some(2)
t.get("hellos") === Some(3)
}
}
}
示例4: ExampleSpec
//设置package包名称以及导入依赖的类
package falkner.jayson.metrics
import java.nio.file.{Files, Path}
import falkner.jayson.metrics.io.{CSV, JSON}
import org.specs2.matcher.MatchResult
import org.specs2.mutable.Specification
import collection.JavaConverters._
import falkner.jayson.metrics.Distribution.calcContinuous
class ExampleSpec extends Specification {
class Example extends Metrics {
override val namespace = "Example"
override val version = "_"
override lazy val values: List[Metric] = List(
Str("Name", "Data Scientist"),
Num("Age", "123"),
DistCon("Data", calcContinuous(Seq(0f, 1f, 0.5f), nBins = 3, sort = true)),
Num("Borken", throw new Exception("Calculation failed!"))
)
}
"README.md example" should {
"CSV export" in {
withCleanup { (p) =>
new String(Files.readAllBytes(CSV(p, new Example()))).contains("Data Scientist") must beTrue
}
}
"JSON serialization works" in {
withCleanup { (p) =>
new String(Files.readAllBytes(JSON(p, new Example()))).contains("Data Scientist") must beTrue
}
}
"JSON serialization lazy-makes parent directories" in {
val dir = Files.createTempDirectory("lazyMakeDirTest")
val subdir = dir.resolve("subdir")
val p = subdir.resolve("example.json")
try {
val data = new String(Files.readAllBytes(JSON(p, new Example())))
data.contains("Data Scientist") mustEqual true
}
finally {
Seq(p, subdir, dir).foreach(Files.delete)
}
}
}
def withCleanup(f: (Path) => MatchResult[Any]): MatchResult[Any] = {
val temp = Files.createTempFile("test", "tmp")
try {
f(temp)
}
finally {
Files.delete(temp)
}
}
}
示例5: MultiRowCSVSpec
//设置package包名称以及导入依赖的类
package falkner.jayson.metrics
import java.nio.file.{Files, Path}
import falkner.jayson.metrics.io.{CSV, JSON}
import org.specs2.matcher.MatchResult
import org.specs2.mutable.Specification
import scala.collection.JavaConverters._
class MultiRowCSVSpec extends Specification {
class Row(foo: String, bar: Int) extends Metrics {
override val namespace = "Example"
override val version = "_"
override lazy val values: List[Metric] = List(Str("Foo", foo), Num("Bar", bar))
}
"Multi-line CSVs" should {
"Parse correctly" in {
withCleanup { (p) =>
println("README.md Example CSV Export")
val a = new Row("a", 1)
val b = new Row("b", 2)
val c = new Row("c", 3)
Files.write(p, (CSV(a).all + "\n" + Seq(b, c).map(v => CSV(v).values).mkString("\n")).getBytes)
val lines = Files.readAllLines(p).asScala
CSV(lines) mustEqual CSV(a)
CSV(lines, 2) mustEqual CSV(b)
CSV(lines, 3) mustEqual CSV(c)
}
}
}
def withCleanup(f: (Path) => MatchResult[Any]): MatchResult[Any] = {
val temp = Files.createTempFile("test", "tmp")
try {
f(temp)
}
finally {
Files.delete(temp)
}
}
}
示例6: containSlice
//设置package包名称以及导入依赖的类
package com.dwolla.testutils.matchers
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
import util.Try
trait AdditionalSeqMatchers
extends ContainSliceMatcher
with StartWithMatcher
with EndWithMatcher
trait ContainSliceMatcher {
def containSlice[T](expected: T*): ContainSlice[T] = new ContainSlice[T](expected: _*)
class ContainSlice[T](expected: T*) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = {
val prettySlice = s"( ${expected.mkString(", ")} )"
result(
test = t.value.containsSlice(expected),
okMessage = s"${t.description} contains the slice $prettySlice",
koMessage = s"${t.description} does not contain the slice $prettySlice",
value = t
)
}
}
}
trait StartWithMatcher {
def startWith[T](expected: T): StartWith[T] = new StartWith[T](expected)
class StartWith[T](expected: T) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = result(
test = t.value.headOption.exists(_ == expected),
okMessage = s"""${t.description} starts with "$expected"""",
koMessage = s"""${t.description} does not start with "$expected"""",
value = t
)
}
}
trait EndWithMatcher {
def endWith[T](expected: T): EndWith[T] = new EndWith[T](expected)
class EndWith[T](expected: T) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = result(
test = Try {
t.value.last == expected
}.getOrElse(false),
okMessage = s"""${t.description} ends with "$expected"""",
koMessage = if (t.value.isEmpty)
s"""The provided (but empty) sequence does not end with "$expected""""
else
s"""${t.description} does not end with "$expected"""",
value = t
)
}
}
示例7: testWithAllAuths
//设置package包名称以及导入依赖的类
package de.frosner.broccoli.controllers
import de.frosner.broccoli.models.{Account, Role, UserAccount}
import de.frosner.broccoli.services.SecurityService
import org.specs2.matcher.MatchResult
import org.specs2.matcher.MatchersImplicits._
import play.api.mvc.{Action, AnyContent, Result}
import play.api.test._
import play.api.test.Helpers._
import jp.t2v.lab.play2.auth.test.Helpers._
import org.mockito.Mockito._
import scala.concurrent.Future
trait AuthUtils extends ServiceMocks {
def testWithAllAuths[T <: AuthConfigImpl](account: Account)(controller: SecurityService => T)(
action: T => Action[AnyContent])(requestModifier: FakeRequest[_] => FakeRequest[_])(
matcher: (T, Future[Result]) => MatchResult[_]): MatchResult[_] = {
val confAuthController = controller(withAuthConf(mock(classOf[SecurityService]), List(account)))
val confAuthRequest = requestModifier(
FakeRequest().withLoggedIn(confAuthController)(account.name)
).asInstanceOf[FakeRequest[AnyContent]]
val confAuthResult = action(confAuthController).apply(confAuthRequest)
val confAuthMatcher = matcher(confAuthController, confAuthResult)
val noAuthController = controller(withAuthNone(mock(classOf[SecurityService])))
val noAuthRequest = requestModifier(FakeRequest()).asInstanceOf[FakeRequest[AnyContent]]
val confAuthNoLoginResult = action(confAuthController).apply(noAuthRequest)
val confAuthNoLoginMatcher = status(confAuthNoLoginResult) === 403
confAuthMatcher and confAuthNoLoginMatcher
}
def testWithAllAuths[T <: AuthConfigImpl](controller: SecurityService => T)(action: T => Action[AnyContent])(
requestModifier: FakeRequest[_] => FakeRequest[_])(
matcher: (T, Future[Result]) => MatchResult[_]): MatchResult[_] = {
val account = UserAccount("user", "pass", ".*", Role.Administrator)
val noAuthController = controller(withAuthNone(mock(classOf[SecurityService])))
val noAuthRequest = requestModifier(FakeRequest()).asInstanceOf[FakeRequest[AnyContent]]
val noAuthResult = action(noAuthController).apply(noAuthRequest)
val noAuthMatcher = matcher(noAuthController, noAuthResult)
val authMatchers = testWithAllAuths(account)(controller)(action)(requestModifier)(matcher)
noAuthMatcher and authMatchers
}
}
示例8: XPathResultMatcher
//设置package包名称以及导入依赖的类
package com.github.eerohele.expek
import net.sf.saxon.s9api.XdmNode
import org.specs2.matcher.{Expectable, MatchFailure, MatchResult, MatchResultCombinators, Matcher}
import shapeless.syntax.typeable.typeableOps
class XPathResultMatcher[T <: Transformation](matcher: (String, XdmNode) => Boolean)(query: String)
extends Matcher[T] with MatchResultCombinators {
def apply[S <: T](expectable: Expectable[S]): MatchResult[S] = {
val actual = expectable.value.result
val matchResult: Vector[MatchResult[S]] = actual.map(_.cast[XdmNode].map { node =>
result(
matcher(query, node),
"ok",
s"""${node.toString} doesn't match XPath expression "${query}"""",
expectable
)
}.getOrElse(MatchFailure("ok", "The transformation doesn't produce a node that can be validated.", expectable)))
matchResult.reduceLeft(_ and _)
}
}
示例9: containSlice
//设置package包名称以及导入依赖的类
package com.dwolla.testutils.sequences
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
import scala.util.Try
trait AdditionalSeqMatchers
extends ContainSliceMatcher
with StartWithMatcher
with EndWithMatcher
trait ContainSliceMatcher {
def containSlice[T](expected: T*): ContainSlice[T] = new ContainSlice[T](expected: _*)
class ContainSlice[T](expected: T*) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = {
val prettySlice = s"( ${expected.mkString(", ")} )"
result(
test = t.value.containsSlice(expected),
okMessage = s"${t.description} contains the slice $prettySlice",
koMessage = s"${t.description} does not contain the slice $prettySlice",
value = t
)
}
}
}
trait StartWithMatcher {
def startWith[T](expected: T): StartWith[T] = new StartWith[T](expected)
class StartWith[T](expected: T) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = result(
test = t.value.headOption.contains(expected),
okMessage = s"""${t.description} starts with "$expected"""",
koMessage = s"""${t.description} does not start with "$expected"""",
value = t
)
}
}
trait EndWithMatcher {
def endWith[T](expected: T): EndWith[T] = new EndWith[T](expected)
class EndWith[T](expected: T) extends Matcher[Seq[T]] {
override def apply[S <: Seq[T]](t: Expectable[S]): MatchResult[S] = result(
test = Try {
t.value.last == expected
}.getOrElse(false),
okMessage = s"""${t.description} ends with "$expected"""",
koMessage = if (t.value.isEmpty)
s"""The provided (but empty) sequence does not end with "$expected""""
else
s"""${t.description} does not end with "$expected"""",
value = t
)
}
}
示例10: Matchers
//设置package包名称以及导入依赖的类
package hivevalid
import java.util.StringTokenizer
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
import HiveValid.CompileResult._
object Matchers {
type Hql = String
case class beSameHqlAs(expected: Hql) extends Matcher[Hql] {
override def apply[S <: Hql](self: Expectable[S]): MatchResult[S] = {
val expectedCompilation = HiveValid.compile(expected)
val selfCompilation = HiveValid.compile(self.value)
val areTheSame = tokenized(self.value.trim) == tokenized(expected.trim)
val results = (expectedCompilation, areTheSame, selfCompilation)
def failureMessage = results match {
case (Failure(msg), _, _) =>
s"The expected query:\n\n'${expected.trim}'\n\ndid not compile: $msg"
case (Success, false, _) =>
s"${self.value.trim}\n\nwas not the same HiveQL as:\n\n${expected.trim}"
case other =>
sys error s"Unexpected results: $results"
}
result(
results == (Success, true, Success),
"The queries compiled and matched",
failureMessage,
self)
}
private def tokenized(hql: Hql): List[String] = {
val Delimiters = " \n()[]{},;:"
def toList(t: StringTokenizer): List[String] =
if(t.hasMoreTokens)
t.nextToken :: toList(t)
else
Nil
toList(new StringTokenizer(hql, Delimiters, true)).filterNot(_.trim.isEmpty)
}
}
}
示例11: apply
//设置package包名称以及导入依赖的类
package org.quicli.testbase.matchers.base
import org.specs2.matcher.{Expectable, MatchResult, Matcher}
import scala.reflect.ClassTag
trait BaseMatcher[T] extends Matcher[T] {
override def apply[S <: T](t: Expectable[S]): MatchResult[S] = {
val maybeErrorMessage: Option[String] = test(t.value)
maybeErrorMessage match {
case None => success("", t)
case Some(errorMessage) => failure(errorMessage, t)
}
}
protected def test[S <: T](value: S): Option[String]
}
object NewMatcher {
def apply[T](check: T => Option[String]): BaseMatcher[T] = {
new BaseMatcher[T] {
override protected def test[S <: T](value: S): Option[String] = check(value)
}
}
def apply[C, E](check: C => Option[String],
matchingItems: C => Iterable[E],
allItems: C => Iterable[Any])
(implicit eTag: ClassTag[E]): ContainLikeMatcher[C, E] = {
new ContainLikeMatcher[C, E] {
override protected def test[U <: C](value: U): Option[String] = check(value)
override protected def matchingElements(c: C): Iterable[E] = matchingItems(c)
override protected def allElements(c: C): Iterable[Any] = {
val all: Iterable[Any] = allItems(c)
if (all.nonEmpty) all else matchingElements(c)
}
}
}
def apply[C, E](check: C => Option[String],
matchingItems: C => Iterable[E])
(implicit eTag: ClassTag[E]): ContainLikeMatcher[C, E] = {
apply(check, matchingItems, matchingItems)
}
}