本文整理汇总了Scala中org.scalatest.Assertion类的典型用法代码示例。如果您正苦于以下问题:Scala Assertion类的具体用法?Scala Assertion怎么用?Scala Assertion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Assertion类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: CodecTestUtils
//设置package包名称以及导入依赖的类
package wow.common.codecs
import org.scalatest.{Assertion, Assertions, Matchers}
import scodec.Attempt.{Failure, Successful}
import scodec.bits.BitVector
import scodec.{Codec, DecodeResult}
object CodecTestUtils extends Assertions with Matchers {
def decode[A](bits: BitVector, expectedValue: A)(implicit codec: Codec[A]): Assertion = {
codec.decode(bits) match {
case Successful(DecodeResult(x, remainder)) if remainder.nonEmpty =>
fail(s"non empty remainder: $x / $remainder")
case Successful(DecodeResult(parsedValue, BitVector.empty)) =>
parsedValue shouldEqual expectedValue
case Failure(err) => fail(err.toString())
}
}
def encode[A](expectedBits: BitVector, value: A)(implicit codec: Codec[A]): Assertion = {
codec.encode(value) match {
case Successful(bits) =>
bits.toHex shouldEqual expectedBits.toHex
bits shouldEqual expectedBits
case Failure(err) => fail(err.toString())
}
}
}
开发者ID:SKNZ,项目名称:SpinaciCore,代码行数:30,代码来源:CodecTestUtils.scala
示例2: assertThrowsAndTestMessage
//设置package包名称以及导入依赖的类
package org.scalawebtest.integration
import org.scalactic.source.Position
import org.scalatest.{Assertion, Succeeded, Suite}
import scala.reflect.ClassTag
trait AdditionalAssertions {self: Suite =>
def assertThrowsAndTestMessage[T <: AnyRef](f: => Any)(messageTest: String => Assertion)(implicit classTag: ClassTag[T], pos: Position): Assertion = {
val clazz = classTag.runtimeClass
val threwExpectedException =
try {
f
false
}
catch {
case u: Throwable =>
messageTest(u.getMessage)
if (!clazz.isAssignableFrom(u.getClass)) {
fail(s"didn't throw expected exception ${clazz.getCanonicalName}")
}
else true
}
if (threwExpectedException) {
Succeeded
}
else {
fail(s"didn't throw expected exception ${clazz.getCanonicalName}")
}
}
}
开发者ID:unic,项目名称:ScalaWebTest,代码行数:33,代码来源:AdditionalAssertions.scala
示例3: localThread
//设置package包名称以及导入依赖的类
package com.twitter.finagle.mux.lease.exp
import com.twitter.util.Local
import org.scalatest.Assertion
import org.scalatest.concurrent.{IntegrationPatience, Conductors}
trait LocalConductors extends Conductors with IntegrationPatience {
def localThread(conductor: Conductor)(fn: => Unit): Unit = {
val outer = Local.save()
conductor.thread {
val saved = Local.save()
Local.restore(outer)
try {
fn
} finally {
Local.restore(saved)
}
}
}
def localWhenFinished(conductor: Conductor)(fn: => Assertion): Unit = {
val outer = Local.save()
conductor.whenFinished {
val saved = Local.save()
Local.restore(outer)
try {
fn
} finally {
Local.restore(saved)
}
}
}
}
开发者ID:wenkeyang,项目名称:finagle,代码行数:35,代码来源:LocalConductors.scala
示例4: add
//设置package包名称以及导入依赖的类
package com.olegych.scastie.balancer
import com.olegych.scastie.api._
import com.olegych.scastie.balancer.utils._
import org.scalatest.{FunSuite, Assertion}
import scala.collection.immutable.Queue
trait LoadBalancerTestUtils extends FunSuite with TestUtils {
type TestLoadBalancer = LoadBalancer[String, String]
private var taskId = 1000
def add(balancer: TestLoadBalancer, config: String): TestLoadBalancer = {
val (_, balancer0) =
balancer.add(
Task(config, nextIp, SbtRunTaskId(SnippetId(taskId.toString, None)))
)
taskId += 1
balancer0
}
def assertConfigs(
balancer: TestLoadBalancer
)(columns: Seq[String]*): Assertion = {
assertMultiset(
balancer.servers.map(_.currentConfig),
columns.flatten
)
}
def assertMultiset[T: Ordering](xs: Seq[T], ys: Seq[T]): Assertion =
assert(Multiset(xs) == Multiset(ys))
private var serverId = 0
def server(config: String): Server[String, String] = {
val t = Server("s" + serverId, config)
serverId += 1
t
}
def servers(columns: Seq[String]*): Vector[Server[String, String]] = {
columns.to[Vector].flatten.map(server)
}
private var currentIp = 0
def nextIp: Ip = {
val t = Ip("ip" + currentIp)
currentIp += 1
t
}
def history(columns: Seq[String]*): History[String] = {
val records =
columns.to[Vector].flatten.map(config => Record(config, nextIp)).reverse
History(Queue(records: _*), size = 20)
}
}
开发者ID:scalacenter,项目名称:scastie,代码行数:60,代码来源:LoadBalancerTestUtils.scala
示例5: assertStructurallyEqual
//设置package包名称以及导入依赖的类
package preact
import org.scalatest.{Assertion, Assertions}
import scala.meta.Tree
import scala.meta.testkit.StructurallyEqual
package object macros {
def assertStructurallyEqual(actual: Tree, expected: Tree): Assertion = {
StructurallyEqual(actual, expected) match {
case Left(diff) =>
Assertions.fail(
s"""Not Structurally equal:
|$diff
|Details:
|${diff.detailed}""".stripMargin)
case _ => Assertions.succeed
}
}
}
开发者ID:LMnet,项目名称:scala-js-preact,代码行数:22,代码来源:package.scala
示例6: afterAll
//设置package包名称以及导入依赖的类
package test
import model.json.ResultMessage
import org.scalatest.{Assertion, BeforeAndAfterAll}
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.mvc.Result
import play.api.test.Helpers._
import play.test.WithApplication
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
override def afterAll() {
application.stopPlay()
}
def assertFutureResultStatus(future: Future[Result], status: Int) = {
val result: Result = Await.result(future, 20 seconds)
if(result.header.status != status){
play.Logger.error(contentAsString(future))
}
assert(result.header.status == status)
}
def assertBodyJsonMessage(future: Future[Result], message: String, emptyExtras: Boolean): Assertion = {
//val result: Result = Await.result(future,20 seconds)
val bodyJson = contentAsJson(future)
play.Logger.debug(s"BodyJson: $bodyJson")
val jsResult = bodyJson.validate[ResultMessage]
assert(jsResult.isSuccess)
if(!emptyExtras) {
assert(jsResult.get.extras.nonEmpty)
if(jsResult.get.extras.isEmpty){
play.Logger.debug(jsResult.toString)
}
}
assert(jsResult.get.result === message)
}
def assertBodyJsonMessage(future: Future[Result], message: String): Assertion = {
assertBodyJsonMessage(future, message, emptyExtras = true)
}
}
开发者ID:camilosampedro,项目名称:Aton,代码行数:46,代码来源:ControllerTest.scala
示例7: CommandParsingSpec
//设置package包名称以及导入依赖的类
package commands
import model.UserId
import org.scalatest.{Assertion, FlatSpec, MustMatchers}
import slack.models.Message
class CommandParsingSpec extends FlatSpec with MustMatchers {
val testUser: UserId = "test_user"
private def getMessage(text: String): Message = {
Message("", "", testUser, text, None)
}
it should "parse all commands" in new CommandParsing {
Commands.allCommands foreach {
case oneArg: OneArgCommand => assertOneArgCommand(oneArg.name, oneArg.apply, parse)
case noArg: NoArgCommand => assertNoArgCommand(noArg.name, noArg.apply, parse)
}
}
type ParseFunction = Message => Option[Command]
def assertOneArgCommand(commandName: String,
expected: (UserId, String) => Command,
parse: ParseFunction): Assertion = {
parse(getMessage(s"$commandName")) mustBe None
parse(getMessage(s"${commandName}a")) mustBe None
parse(getMessage(s" ${commandName}a")) mustBe None
parse(getMessage(s" $commandName")) mustBe None
parse(getMessage(s" $commandName ")) mustBe None
parse(getMessage(s"$commandName a")) mustBe Some(expected(testUser, "a"))
parse(getMessage(s"$commandName\na")) mustBe Some(expected(testUser, "a"))
parse(getMessage(s"$commandName a ")) mustBe Some(expected(testUser, "a"))
parse(getMessage(s"$commandName a b c")) mustBe Some(expected(testUser, "a b c"))
parse(getMessage(s"$commandName a b c ")) mustBe Some(expected(testUser, "a b c"))
}
def assertNoArgCommand(commandName: String,
expected: UserId => Command,
parse: ParseFunction): Assertion = {
parse(getMessage(s"$commandName")) mustBe Some(expected(testUser))
parse(getMessage(s" $commandName")) mustBe Some(expected(testUser))
parse(getMessage(s" $commandName ")) mustBe Some(expected(testUser))
parse(getMessage(s"$commandName a")) mustBe None
parse(getMessage(s"$commandName a ")) mustBe None
parse(getMessage(s"${commandName}a")) mustBe None
parse(getMessage(s" $commandName a ")) mustBe None
}
}
开发者ID:mturlo,项目名称:lunchbot,代码行数:56,代码来源:CommandParsingSpec.scala
示例8: emptyComponent
//设置package包名称以及导入依赖的类
package io.udash.testing
import com.github.ghik.silencer.silent
import org.scalajs.dom
import org.scalatest.{Assertion, Succeeded}
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.time.{Millis, Span}
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.scalajs.concurrent.JSExecutionContext
import scala.scalajs.js.Date
import scala.util.{Failure, Success}
trait FrontendTestUtils {
import scalatags.JsDom.all.div
def emptyComponent() = div().render
}
trait UdashFrontendTest extends UdashSharedTest with FrontendTestUtils {
@silent
implicit val testExecutionContext = JSExecutionContext.runNow
}
trait AsyncUdashFrontendTest extends AsyncUdashSharedTest with FrontendTestUtils with PatienceConfiguration {
case object EventuallyTimeout extends Exception
@silent
override implicit def executionContext: ExecutionContext = JSExecutionContext.runNow
override implicit val patienceConfig = PatienceConfig(scaled(Span(5000, Millis)), scaled(Span(100, Millis)))
def eventually(code: => Any)(implicit patienceConfig: PatienceConfig): Future[Assertion] = {
val start = Date.now()
val p = Promise[Assertion]
def startTest(): Unit = {
dom.window.setTimeout(() => {
if (patienceConfig.timeout.toMillis > Date.now() - start) {
try {
code
p.complete(Success(Succeeded))
} catch {
case _: Exception => startTest()
}
} else {
p.complete(Failure(EventuallyTimeout))
}
}, patienceConfig.interval.toMillis)
}
startTest()
p.future
}
}
开发者ID:UdashFramework,项目名称:udash-core,代码行数:52,代码来源:UdashFrontendTest.scala
示例9: SanitizerTest
//设置package包名称以及导入依赖的类
package communicate.api.core
import org.scalatest.{Assertion, FlatSpec}
class SanitizerTest extends FlatSpec {
def ensureSanitizedInput(in: String, expected: String): Assertion =
assert(Sanitizer.sanitizeInput(in).trim === expected.trim)
def ensureSanitizedOutput(out: String, expected: String): Assertion =
assert(Sanitizer.sanitizeOutput(out).trim === expected.trim)
def ensureNoSanitization(in: String) : Assertion =
ensureSanitizedInput(in, in)
"Inputs" should "be sanitized" in {
ensureSanitizedInput("```foo```", "foo")
ensureSanitizedInput("```\nfoo\n```", "foo")
ensureSanitizedInput("``` \nfoo\n ```", "foo")
ensureSanitizedInput("``` \nfoo \n```", "foo")
ensureSanitizedInput("`foo`", "foo")
ensureSanitizedInput("```scala\nfoo```", "foo")
ensureSanitizedInput("```scala \nfoo```", "foo")
ensureSanitizedInput("```scala \nfoo\n```", "foo")
ensureSanitizedInput("```scala\n! class Foo {\n}\n```", "! class Foo {\n}")
// I have no idea why anyone would do this, but make sure the result is expected
ensureSanitizedInput("````foo````", "`foo`")
ensureSanitizedInput("``foo``", "`foo`")
}
it should "not be sanitized" in {
ensureNoSanitization("foo")
}
"Outputs" should "be sanitized" in {
ensureSanitizedOutput("1", "```\n1\n```")
ensureSanitizedOutput("String = foo", "```\nString = \"foo\"\n```")
ensureSanitizedOutput(
"""1
|String = foo""".stripMargin,
"""```
|1
|String = "foo"
|```""".stripMargin)
ensureSanitizedOutput(
"""String = foo
|1
""".stripMargin,
"""```
|String = "foo"
|1
|```""".stripMargin)
ensureSanitizedOutput("\"I `really` like cats\"", "```\n\"I 'really' like cats\"\n```")
}
}
开发者ID:DavidDudson,项目名称:communicate,代码行数:58,代码来源:SanitizerTest.scala
注:本文中的org.scalatest.Assertion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论