Skip to content

Commit

Permalink
daveD - Renamed Empty to EmptyGenerators, as was being mixed up with …
Browse files Browse the repository at this point in the history
…Steam.Empty
  • Loading branch information
daviddenton committed Oct 25, 2015
1 parent d2a8fe3 commit eba1e3c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/main/scala/io/github/databob/Databob.scala
Expand Up @@ -57,21 +57,23 @@ object Databob {
* @param mf manifest for the object to generate
* @return the generated object
*/
def mk[A](implicit generators: Generators = Empty, mf: Manifest[A]): A = new Databob(generators).mk[A]
def mk[A](implicit generators: Generators = EmptyGenerators, mf: Manifest[A]): A = new Databob(generators).mk[A]

/**
* Make a default object using the overrides provided and falling back to the set of Default generators
* @param overrides the set of override generators to apply to the generation
* @param mf manifest for the object to generate
* @return the generated object
*/
def default[A](implicit overrides: Generators = Empty, mf: Manifest[A]): A = mk[A](overrides ++ Defaults, mf)
def default[A](implicit overrides: Generators = EmptyGenerators, mf: Manifest[A]): A = mk[A](overrides ++ Defaults, mf)

/**
* Make a random object using the overrides provided and falling back to the set of Random generators
* @param overrides the set of override generators to apply to the generation
* @param mf manifest for the object to generate
* @return the generated object
*/
def random[A](implicit overrides: Generators = Empty, mf: Manifest[A]): A = mk[A](overrides ++ Random, mf)
def random[A](implicit overrides: Generators = EmptyGenerators, mf: Manifest[A]): A = {
mk[A](overrides ++ Random, mf)
}
}
3 changes: 2 additions & 1 deletion src/main/scala/io/github/databob/Generator.scala
@@ -1,5 +1,6 @@
package io.github.databob

import io.github.databob.generators.Generators._
import io.github.databob.generators.{ErasureMatchingGenerator, Generators, TypeMatchingGenerator}

/**
Expand All @@ -19,7 +20,7 @@ trait Generator[A] {
* @param that the generator to append
* @return the combined Generators
*/
def +(that: Generator[_]): Generators = this +: (that +: Generators.Empty)
def +(that: Generator[_]): Generators = this +: (that +: EmptyGenerators)
}

object Generator {
Expand Down
Expand Up @@ -47,7 +47,7 @@ class Generators(generators: Iterable[Generator[_]] = Nil) extends Iterable[Gene

object Generators {

lazy val Empty = new Generators()
lazy val EmptyGenerators = new Generators()

lazy val Defaults =
PrimitiveGenerators.Defaults ++
Expand Down
11 changes: 6 additions & 5 deletions src/test/scala/databob/examples/Examples.scala
Expand Up @@ -4,10 +4,9 @@ import java.time.ZonedDateTime

import io.github.databob.Databob
import io.github.databob.Generator.typeIs
import io.github.databob.generators.CollectionSizeRange
import io.github.databob.generators.CollectionSizeRange.collectionSizeRange
import io.github.databob.generators.CollectionSizeRange._
import io.github.databob.generators.{CollectionSizeRange, Generators}

import scala.collection.immutable.Stream.Empty
import scala.util.Try

case class ReadReceipt(readDate: ZonedDateTime)
Expand Down Expand Up @@ -36,14 +35,16 @@ object Examples extends App {
println(randomObjectWithOverridenField)

def objectWithCustomCollectionSizes = {
implicit val generators = collectionSizeRange(() => CollectionSizeRange(3, 5))
implicit val generators = collectionSizeRange(CollectionSizeRange(3, 5))
Databob.random[Email]
}

println(objectWithCustomCollectionSizes)

def usingACustomGenerator = {
implicit val generators = typeIs(databob => EmailAddress(databob.mk[String] + "@" + databob.mk[String] + ".com")) +: Empty
implicit val generators = typeIs(databob => {
EmailAddress(databob.mk[String] + "@" + databob.mk[String] + ".com")
}) +: Generators.EmptyGenerators
Databob.random[Email]
}

Expand Down

0 comments on commit eba1e3c

Please sign in to comment.