Additional generators based on StreamData
Summary
Functions
Generates DateTime.t/0 structs.
Generates Decimal.t/0 values based on the given opts.
Generates valid domains according to RFC-1035
Generates a Duration.t/0 struct.
Generates valid email addresses.
Generates valid strings from a given regex.
Generates IPv4 and IPv6 addresses as a string
Same as StreamData.float/1 but also accepts exclusion options
Same as StreamData.integer/0
Same as StreamData.integer/1 but also accepts a single end instead of
a range.
Returns a list of elements from the input enum in random order.
Generates Time.t/0 structs based on the provided opts.
Functions
@spec datetime(Keyword.t()) :: StreamData.t(DateTime.t())
Generates DateTime.t/0 structs.
Options
:min- (DateTime.t/0) if present, only datetimes after this value are generated:max- (DateTime.t/0) if present, only datetimes before this value are generated:date- (StreamData.t(Date.t())) if present, uses this strategy for the date part:time- (StreamData.t(Time.t())) if present, uses this strategy for the time part
If :min and/or :max are provided then :date and :time are ignored
Shrinking
Shrinks according to the provided options:
:minand/or:maxprovided -> towards:min:maxprovided -> towards:max:dateand/or:timeprovided -> towards the combination of the generators- No range provided: towards
DateTime.utc_now/0
@spec decimal(Keyword.t()) :: StreamData.t(Decimal.t())
Generates Decimal.t/0 values based on the given opts.
Options
:min- (Decimal.t/0) the minimum value to generate (inclusive):max- (Decimal.t/0) the maximum value to generate (inclusive):precision- (pos_integer/0) maximum number of decimal places:allow_nan?- (boolean() | nil) whether to allow"NaN". Ifnil, then"NaN"is allowed unless both:minand:maxare specified.:allow_infinity?- (boolean() | nil()) whether to allow"±Infinity". Ifnil,"±Infinity"is allowed based on:minand:max. If set totrue,"±Infinity"is generated even if:minand:maxare specified.
Shrinking
Shrinks towards Decimal.new(0) or :min if specified.
@spec domain(Keyword.t()) :: StreamData.t(String.t())
Generates valid domains according to RFC-1035
Top Level Domains are sampled from the IANA List, excluding
punycode ("xn--.*") domains
Options
:max_length- (pos_integer/0) the maximum length of the entire domain. Must be4 <= :max_length <= 255as per RFC-1035. Defaults to255.:max_label_length- (pos_integer/0) the maximum length of each label. Must be1 <= :max_label_length <= 63as per RFC-1035. Defaults to63.
Shrinking
Shrinks towards shorter and fewer labels, and to "com" top level domain, if allowed by
:max_length
@spec duration(Keyword.t()) :: StreamData.t(Duration.t())
Generates a Duration.t/0 struct.
Shrinks towards all values going to 0. Keep in mind the values in
Duration.t() structs can be negative. Therefore calling
duration(min: Duration.new!(day: 1)) can generate Duration.new!(day: -20)
Options
:min- (Duration.t/0|Keyword.t/0) the minimum duration to generate.:max- (Duration.t/0|Keyword.t/0) the maximum duration to generate.
Keep in mind that units are collapsed into months, seconds and microseconds.
Therefore passing min: [week: 5] can set any value between :microsecond and :week,
but :year and :month are always set to 0. This is because there is no conversion
from week to month.
Shrinking
Shrinks towards zero values. Keep in mind the values in Duration.t/0 structs
can be negative. Therefore calling duration(min: Duration.new!(day: 1))
can generate Duration.new!(day: -20)
@spec email(Keyword.t()) :: StreamData.t(String.t())
Generates valid email addresses.
Does not follow RFC-5322. Instead, it generates emails considered valid by the most common internet providers. Some differences:
- Addresses are limited to ASCII characters
- No double quotes (
") allowed - No single domain such as
john@doe - No IP address as domain
Options
:domains- (StreamData.t(String.t())) strategy that generates domains. If not provided thendomain/1is used.:max_length- (pos_integer/0) maximum length of the entire email. Must be at least6, since the shortest possible email is of the forma@b.cd. Defaults to the maximum email length allowed (254)
Shrinking
Shrinks towards shorter local parts. The domain part follows :domains behaviour.
@spec from_regex(Regex.t() | String.t(), Keyword.t()) :: StreamData.t(String.t())
Generates valid strings from a given regex.
Refer to the README for the list of supported regex features and patterns.
Options
:character_set- (:printable | :all) if set to:printableonly printable characters are generated, otherwise every character in the ASCII extended range 0-255 can be generated. Defaults to:all
Shrinking
Shrinks towards lower ASCII characters and shorter expressions. For example
from_regex(~r/[A-Z]+_[a-z]+/) shrinks towards A_a
@spec ip_address(Keyword.t()) :: StreamData.t(String.t())
Generates IPv4 and IPv6 addresses as a string
Options:
:version- (4 | 6) generates IP adresses only of this version. Defaults to generating both IPv4 and IPv6.:network- (String.t/0) A string representing an IPv4 network or an IPv6 network, such as"123.111.0.0/16"or"1234:3210::/16. If specified, only IPs in the given range are generated.
In case both :version and :network are specified, the version must match the network.
In case :network is not set then IPs from IPv4 Special Registry
and/or IPv6 Special Registry
are generated alongside random IPs for better edge-case coverage.
Shrinking
Shrinks towards lower IP addresses. For example
ip_address(network: "255.255.255.0/8") shrinks towards "255.255.255.0"
@spec more_float(Keyword.t()) :: StreamData.t(float())
Same as StreamData.float/1 but also accepts exclusion options
Options
:exclude_min?- (boolean/0) whether to exclude the min value if set. Defaults tofalse:exclude_max?- (boolean/0) whether to exclude the max value if set. Defaults tofalse
Shrinking
Same as StreamData.float/1 since the additional options don't modify the underlying
generator
Same as StreamData.integer/0
@spec more_integer(Keyword.t() | Range.t()) :: StreamData.t(integer())
Same as StreamData.integer/1 but also accepts a single end instead of
a range.
Options
Shrinking
If only one of :min, :max is specified it shrinks toward the specified limit. In any
other case it behaves as StreamData.integer/1
Returns a list of elements from the input enum in random order.
This function can return duplicates if the input enum contains duplicate elements.
Options
:min_length- (non_neg_integer/0) the minimum length of the list. Defaults to 0:max_length- (non_neg_integer/0) the maximum length of the list. Defaults to the length of the input enum.
Shrinking
Shrinks towards smaller lists and in the same order as the original input
@spec time(Keyword.t()) :: StreamData.t(Time.t())
Generates Time.t/0 structs based on the provided opts.
Options
:min- (Time.t/0) the minimum time to generate (inclusive):max- (Time.t/0) the maximum time to generate (inclusive)
Shrinking
Shrinks towards ~T[00:00:00] or the specified :min.
@spec url() :: StreamData.t(String.t())
Generates valid http/https URLs according to RFC-3986
URLs contain ASCII characters only