generators library

The generator catalog, on its own.

Everything package:hegel/hegel.dart exports about making values, for anyone who would rather prefix them than import forty names:

import 'package:hegel/hegel.dart';
import 'package:hegel/generators.dart' as gen;

final names = gen.text(minLength: 1);

property('a greeting keeps the name it was given', (tc) {
  final name = tc.draw(names, name: 'name');
  expect(greet(name), contains(name));
});

The same generators either way; this is a spelling, not a second API.

Pool comes with them, which is not itself a generator: it is where pool.reusable and pool.consumed come from, and putting a pool on the far side of an import from the generators it hands out would be a seam across one idea.

Classes

DeferredGenerator<T>
The generator deferred returns, before and after it is defined.
Generator<T>
A recipe for values of type T.
Pool<T>
A set of values a stateful test made, that the engine can choose among.
TextGenerator
Generates strings over an alphabet.

Functions

bigIntegers({BigInt? min, BigInt? max}) Generator<BigInt>
Generates integers of any width between min and max inclusive.
booleans({double probability = 0.5}) Generator<bool>
Generates true with probability probability, false otherwise.
bytes({int minLength = 0, int? maxLength}) Generator<Uint8List>
Generates byte strings of minLength to maxLength bytes.
characters({String? codec, int? minCodepoint, int? maxCodepoint, List<String>? categories, List<String>? excludeCategories, String? includeCharacters, String? excludeCharacters}) TextGenerator
Generates single characters, drawn the way text draws them.
composite<T>(T build(TestCase testCase)) Generator<T>
Generates values build puts together out of draws of its own.
dates({DateTime? min, DateTime? max}) Generator<DateTime>
Generates dates between min and max inclusive.
dateTimes({DateTime? min, DateTime? max}) Generator<DateTime>
Generates dates and times between min and max inclusive.
deferred<T>() DeferredGenerator<T>
A generator that stands in for one not written yet.
domains({int maxLength = 255}) Generator<String>
Generates fully-qualified domain names of at most maxLength characters.
doubles({double min = double.negativeInfinity, double max = double.infinity, bool? allowNan, bool? allowInfinity, bool excludeMin = false, bool excludeMax = false}) Generator<double>
Generates doubles between min and max.
durations({Duration? min, Duration? max}) Generator<Duration>
Generates durations between min and max inclusive.
emails() Generator<String>
Generates email addresses, per RFC 5321 and 5322.
fromRegex(String pattern, {bool fullMatch = true, TextGenerator? alphabet}) Generator<String>
Generates strings matching pattern, in Python re syntax.
integers({int? min, int? max}) Generator<int>
Generates integers between min and max inclusive.
ipAddresses({InternetAddressType? type}) Generator<InternetAddress>
Generates IP addresses of type, or of either kind when none is given.
just<T>(T value) Generator<T>
Generates value and nothing else.
lists<T>(Generator<T> elements, {int minLength = 0, int? maxLength, bool unique = false}) Generator<List<T>>
Generates lists of what elements generates.
maps<K, V>(Generator<K> keys, Generator<V> values, {int minLength = 0, int? maxLength}) Generator<Map<K, V>>
Generates maps of what keys and values generate.
oneOf<T>(List<Generator<T>> options, {List<int>? weights}) Generator<T>
Generates values from whichever of options each case picks.
optional<T>(Generator<T> value) Generator<T?>
Generates values from value, or null.
sampledFrom<T>(List<T> values) Generator<T>
Generates values picked from values.
sets<T>(Generator<T> elements, {int minLength = 0, int? maxLength}) Generator<Set<T>>
Generates sets of what elements generates.
text({int minLength = 0, int? maxLength, String? codec, int? minCodepoint, int? maxCodepoint, List<String>? categories, List<String>? excludeCategories, String? includeCharacters, String? excludeCharacters}) TextGenerator
Generates strings of minLength to maxLength characters.
times({Duration? min, Duration? max}) Generator<Duration>
Generates times of day between min and max inclusive.
tuple2<A, B>(Generator<A> first, Generator<B> second) Generator<(A, B)>
Generates pairs of what first and second generate.
tuple3<A, B, C>(Generator<A> first, Generator<B> second, Generator<C> third) Generator<(A, B, C)>
Generates triples of what first, second and third generate.
tuple4<A, B, C, D>(Generator<A> first, Generator<B> second, Generator<C> third, Generator<D> fourth) Generator<(A, B, C, D)>
Generates quadruples of what first to fourth generate.
urls() Generator<String>
Generates http and https URLs, per RFC 3986.
uuids({int? version}) Generator<String>
Generates UUIDs in the canonical 8-4-4-4-12 form.