Skip to content

Commit

Permalink
Additional tests and cleanup, migrated to ScalaTest 2.2.4 (only for a…
Browse files Browse the repository at this point in the history
…ccord-core tests for now, need to check into compatibility issues before migrating accord-scalatest).
  • Loading branch information
holograph committed Jun 10, 2015
1 parent 94b53f9 commit 217f8eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion core/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ libraryDependencies <++= scalaVersion {
case _ => Seq.empty
}

libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.3" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.2.4" % "test"

unmanagedSourceDirectories in Compile <+= ( scalaVersion, baseDirectory ) { case ( sv, base ) => sv match {
case v if v startsWith "2.10" => base / "src/main/scala-2.10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ package com.wix.accord.tests.dsl

import com.wix.accord._
import com.wix.accord.scalatest.ResultMatchers
import org.scalatest.{Matchers, WordSpec}
import org.scalatest.{Inside, Matchers, WordSpec}
import scala.collection.mutable

object CollectionOpsTests {
import dsl._

val seqEmptyValidator = validator[ Seq[_] ] { _ is empty }
val seqNotEmptyValidator = validator[ Seq[_] ] { _ is notEmpty }
val seqSizeValidator = validator[ Seq[_] ] { _ has size > 0 }
val seqEachValidator = validator[ Seq[ String ] ] { _.each is empty }

trait ArbitraryType
object ArbitraryType { def apply() = new ArbitraryType {} }

val seq = Seq.empty[ ArbitraryType ]
val emptyValidator = seq is empty
val notEmptyValidator = seq is notEmpty
val seqSizeValidator = validator[ Seq[_] ] { _ has size > 0 }

def visit[ T ]( coll: Traversable[ T ] )( visitor: T => Result ): Result = {
val visited = new Validator[ T ] {
def apply( v: T ) = visitor( v )
Expand All @@ -40,26 +40,20 @@ object CollectionOpsTests {
}
}

class CollectionOpsTests extends WordSpec with Matchers with ResultMatchers {
class CollectionOpsTests extends WordSpec with Matchers with ResultMatchers with Inside {
import CollectionOpsTests._
import combinators.{Empty, NotEmpty}

"empty" should {
"successfully validate a empty collection" in {
validate( Seq.empty )( seqEmptyValidator ) should be( aSuccess )
}
"successfully validate a non-empty collection" in {
validate( Seq( 1, 2, 3 ) )( seqEmptyValidator ) should be( aFailure )
}
}
"notEmpty" should {
"successfully validate a non-empty collection" in {
validate( Seq( 1, 2, 3 ) )( seqNotEmptyValidator ) should be( aSuccess )
}
"successfully validate a empty collection" in {
validate( Seq.empty )( seqNotEmptyValidator ) should be( aFailure )

"Calling \"has size\"" should {
"fail to compile on a type with no \"size\" property" in {
"""
import com.wix.accord.dsl._
val lhs: Int = 0
lhs has com.wix.accord.dsl.size > 5
""" shouldNot compile
}
}
"size extensions" should {

// No need to test all extensions -- these should be covered in OrderingOpsTest. We only need to test
// one to ensure correct constraint generation.
"generate a correctly prefixed constraint" in {
Expand All @@ -68,6 +62,18 @@ class CollectionOpsTests extends WordSpec with Matchers with ResultMatchers {
}
}

"The expression \"is empty\"" should {
"return an Empty combinator" in {
emptyValidator shouldBe an[ Empty[ Seq[ ArbitraryType ] ] ]
}
}

"The expression \"is notEmpty\"" should {
"return an Empty combinator" in {
notEmptyValidator shouldBe a[ NotEmpty[ Seq[ ArbitraryType ] ] ]
}
}

"Calling \".each\" on a Traversable" should {
"apply subsequent validation rules to all elements" in {
val coll = Seq.fill( 5 )( ArbitraryType.apply )
Expand Down

0 comments on commit 217f8eb

Please sign in to comment.