Hegel.Generators (hegel_elixir v0.1.1)
View SourceGenerators for Hegel property tests.
Functions use familiar StreamData names such as integer/1, list_of/2,
map/2, and bind/2. A %Hegel.Generator{} draws through the active test
case. libhegel chooses primitives; compound generators add spans and
collections that guide shrinking.
Use composite/1 for dependent draws:
pair =
composite(fn draw ->
lower = draw.(integer(0..10))
{lower, draw.(integer(lower..20))}
end)
Summary
Functions
Alias for binary/1.
Generates arbitrary byte-aligned binaries.
Draws from generator, then uses its value to build a dependent generator.
Generates booleans, with probability as the chance of true.
Alias for boolean/0.
Generates an integer byte (0..255).
Generates one Unicode character as its integer codepoint.
Alias for character/1.
Alias for character/1, matching StreamData's terminology.
Creates a generator from imperative draw code.
Returns value without drawing from libhegel.
Generates Date values.
Alias for date/1.
Generates naive NaiveDateTime values between inclusive bounds.
Alias for datetime/1.
Generates domain names.
Alias for domain/1.
Generates RFC 5321/5322 email address strings.
Keeps values satisfying predicate, discarding rejected choice spans.
Generates a fixed-length list, drawing from each supplied generator.
Generates maps with fixed keys and one generator per value.
Alias for bind/2.
Generates finite BEAM floats using libhegel's IEEE-754 draw.
Alias for float/1.
Chooses from {positive_weight, generator} pairs.
Generates strings matching a Python re pattern.
Generates an arbitrary-precision integer.
Generates an integer in the inclusive interval min..max.
Alias for integer/0.
Generates an Erlang/Elixir IP-address tuple.
Alias for ip_address/1.
Generates IPv4 address tuples.
Generates IPv6 address tuples.
Alias for constant/1, matching Hegel's other frontends.
Defers generator construction until draw time.
Generates variable-length lists from element_generator.
Alias for list_of/2.
Transforms each value produced by generator.
Generates variable-size maps from key and value generators.
Picks a value from a non-empty, finite enumerable.
Alias for datetime/1.
Generates integers greater than or equal to zero.
Generates either nil or a value from generator.
Chooses and draws from one of a non-empty enumerable of generators.
Convenience two-generator form of one_of/1.
Alias for nullable/2.
Generates integers greater than zero.
Alias for from_regex/2.
Alias for member_of/1, matching Hegel's other frontends.
StreamData-style string entry point.
Generates UTF-8 text.
Alias for text/1.
Generates Time values between inclusive :min and :max bounds.
Alias for time/1.
Generates tuples matching the fixed shape of generator_tuple.
Alias for character/1.
Alias for text/1, emphasizing the returned Elixir UTF-8 binary.
Generates lists whose elements are unique.
Generates RFC 3986 HTTP or HTTPS URL strings.
Generates canonical lower-case UUID strings.
Alias for uuid/1.
Alias for boolean/1.
Types
Functions
@spec binaries(options()) :: Hegel.Generator.t(binary())
Alias for binary/1.
@spec binary(options()) :: Hegel.Generator.t(binary())
Generates arbitrary byte-aligned binaries.
@spec bind(Hegel.Generator.t(input), (input -> Hegel.Generator.t(output))) :: Hegel.Generator.t(output) when input: term(), output: term()
Draws from generator, then uses its value to build a dependent generator.
This is also known as flat_map in Hegel's other frontends.
@spec boolean(number()) :: Hegel.Generator.t(boolean())
Generates booleans, with probability as the chance of true.
@spec booleans() :: Hegel.Generator.t(boolean())
Alias for boolean/0.
@spec byte() :: Hegel.Generator.t(byte())
Generates an integer byte (0..255).
@spec character(options()) :: Hegel.Generator.t(non_neg_integer())
Generates one Unicode character as its integer codepoint.
Elixir represents characters as integers; use text(length: 1) when a
one-codepoint binary is preferred.
@spec characters(options()) :: Hegel.Generator.t(non_neg_integer())
Alias for character/1.
@spec codepoint(:utf8 | :unicode | :ascii | options()) :: Hegel.Generator.t(non_neg_integer())
Alias for character/1, matching StreamData's terminology.
@spec composite(function(), options()) :: Hegel.Generator.t(term())
Creates a generator from imperative draw code.
The callback receives draw, an arity-one function accepting another
generator. An arity-two callback also receives the active test case as its
first argument. Hegel groups nested draws in one frontend-owned
span; pass label: non_negative_integer to distinguish custom structures.
@spec constant(value) :: Hegel.Generator.t(value) when value: term()
Returns value without drawing from libhegel.
@spec date(Date.Range.t() | options()) :: Hegel.Generator.t(Date.t())
Generates Date values.
Accepts either a Date.Range or :min and :max options. The default is
the conventional Hypothesis range 0001-01-01 through 9999-12-31.
@spec dates(Date.Range.t() | options()) :: Hegel.Generator.t(Date.t())
Alias for date/1.
@spec datetime(options()) :: Hegel.Generator.t(NaiveDateTime.t())
Generates naive NaiveDateTime values between inclusive bounds.
libhegel generates datetimes without a timezone. This function returns
NaiveDateTime.
@spec datetimes(options()) :: Hegel.Generator.t(NaiveDateTime.t())
Alias for datetime/1.
@spec domain(options()) :: Hegel.Generator.t(String.t())
Generates domain names.
@spec domains(options()) :: Hegel.Generator.t(String.t())
Alias for domain/1.
@spec email() :: Hegel.Generator.t(String.t())
Generates RFC 5321/5322 email address strings.
@spec emails() :: Hegel.Generator.t(String.t())
Alias for email/0.
@spec filter( Hegel.Generator.t(value), (value -> as_boolean(term())), pos_integer() | options() ) :: Hegel.Generator.t(value) when value: term()
Keeps values satisfying predicate, discarding rejected choice spans.
After max_attempts local retries the complete test case is rejected, which
lets libhegel's filter health check diagnose a narrow predicate.
@spec fixed_list([Hegel.Generator.t(term())]) :: Hegel.Generator.t([term()])
Generates a fixed-length list, drawing from each supplied generator.
@spec fixed_map(%{optional(term()) => Hegel.Generator.t(term())}) :: Hegel.Generator.t(map())
Generates maps with fixed keys and one generator per value.
@spec flat_map(Hegel.Generator.t(input), (input -> Hegel.Generator.t(output))) :: Hegel.Generator.t(output) when input: term(), output: term()
Alias for bind/2.
@spec float(options()) :: Hegel.Generator.t(float())
Generates finite BEAM floats using libhegel's IEEE-754 draw.
Supported options are :min, :max, :exclude_min, :exclude_max,
:width (32 or 64), and :allow_subnormal. The libhegel flags
BEAM float terms cannot represent NaN or infinity, so
:allow_nan and :allow_infinity must be false.
@spec floats(options()) :: Hegel.Generator.t(float())
Alias for float/1.
@spec frequency([{pos_integer(), Hegel.Generator.t(term())}]) :: Hegel.Generator.t(term())
Chooses from {positive_weight, generator} pairs.
@spec from_regex(String.t(), options()) :: Hegel.Generator.t(String.t())
Generates strings matching a Python re pattern.
@spec integer() :: Hegel.Generator.t(integer())
Generates an arbitrary-precision integer.
A range supplies inclusive bounds. For a range with a non-unit step, Hegel draws an index into the range. With no argument, the generator uses signed 128-bit bounds because libhegel's integer primitive requires a finite domain.
@spec integer(Range.t() | options()) :: Hegel.Generator.t(integer())
@spec integer(integer(), integer()) :: Hegel.Generator.t(integer())
Generates an integer in the inclusive interval min..max.
@spec integers() :: Hegel.Generator.t(integer())
Alias for integer/0.
@spec ip_address(options()) :: Hegel.Generator.t(:inet.ip_address())
Generates an Erlang/Elixir IP-address tuple.
Pass version: 4 or version: 6 to restrict the family; by default the
engine chooses between both under a ONE_OF span.
@spec ip_addresses(options()) :: Hegel.Generator.t(:inet.ip_address())
Alias for ip_address/1.
@spec ipv4() :: Hegel.Generator.t(:inet.ip4_address())
Generates IPv4 address tuples.
@spec ipv6() :: Hegel.Generator.t(:inet.ip6_address())
Generates IPv6 address tuples.
@spec just(value) :: Hegel.Generator.t(value) when value: term()
Alias for constant/1, matching Hegel's other frontends.
@spec lazy((-> Hegel.Generator.t(value))) :: Hegel.Generator.t(value) when value: term()
Defers generator construction until draw time.
Use this recursion primitive with a zero-arity function that returns a generator on each draw.
@spec list_of(Hegel.Generator.t(value), options()) :: Hegel.Generator.t([value]) when value: term()
Generates variable-length lists from element_generator.
@spec lists(Hegel.Generator.t(value), options()) :: Hegel.Generator.t([value]) when value: term()
Alias for list_of/2.
@spec map(Hegel.Generator.t(input), (input -> output)) :: Hegel.Generator.t(output) when input: term(), output: term()
Transforms each value produced by generator.
@spec map_of(Hegel.Generator.t(key), Hegel.Generator.t(value), options()) :: Hegel.Generator.t(%{optional(key) => value}) when key: term(), value: term()
Generates variable-size maps from key and value generators.
@spec member_of(Enumerable.t()) :: Hegel.Generator.t(term())
Picks a value from a non-empty, finite enumerable.
@spec naive_datetime(options()) :: Hegel.Generator.t(NaiveDateTime.t())
Alias for datetime/1.
@spec non_negative_integer() :: Hegel.Generator.t(non_neg_integer())
Generates integers greater than or equal to zero.
@spec nullable(Hegel.Generator.t(value), options()) :: Hegel.Generator.t(value | nil) when value: term()
Generates either nil or a value from generator.
@spec one_of(Enumerable.t()) :: Hegel.Generator.t(term())
Chooses and draws from one of a non-empty enumerable of generators.
@spec one_of(Hegel.Generator.t(term()), Hegel.Generator.t(term())) :: Hegel.Generator.t(term())
Convenience two-generator form of one_of/1.
@spec optional(Hegel.Generator.t(value), options()) :: Hegel.Generator.t(value | nil) when value: term()
Alias for nullable/2.
@spec positive_integer() :: Hegel.Generator.t(pos_integer())
Generates integers greater than zero.
@spec regex(String.t(), options()) :: Hegel.Generator.t(String.t())
Alias for from_regex/2.
@spec sampled_from(Enumerable.t()) :: Hegel.Generator.t(term())
Alias for member_of/1, matching Hegel's other frontends.
@spec string(:unicode | :utf8 | :ascii | binary(), options()) :: Hegel.Generator.t(String.t())
StreamData-style string entry point.
@spec text(options()) :: Hegel.Generator.t(String.t())
Generates UTF-8 text.
Length options are :length, :min_length, and :max_length (the
*_size spellings are also accepted). Character options mirror libhegel:
:alphabet, :codec, :min_codepoint, :max_codepoint, :categories,
:exclude_categories, :include_characters, and :exclude_characters.
@spec texts(options()) :: Hegel.Generator.t(String.t())
Alias for text/1.
@spec time(options()) :: Hegel.Generator.t(Time.t())
Generates Time values between inclusive :min and :max bounds.
@spec times(options()) :: Hegel.Generator.t(Time.t())
Alias for time/1.
@spec tuple(tuple()) :: Hegel.Generator.t(tuple())
Generates tuples matching the fixed shape of generator_tuple.
@spec unicode_character(options()) :: Hegel.Generator.t(non_neg_integer())
Alias for character/1.
@spec unicode_string(options()) :: Hegel.Generator.t(String.t())
Alias for text/1, emphasizing the returned Elixir UTF-8 binary.
@spec uniq_list_of(Hegel.Generator.t(value), options()) :: Hegel.Generator.t([value]) when value: term()
Generates lists whose elements are unique.
:uniq_fun has the same meaning as Enum.uniq_by/2. The collection
rejection primitive retries duplicate candidates without adding them to the
requested size.
@spec url() :: Hegel.Generator.t(String.t())
Generates RFC 3986 HTTP or HTTPS URL strings.
@spec urls() :: Hegel.Generator.t(String.t())
Alias for url/0.
@spec uuid(options()) :: Hegel.Generator.t(String.t())
Generates canonical lower-case UUID strings.
@spec uuids(options()) :: Hegel.Generator.t(String.t())
Alias for uuid/1.
@spec weighted_boolean(number()) :: Hegel.Generator.t(boolean())
Alias for boolean/1.