Class: Hegel::Generator
- Inherits:
-
Object
- Object
- Hegel::Generator
- Defined in:
- lib/hegel/generator.rb,
sig/hegel.rbs
Overview
Base class for every value generator (Hegel::Generators.integers,
.booleans, .arrays, and so on) and the two combinators, #map and
#filter, that build a new generator out of an existing one. Mirrors
hegel-rust's Generator
Direct Known Subclasses
Hegel::Generators::ArrayGenerator, Hegel::Generators::BinaryGenerator, Hegel::Generators::BooleanGenerator, Hegel::Generators::CharactersGenerator, Hegel::Generators::CompositeGenerator, Hegel::Generators::DatesGenerator, Hegel::Generators::DatetimesGenerator, Hegel::Generators::DeferredGenerator, Hegel::Generators::DomainsGenerator, Hegel::Generators::EmailsGenerator, Hegel::Generators::FloatGenerator, Hegel::Generators::FromRegexGenerator, Hegel::Generators::HashGenerator, Hegel::Generators::IntegerGenerator, Hegel::Generators::IpAddressesGenerator, Hegel::Generators::JustGenerator, Hegel::Generators::OneOfGenerator, Hegel::Generators::OptionalGenerator, Hegel::Generators::SampledFromGenerator, Hegel::Generators::SetGenerator, Hegel::Generators::TextGenerator, Hegel::Generators::TimesGenerator, Hegel::Generators::TupleGenerator, Hegel::Generators::UrlsGenerator, Hegel::Generators::UuidsGenerator, Stateful::Pool::ValuesConsumed, Stateful::Pool::ValuesReusable
Defined Under Namespace
Instance Method Summary collapse
-
#do_draw(_tc) ⇒ Object
Draws one value using
tc(a Hegel::TestCase). -
#filter {|arg0| ... } ⇒ Generator
Returns a new Generator whose #do_draw retries this generator until
blockreturns true for the drawn value, or discards the test case if it never does. -
#map {|arg0| ... } ⇒ Generator
Returns a new Generator whose #do_draw runs
blockon the value this generator drew, spanned with HEGEL_LABEL_MAPPED so the shrinker treats the source draw and the transform as one unit (see hegel-rust's Mapped, src/generators/generators.rs).
Instance Method Details
#do_draw(_tc) ⇒ Object
Draws one value using tc (a Hegel::TestCase). Every concrete
generator implements this; the base class only exists to raise a
clear error for a subclass that forgot to.
17 18 19 |
# File 'lib/hegel/generator.rb', line 17 def do_draw(_tc) raise NotImplementedError, "#{self.class} must implement #do_draw" end |
#filter {|arg0| ... } ⇒ Generator
Returns a new Generator whose #do_draw retries this generator until
block returns true for the drawn value, or discards the test case
if it never does. See Filtered for the retry budget.
32 33 34 |
# File 'lib/hegel/generator.rb', line 32 def filter(&block) Filtered.new(self, block) end |
#map {|arg0| ... } ⇒ Generator
Returns a new Generator whose #do_draw runs block on the value this
generator drew, spanned with HEGEL_LABEL_MAPPED so the shrinker
treats the source draw and the transform as one unit (see
hegel-rust's Mapped, src/generators/generators.rs).
25 26 27 |
# File 'lib/hegel/generator.rb', line 25 def map(&block) Mapped.new(self, block) end |