当前位置: 首页>>代码示例>>Scala>>正文


Scala FreeSpec类代码示例

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


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


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