migrate to scalatest 2.2.4

This commit is contained in:
Eugene Yokota 2015-09-04 17:40:48 -04:00 committed by Dale Wijnand
parent 53e719656f
commit d93db4a634
No known key found for this signature in database
GPG Key ID: 4F256E3D151DF5EF
3 changed files with 94 additions and 88 deletions

View File

@ -1,54 +1,60 @@
package sbt.util.internal
package complete
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import java.io.File
import sbt.io.IO._
class FileExamplesTest extends Specification {
class FileExamplesTest extends UnitSpec {
"listing all files in an absolute base directory" should {
"produce the entire base directory's contents" in new directoryStructure {
fileExamples().toList should containTheSameElementsAs(allRelativizedPaths)
"listing all files in an absolute base directory" should
"produce the entire base directory's contents" in {
val _ = new DirectoryStructure {
fileExamples().toList should contain theSameElementsAs (allRelativizedPaths)
}
}
"listing files with a prefix that matches none" should
"produce an empty list" in {
val _ = new DirectoryStructure(withCompletionPrefix = "z") {
fileExamples().toList shouldBe empty
}
}
"listing single-character prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "f") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
"listing directory-prefixed files" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
it should "produce sub-dir contents only when appending a file separator to the directory" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator) {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
"listing files with a prefix that matches none" should {
"produce an empty list" in new directoryStructure(withCompletionPrefix = "z") {
fileExamples().toList should beEmpty
}
}
"listing single-character prefixed files" should {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "f") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
}
}
"listing directory-prefixed files" should {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "far") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
"listing files with a sub-path prefix" should
"produce matching paths only" in {
val _ = new DirectoryStructure(withCompletionPrefix = "far" + File.separator + "ba") {
fileExamples().toList should contain theSameElementsAs (prefixedPathsOnly)
}
}
"produce sub-dir contents only when appending a file separator to the directory" in new directoryStructure(withCompletionPrefix = "far" + File.separator) {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
"completing a full path" should
"produce a list with an empty string" in {
val _ = new DirectoryStructure(withCompletionPrefix = "bazaar") {
fileExamples().toList shouldEqual List("")
}
}
}
"listing files with a sub-path prefix" should {
"produce matching paths only" in new directoryStructure(withCompletionPrefix = "far" + File.separator + "ba") {
fileExamples().toList should containTheSameElementsAs(prefixedPathsOnly)
}
}
"completing a full path" should {
"produce a list with an empty string" in new directoryStructure(withCompletionPrefix = "bazaar") {
fileExamples().toList shouldEqual List("")
}
}
class directoryStructure(withCompletionPrefix: String = "") extends Scope with DelayedInit {
class DirectoryStructure(withCompletionPrefix: String = "") extends DelayedInit {
var fileExamples: FileExamples = _
var baseDir: File = _
var childFiles: List[File] = _

View File

@ -1,26 +1,23 @@
package sbt.util.internal
package complete
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
class FixedSetExamplesTest extends UnitSpec {
class FixedSetExamplesTest extends Specification {
"adding a prefix" should {
"produce a smaller set of examples with the prefix removed" in new examples {
fixedSetExamples.withAddedPrefix("f")() must containTheSameElementsAs(List("oo", "ool", "u"))
fixedSetExamples.withAddedPrefix("fo")() must containTheSameElementsAs(List("o", "ol"))
fixedSetExamples.withAddedPrefix("b")() must containTheSameElementsAs(List("ar"))
"adding a prefix" should "produce a smaller set of examples with the prefix removed" in {
val _ = new Examples {
fixedSetExamples.withAddedPrefix("f")() should contain theSameElementsAs (List("oo", "ool", "u"))
fixedSetExamples.withAddedPrefix("fo")() should contain theSameElementsAs (List("o", "ol"))
fixedSetExamples.withAddedPrefix("b")() should contain theSameElementsAs (List("ar"))
}
}
"without a prefix" should {
"produce the original set" in new examples {
fixedSetExamples() mustEqual exampleSet
"without a prefix" should "produce the original set" in {
val _ = new Examples {
fixedSetExamples() shouldBe exampleSet
}
}
trait examples extends Scope {
trait Examples {
val exampleSet = List("foo", "bar", "fool", "fu")
val fixedSetExamples = FixedSetExamples(exampleSet)
}

View File

@ -1,61 +1,64 @@
package sbt.util.internal
package complete
import org.specs2.mutable.Specification
import org.specs2.specification.Scope
import Completion._
class ParserWithExamplesTest extends Specification {
class ParserWithExamplesTest extends UnitSpec {
"listing a limited number of completions" should {
"grab only the needed number of elements from the iterable source of examples" in new parserWithLazyExamples {
parserWithExamples.completions(0)
examples.size shouldEqual maxNumberOfExamples
"listing a limited number of completions" should
"grab only the needed number of elements from the iterable source of examples" in {
val _ = new ParserWithLazyExamples {
parserWithExamples.completions(0)
examples.size shouldEqual maxNumberOfExamples
}
}
}
"listing only valid completions" should {
"use the delegate parser to remove invalid examples" in new parserWithValidExamples {
val validCompletions = Completions(Set(
suggestion("blue"),
suggestion("red")))
parserWithExamples.completions(0) shouldEqual validCompletions
"listing only valid completions" should
"use the delegate parser to remove invalid examples" in {
val _ = new ParserWithValidExamples {
val validCompletions = Completions(Set(
suggestion("blue"),
suggestion("red")))
parserWithExamples.completions(0) shouldEqual validCompletions
}
}
}
"listing valid completions in a derived parser" should {
"produce only valid examples that start with the character of the derivation" in new parserWithValidExamples {
val derivedCompletions = Completions(Set(
suggestion("lue")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
"listing valid completions in a derived parser" should
"produce only valid examples that start with the character of the derivation" in {
val _ = new ParserWithValidExamples {
val derivedCompletions = Completions(Set(
suggestion("lue")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
}
}
"listing valid and invalid completions" should {
"produce the entire source of examples" in new parserWithAllExamples {
val completions = Completions(examples.map(suggestion(_)).toSet)
parserWithExamples.completions(0) shouldEqual completions
"listing valid and invalid completions" should
"produce the entire source of examples" in {
val _ = new parserWithAllExamples {
val completions = Completions(examples.map(suggestion(_)).toSet)
parserWithExamples.completions(0) shouldEqual completions
}
}
}
"listing valid and invalid completions in a derived parser" should {
"produce only examples that start with the character of the derivation" in new parserWithAllExamples {
val derivedCompletions = Completions(Set(
suggestion("lue"),
suggestion("lock")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
"listing valid and invalid completions in a derived parser" should
"produce only examples that start with the character of the derivation" in {
val _ = new parserWithAllExamples {
val derivedCompletions = Completions(Set(
suggestion("lue"),
suggestion("lock")))
parserWithExamples.derive('b').completions(0) shouldEqual derivedCompletions
}
}
}
class parserWithLazyExamples extends parser(GrowableSourceOfExamples(), maxNumberOfExamples = 5, removeInvalidExamples = false)
class ParserWithLazyExamples extends ParserExample(GrowableSourceOfExamples(), maxNumberOfExamples = 5, removeInvalidExamples = false)
class parserWithValidExamples extends parser(removeInvalidExamples = true)
class ParserWithValidExamples extends ParserExample(removeInvalidExamples = true)
class parserWithAllExamples extends parser(removeInvalidExamples = false)
class parserWithAllExamples extends ParserExample(removeInvalidExamples = false)
case class parser(examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"),
case class ParserExample(examples: Iterable[String] = Set("blue", "yellow", "greeen", "block", "red"),
maxNumberOfExamples: Int = 25,
removeInvalidExamples: Boolean) extends Scope {
removeInvalidExamples: Boolean) {
import DefaultParsers._