• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala FreeSpec类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.scalatest.FreeSpec的典型用法代码示例。如果您正苦于以下问题:Scala FreeSpec类的具体用法?Scala FreeSpec怎么用?Scala FreeSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了FreeSpec类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: QQStagerTestCase

//设置package包名称以及导入依赖的类
package qq
package macros

import org.scalatest.{FreeSpec, Matchers}
import qq.cc.{LocalOptimizer, Parser}
import qq.data.{FilterAST, Program}
import qq.macros.QQStager._
import qq.util.Recursion
import qq.util.Recursion.RecursionEngine

case class QQStagerTestCase(name: String, programs: Vector[String], literalResults: Vector[Program[FilterAST]])

class QQStagerSmokeTest extends FreeSpec with Matchers {
  implicit val recEngine: RecursionEngine =
    Recursion.Unsafe.Direct

  val testCases = Vector(
    QQStagerTestCase("paths",
      Vector(".", ". | .", ".lol", ".key.[1].hey"),
      Vector(qq".", qq". | .", qq".lol", qq".key.[1].hey"))
  )

  val _ =
    testCases.foreach(tc =>
      tc.name in {
        val _ = tc.programs.map(p => LocalOptimizer.optimizeProgram(Parser.program.parse(p).get.value)) shouldBe tc.literalResults
      }
    )
} 
开发者ID:edmundnoble,项目名称:slate,代码行数:30,代码来源:QQStagerTest.scala


示例2: ImplicitInstanceResolutionSpec

//设置package包名称以及导入依赖的类
package com.example.catfood.futures

import cats.Applicative
import org.scalatest.{ FreeSpec, MustMatchers }
import cats.implicits._

import scala.util.Success

class ImplicitInstanceResolutionSpec extends FreeSpec with MustMatchers {

  def wrapA[A, F[_]](v: A)(implicit F: Applicative[F]): F[A] =
    F.pure(v)

  // F[_] <: Applicative[_]]
  def doubleWrap[A, F[_]](v: F[A])(implicit F: Applicative[F]): F[F[A]] =
    F.pure(v)

  "hinting at an implicit with the value type does not work" in {
    // found scala.util.Try[Int], required Option[Int]
    "val o: Option[Int] = wrapA(1)" mustNot typeCheck
  }

  "the default implicit instance is Try" in {
    // found scala.util.Try[Int], required Option[Int]
    val tr = wrapA(1)
    tr mustBe Success(1)
  }

  "explicit passing of the implicit instance works" in {
    val opt = wrapA(1)(catsStdInstancesForOption)
    opt mustBe Some(1) //an[Option[Int]]
  }

  "explicit parametrization works" in {
    val opt = wrapA[Int, Option](1)
    opt mustBe Some(1) //an[Option[Int]]
  }

  "if the Applicative type is passed in, the correct instance is resolved" in {
    val x = doubleWrap(Option(1))
    x mustBe Some(Some(1))
  }

} 
开发者ID:ksilin,项目名称:catfood,代码行数:45,代码来源:ImplicitInstanceResolutionSpec.scala


示例3: ExistentialPrerequisitesSpec

//设置package包名称以及导入依赖的类
package com.example.catfood.existentials

import org.scalatest.{ FreeSpec, MustMatchers }

class ExistentialPrerequisitesSpec extends FreeSpec with MustMatchers {

  "must work a as a type erasure" in {

    trait Existential {
      type Inner
      val value: Inner
    }

    case class ExOne(value: Int) extends Existential {
      override type Inner = Int
    }

    val ex1: Existential = ExOne(1)
    println(ex1.getClass)

    final case class TypeErasor[A](value: A) extends Existential { type Inner = A }

    val intErased: Existential = TypeErasor(1)
    println(intErased)
    val v1: intErased.Inner = intErased.value
    val stringErased        = TypeErasor("abc")
    println(stringErased)
    val v2: stringErased.Inner = stringErased.value
    val caseErased             = TypeErasor(ExOne(4))
    println(caseErased)
    val v3: caseErased.Inner = caseErased.value

    // we lost the information about the type of the .value of each Existential instance.
    //  but we can still add restrictions to it

  }

} 
开发者ID:ksilin,项目名称:catfood,代码行数:39,代码来源:ExistentialPrerequisitesSpec.scala


示例4: EitherErrorSpec

//设置package包名称以及导入依赖的类
package com.example.catfood.errors

import com.example.catfood.errors.ApplicationDomain._
import org.scalatest.{ FreeSpec, MustMatchers }

class EitherErrorSpec extends FreeSpec with MustMatchers {

  def arm: Either[SystemOffline, Nuke]      = Right(Nuke())
  def aim: Either[RotationNeedsOil, Target] = Right(Target())
  def launch(target: Target, nuke: Nuke): Either[MissedByMeters, Impacted] =
    Left(MissedByMeters(5))

  def attack(): Either[NukeException, Impacted] =
    for {
      nuke     <- arm
      target   <- aim
      impacted <- launch(target, nuke)
    } yield impacted

  "must attack" in {
    attack() mustBe Left(MissedByMeters(5))
  }

} 
开发者ID:ksilin,项目名称:catfood,代码行数:25,代码来源:EitherErrorSpec.scala


示例5: CartesianSyntaxSpec

//设置package包名称以及导入依赖的类
package com.example.catfood.ap

import org.scalatest.{ FreeSpec, MustMatchers }
import cats.implicits._

class CartesianSyntaxSpec extends FreeSpec with MustMatchers {

  "raw result is a CartesianBuilder" in {
//    CartesianBuilder[Option]#CartesianBuilder2[Int, Int] - is inaccessible - private to syntax
    val builder = Option(1) |@| Option(2)
    println(builder.getClass)
  }

  // def tupled(implicit invariant: Invariant[F], cartesian: Cartesian[F]): F[(A0, A1)] = Cartesian.tuple2(a0, a1)
  "tupling the results" in {
    (Option(1) |@| Option(2)).tupled mustBe Option((1, 2))
  }

  "mapping over the builder" in {

    // CartesianBuilder2:
    // def map[Z](f: (A0, A1) => Z)(implicit functor: Functor[F], cartesian: Cartesian[F]): F[Z] = Cartesian.map2(a0, a1)(f)
    Option(1) |@| Option(2) map ((i, j) => (i, j)) mustBe Option((1, 2))
  }

  "right projection" in {
    Option(1) *> Option(2) mustBe Option(2)
    Option(1) *> None mustBe None
  }

  "left projection" in {
    Option(1) <* Option(2) mustBe Option(1)
    None <* Option(1) mustBe None
  }

  "contramap" in {}

} 
开发者ID:ksilin,项目名称:catfood,代码行数:39,代码来源:CartesianSyntaxSpec.scala


示例6: AvroSpec

//设置package包名称以及导入依赖的类
package com.lukecycon.avro

import org.scalatest.FreeSpec
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._

class AvroSpec extends FreeSpec with Checkers {

  def roundTrip[T: AvroFormat](v: T, comp: Boolean = false) =
    Avro.read(Avro.write(v, comp), comp)

  def checkPrimative[T: Arbitrary: AvroFormat](name: String) =
    s"Avro roundTrip should be identity for $name" - {
      "uncompressed" in {
        check { i: T =>
          roundTrip(i) == Right(i)
        }
      }

      "compressed" in {
        check { i: T =>
          roundTrip(i, true) == Right(i)
        }
      }
    }

  checkPrimative[Boolean]("Boolean")
  checkPrimative[Int]("Int")
  checkPrimative[Long]("Long")
  checkPrimative[Float]("Float")
  checkPrimative[Double]("Double")
  checkPrimative[Seq[Byte]]("bytes")
  checkPrimative[String]("Sstring")
  checkPrimative[Option[Int]]("Option[_]")
  checkPrimative[Either[Int, String]]("Either[_]")
  checkPrimative[List[Int]]("List[_]")
  checkPrimative[Map[String, Int]]("Map[String, _]")
} 
开发者ID:themattchan,项目名称:Skaro,代码行数:41,代码来源:AvroSpec.scala


示例7: PrintVarSpec

//设置package包名称以及导入依赖的类
package simple

import org.scalatest.{ FreeSpec, Matchers }

class PrintVarSpec extends FreeSpec with Matchers {
  import PrintVar._
  "printVarName"  - {
    val myTest = "test"
    val myVar = printVarName(myTest)
    myVar should equal ("myTest")
  }

  "printVar" - {
    val myTest = "test3"
    val myVar = printVar(myTest)
    myVar should equal ("""myTest="test3"""")
  }

} 
开发者ID:gustavoamigo,项目名称:scamacros-samples,代码行数:20,代码来源:PrintVarSpec.scala


示例8: FunctorsSpec

//设置package包名称以及导入依赖的类
import cats.Functor
import org.scalatest.{FreeSpec, Matchers}

class FunctorsSpec extends FreeSpec with Matchers {
  "functor for Tree" in {
    import Functors.treeFunctor

    Functor[Tree].map(Leaf(1))(_ * 2) shouldBe Leaf(2)

    Functor[Tree].map(
      Branch(
        Leaf(1),
        Branch(Leaf(2), Leaf(3))
      )
    )(_ * 3) shouldBe Branch(Leaf(1 * 3), Branch(Leaf(2 * 3), Leaf(3 * 3)))
  }

} 
开发者ID:konradwudkowski,项目名称:exercises-scala-cats,代码行数:19,代码来源:FunctorsSpec.scala


示例9: SuperAdderSpec

//设置package包名称以及导入依赖的类
import cats.Monoid
import org.scalatest.{FreeSpec, Matchers}
import cats.instances.int._
import cats.instances.option._

class SuperAdderSpec extends FreeSpec with Matchers {

  import SuperAdder._

  "addInt" in {
    addInts(List(1,2,3)) shouldBe List(1,2,3).sum
  }

  "addOption" in {
    addOptions(
      List(
        Some(1),
        Some(2),
        None,
        Some(3)
      )
    ) shouldBe Some(1 + 2 + 3)
  }

  "generalized add for lists of anything" in {
    add(List(1,2,3)) shouldBe 1 + 2 + 3
    add(List(Some(1), Some(2), None)) shouldBe Some(1 + 2)
  }

  "adding Orders" in {
    add(List(Order(totalCost = 5, quantity = 2))) shouldBe Order(5, 2)
    add(
      List(
        Order(totalCost = 5, quantity = 2),
        Order(totalCost = 1, quantity = 3)
      )
    ) shouldBe Order(5 + 1, 2 + 3)

  }

}

case class Order(totalCost: Double, quantity: Double)

object Order {
  implicit val monoidInstance: Monoid[Order] = new Monoid[Order] {
    def empty: Order = Order(0,0)

    def combine(x: Order, y: Order): Order =
      Order(
        totalCost = x.totalCost + y.totalCost,
        quantity = x.quantity + y.quantity)
  }
} 
开发者ID:konradwudkowski,项目名称:exercises-scala-cats,代码行数:55,代码来源:SuperAdderSpec.scala


示例10: BuildDefinitionTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.model

import org.scalatest.{FreeSpec, Matchers}

class BuildDefinitionTest extends FreeSpec with Matchers {
  "basic test" in {
    val buildFile = BuildDefinition(
      name = Some("create-sbt-project"),
      organization = Some("com.github.madoc"),
      version = Some("0.1-SNAPSHOT"),
      scalaVersion = Some("2.11.8"),
      extraScalacOptions = Seq("-language:_", "-unchecked", "-deprecation", "-encoding", "utf8"),
      resolverURLsToNames = Map(
        "http://oss.sonatype.org/content/repositories/snapshots" ? "Sonatype Snapshots",
        "http://oss.sonatype.org/content/repositories/releases" ? "Sonatype Releases"
      ),
      libraryDependencies = Seq(
        LibraryDependency(groupID="org.scalatest", artifactID="scalatest", revision="3.0.0", configuration=Some("test"), withSources=true),
        LibraryDependency(groupID="org.scalacheck", artifactID="scalacheck", revision="1.13.3", configuration=Some("test"), withSources=true)
      ),
      javaOptionContextsToOptions = Map(
        Set[String]() ? Seq("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"),
        Set("Test","run") ? Seq("-Djava.awt.headless=true")
      ),
      additionalCommands=Seq("jacoco.settings")
    )
    buildFile.toString should be (
      """organization := "com.github.madoc"
        |
        |name := "create-sbt-project"
        |
        |version := "0.1-SNAPSHOT"
        |
        |scalaVersion := "2.11.8"
        |
        |scalacOptions ++= Seq("-language:_", "-unchecked", "-deprecation", "-encoding", "utf8")
        |
        |resolvers ++= Seq(
        |  "Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases",
        |  "Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots"
        |)
        |
        |libraryDependencies ++= Seq(
        |  "org.scalatest" %% "scalatest" % "3.0.0" % "test" withSources(),
        |  "org.scalacheck" %% "scalacheck" % "1.13.3" % "test" withSources()
        |)
        |
        |javaOptions ++= Seq("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005")
        |
        |javaOptions in (Test, run) += "-Djava.awt.headless=true"
        |
        |jacoco.settings
        |""" stripMargin
    )
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:57,代码来源:BuildDefinitionTest.scala


示例11: LibraryDependencyTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.model

import org.scalatest.{FreeSpec, Matchers}

class LibraryDependencyTest extends FreeSpec with Matchers {
  "simple case" in {
    val ld=LibraryDependency(groupID="com.github.madoc", artifactID="create_sbt_project", revision="0.1-SNAPSHOT")
    ld.toString should be (""""com.github.madoc" %% "create_sbt_project" % "0.1-SNAPSHOT"""")
  }
  "without adding scala version" in {
    val ld=LibraryDependency(groupID="com.github.madoc", artifactID="create_sbt_project", revision="0.1-SNAPSHOT", addScalaVersion=false)
    ld.toString should be (""""com.github.madoc" % "create_sbt_project" % "0.1-SNAPSHOT"""")
  }
  "for 'test'" in {
    val ld=LibraryDependency(groupID="com.github.madoc", artifactID="create_sbt_project", revision="0.1-SNAPSHOT", configuration=Some("test"))
    ld.toString should be (""""com.github.madoc" %% "create_sbt_project" % "0.1-SNAPSHOT" % "test"""")
  }
  "with sources" in {
    val ld=LibraryDependency(groupID="com.github.madoc", artifactID="create_sbt_project", revision="0.1-SNAPSHOT", withSources=true)
    ld.toString should be (""""com.github.madoc" %% "create_sbt_project" % "0.1-SNAPSHOT" withSources()""")
  }
  "everything together" in {
    val ld=LibraryDependency(groupID="com.github.madoc", artifactID="create_sbt_project", revision="0.1-SNAPSHOT", addScalaVersion=false, configuration=Some("test"), withSources=true)
    ld.toString should be (""""com.github.madoc" % "create_sbt_project" % "0.1-SNAPSHOT" % "test" withSources()""")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:27,代码来源:LibraryDependencyTest.scala


示例12: GitIgnoreTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.model

import org.scalatest.{FreeSpec, Matchers}

class GitIgnoreTest extends FreeSpec with Matchers {
  "basic test" in {
    val gitIgnore = GitIgnore(Set(".idea", ".idea_modules", ".c9", "*.iml", "target", "out", "project/target",
      "project/project", "project.vim", "*~", "*#", ".DS_Store", "src/autogenerated"))
    gitIgnore.toString should be (
      """*#
        |*.iml
        |*~
        |.DS_Store
        |.c9
        |.idea
        |.idea_modules
        |out
        |project.vim
        |project/project
        |project/target
        |src/autogenerated
        |target
        |""" stripMargin
    )
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:27,代码来源:GitIgnoreTest.scala


示例13: CSPHelpFormatterTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.cli

import java.io.PrintWriter

import com.github.madoc.create_sbt_project.io.Write.WriteToAppendable
import org.scalatest.{FreeSpec, Matchers}

class CSPHelpFormatterTest extends FreeSpec with Matchers {
  "directory is only attached to the usage line" in {
    val formatter = new CSPHelpFormatter
    val (sb1, sb2) = (new java.lang.StringBuilder, new java.lang.StringBuilder)
    formatter.printWrapped(new PrintWriter(new WriteToAppendable(sb1) asJavaIOWriter), 100, 2, "usage: a b c")
    formatter.printWrapped(new PrintWriter(new WriteToAppendable(sb2) asJavaIOWriter), 100, 2, "non-usage: a b c")
    sb1.toString.trim should be ("usage: a b c [directory]")
    sb2.toString.trim should be ("non-usage: a b c")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:18,代码来源:CSPHelpFormatterTest.scala


示例14: ParseCommandLineTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.cli

import com.github.madoc.create_sbt_project.cli.CommandLineResult.CreateSBTProject
import com.github.madoc.create_sbt_project.config.RootConfig
import org.scalatest.{FreeSpec, Matchers}

class ParseCommandLineTest extends FreeSpec with Matchers {
  "parsing a null command line does not throw an error" in {
    val resultForNull = ParseCommandLine(null)
    resultForNull shouldBe a[CreateSBTProject]
    resultForNull match {
      case CreateSBTProject(modConfig) ? modConfig(RootConfig()) should be (RootConfig())
      case _ ? fail
    }
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:17,代码来源:ParseCommandLineTest.scala


示例15: TestCLIErrors

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.main

import com.github.madoc.create_sbt_project.io.{FileSystemSupport, TestFileSystemSupport}
import org.scalatest.{FreeSpec, Matchers}

class TestCLIErrors extends FreeSpec with Matchers with MainTestTools {
  "adding a missing library reference leads to the appropriate error message" in {
    val fs = runWithNoUserConfig("-l", "foolib", "--", "testproject")(noStandardOutput = true)
    fs.getErrorOutput.trim should be("""Missing definition for library "foolib".""")
  }
  "adding a missing plugin reference leads to the appropriate error message" in {
    val fs = runWithNoUserConfig("-p", "fooplugin", "--", "testproject")(noStandardOutput = true)
    fs.getErrorOutput.trim should be("""Missing definition for plugin "fooplugin".""")
  }
  "leaving out both project name and directory leads to the appropriate error message" in {
    val fs = new TestFileSystemSupport()
    val prevFS = FileSystemSupport.main.get
    FileSystemSupport.main.set(fs)
    try Main.main(Array.empty[String]) finally FileSystemSupport.main.set(prevFS)
    fs.getErrorOutput.trim should be("""Neither project name nor project directory is set, but one of the two must be given.""")
  }
  "specifying more than one project directory leads to the appropriate error message" in {
    val fs = runWithNoUserConfig("testproject1", "testproject2")(noStandardOutput = true)
    fs.getErrorOutput.trim should be("""More than one project directory specified.""")
  }
  "whitespace in the project directory leads to an error" in {
    val fs = runWithNoUserConfig(" ws")(noStandardOutput=true)
    fs.getErrorOutput.trim should be ("""Whitespace before project directory.""")
  }
  "empty project organization (as opposed to left out) leads to an error" in {
    val fs = runWithNoUserConfig("-o", "", "testproject")(noStandardOutput=true)
    fs.getErrorOutput.trim should be ("""Empty project organization.""")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:35,代码来源:TestCLIErrors.scala


示例16: TestHelpAndVersion

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.main

import com.github.madoc.create_sbt_project.version.BuildInfo
import org.scalatest.{FreeSpec, Matchers}

class TestHelpAndVersion extends FreeSpec with Matchers with MainTestTools {
  "version option just prints the version info and exit" in {
    mockSystemProperties(
      "java.runtime.name" ? "Java Test Environment",
      "java.runtime.version" ? "1.8.0_testbuild",
      "java.vm.name" ? "Java Test VM",
      "java.vm.version" ? "25.25-test",
      "java.vm.info" ? "unit test mode"
    ) {
      runWithNoUserConfig("-v")(noErrorOutput=true).getStandardOutput.trim should be (
        s"""
          |create-sbt-project ${BuildInfo version}
          |Java Test Environment (build 1.8.0_testbuild)
          |Java Test VM (build 25.25-test, unit test mode)
        """.stripMargin.trim)
    }
    mockSystemProperties(
      "java.runtime.name" ? null,
      "java.vm.name" ? null
    ) {
      runWithNoUserConfig("-v")(noErrorOutput=true).getStandardOutput.trim should be (
        s"""
          |create-sbt-project ${BuildInfo version}
        """.stripMargin.trim)
    }
    mockSystemProperties(
      "java.runtime.name" ? "Java Test Environment",
      "java.runtime.version" ? null,
      "java.vm.name" ? "Java Test VM",
      "java.vm.version" ? null
    ) {
      runWithNoUserConfig("-v")(noErrorOutput=true).getStandardOutput.trim should be (
        s"""
          |create-sbt-project ${BuildInfo version}
          |Java Test Environment
          |Java Test VM
        """.stripMargin.trim)
    }
    mockSystemProperties(
      "java.runtime.name" ? null,
      "java.vm.name" ? "Java Test VM",
      "java.vm.version" ? "25.25-test",
      "java.vm.info" ? null
    ) {
      runWithNoUserConfig("-v")(noErrorOutput=true).getStandardOutput.trim should be (
        s"""
          |create-sbt-project ${BuildInfo version}
          |Java Test VM (build 25.25-test)
        """.stripMargin.trim)
    }
  }
  "help option just prints the usage and exits" in {
    runWithNoUserConfig("--help")(noErrorOutput=true).getStandardOutput should startWith("usage: create-sbt-project")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:61,代码来源:TestHelpAndVersion.scala


示例17: FileSystemSupportTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.io

import java.nio.file.FileSystems

import org.scalatest.{FreeSpec, Matchers}

class FileSystemSupportTest extends FreeSpec with Matchers {
  "user home directory returns the system property" in {
    val fs = new FileSystemSupport.Default(FileSystems getDefault) {
      def exposeUserHomeDirectory = userHomeDirectory
    }
    fs.exposeUserHomeDirectory should be (System getProperty "user.home")
  }
  "path of user preferences path is composed correctly even when user home ends in a slash" in {
    val fs = new FileSystemSupport.Default(FileSystems getDefault) {
      def exposeUserPreferencesFilePath = super.userPreferencesFilePath
      override protected def userHomeDirectory = "/home/user/"
    }
    fs.exposeUserPreferencesFilePath should be ("/home/user/.create-sbt-project.json")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:22,代码来源:FileSystemSupportTest.scala


示例18: WriteTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.io

import com.github.madoc.create_sbt_project.io.Write.WriteToAppendable
import org.scalatest.{FreeSpec, Matchers}

class WriteTest extends FreeSpec with Matchers {
  "writing a single character works as expected" in {
    val sb = new java.lang.StringBuilder
    val write = new Write {
      def apply(str:String) = {sb append str; this}
    }
    write('X')
    sb.toString should be ("X")
  }
  "the java.io.Writer for a Write instance ignores calls to flush() and close()" in {
    val sb = new java.lang.StringBuilder
    val w = new WriteToAppendable(sb)
    val writer = w.asJavaIOWriter
    writer.append("x").close()
    writer.close()
    writer.flush()
    writer.append("y")
    sb.toString should be ("xy")
  }
  "string escaping works as expected" in {
    val sb = new java.lang.StringBuilder
    new WriteToAppendable(sb).stringEscaped("line\nbreak, carriage\rreturn \t tab slash \\ quote \"")
    sb.toString should be ("line\\nbreak, carriage\\rreturn \\t tab slash \\\\ quote \\\"")
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:31,代码来源:WriteTest.scala


示例19: ActionTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.action.framework

import com.github.madoc.create_sbt_project.action.CreateDirectory
import com.github.madoc.create_sbt_project.action.framework.ActionResult.PreconditionFailures
import com.github.madoc.create_sbt_project.action.precondition.PreconditionFailure
import com.github.madoc.create_sbt_project.action.precondition.PreconditionFailure.DirectoryDoesNotExist
import com.github.madoc.create_sbt_project.io.FileSystemSupport
import org.scalatest.{FreeSpec, Matchers}

class ActionTest extends FreeSpec with Matchers {
  "adding an action list to a simple action returns an action list" in {
    val actionList = ActionList(CreateDirectory("dir1"), CreateDirectory("dir2"))
    val simpleAction = CreateDirectory("dir3")
    (simpleAction >> actionList) should be (ActionList(CreateDirectory("dir3"), CreateDirectory("dir1"), CreateDirectory("dir2")))
  }
  "if an action's precondition returns a failure, executing the action will result in failure" in {
    object ActionWithPreconditionFailure extends Action {
      protected def run(env:ActionEnvironment) = sys error "should not be called because there is a precondition failure"
      def precondition = {_:ActionEnvironment ? Seq(DirectoryDoesNotExist("dummy"))}
      def mightDealWith(failure:PreconditionFailure) = false
    }
    ActionWithPreconditionFailure(FileSystemSupport default) should be (PreconditionFailures(Seq(DirectoryDoesNotExist("dummy"))))
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:25,代码来源:ActionTest.scala


示例20: ActionListTest

//设置package包名称以及导入依赖的类
package com.github.madoc.create_sbt_project.action.framework

import java.util.concurrent.atomic.AtomicBoolean

import com.github.madoc.create_sbt_project.action.CreateDirectory
import com.github.madoc.create_sbt_project.action.framework.ActionResult.PreconditionFailures
import com.github.madoc.create_sbt_project.action.precondition.PreconditionFailure
import com.github.madoc.create_sbt_project.action.precondition.PreconditionFailure.DirectoryDoesNotExist
import com.github.madoc.create_sbt_project.io.FileSystemSupport
import org.scalatest.{FreeSpec, Matchers}

class ActionListTest extends FreeSpec with Matchers {
  "an ActionList combines the precondition failures that its contents might deal with" in {
    val al = ActionList(CreateDirectory("dir1"), CreateDirectory("dir2"))
    al.mightDealWith(DirectoryDoesNotExist("dir1")) should be (true)
    al.mightDealWith(DirectoryDoesNotExist("dir2")) should be (true)
    al.mightDealWith(DirectoryDoesNotExist("dir3")) should be (false)
  }
  "ActionList() returns the empty action" in {
    ActionList() should be (ActionList empty)
  }
  "an empty ActionList cannot deal with any precondition failure" in {
    ActionList.empty.mightDealWith(DirectoryDoesNotExist("dir")) should be (false)
  }
  "an empty ActionList returns a meaningful toString" in {
    ActionList.empty.toString should be ("ActionList()")
  }
  "a non-empty ActionList returns a meaningful toString" in {
    ActionList(CreateDirectory("foo"), CreateDirectory("bar")).toString should be ("ActionList(CreateDirectory(foo), CreateDirectory(bar))")
  }
  "when an action in the middle of an ActionList fails, the following action is not called" in {
    object NonFailingAction extends Action {
      protected def run(env:ActionEnvironment) = ActionResult.Success
      def precondition = {_:ActionEnvironment ? Seq()}
      def mightDealWith(failure:PreconditionFailure) = false
    }
    class FailingAction extends Action {
      val runCalled = new AtomicBoolean(false)
      protected def run(env:ActionEnvironment) = {
        runCalled set true
        ActionResult.PreconditionFailures(Seq(DirectoryDoesNotExist("dummy")))
      }
      def precondition = {_:ActionEnvironment ? Seq()}
      def mightDealWith(failure:PreconditionFailure) = false
    }
    val (action1, action2, action3) = (NonFailingAction, new FailingAction, new FailingAction)
    ActionList(action1, action2, action3)(FileSystemSupport default) should be (PreconditionFailures(Seq(DirectoryDoesNotExist("dummy"))))
    action2.runCalled.get should be (true)
    action3.runCalled.get should be (false)
  }
} 
开发者ID:Madoc,项目名称:create-sbt-project,代码行数:52,代码来源:ActionListTest.scala



注:本文中的org.scalatest.FreeSpec类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala DispatcherType类代码示例发布时间:2022-05-23
下一篇:
Scala FileOutputFormat类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap