Hegel 0.18.3
Property-based testing for C++
Loading...
Searching...
No Matches
core.h
1#pragma once
2
3#include <any>
4#include <cstdint>
5#include <functional>
6#include <memory>
7#include <optional>
8#include <stdexcept>
9#include <string>
10#include <string_view>
11#include <type_traits>
12#include <typeinfo>
13#include <utility>
14#include <vector>
15
16#include "config.h"
17#include "internal.h"
18#include "printer.h"
19#include "repr.h"
20#include "test_case.h"
21
26
27 template <typename T> class AnyGenerator;
28 template <typename T> class Generator;
29 template <typename U, bool SourcePrintable> class Mapped;
30
51 template <typename T> class IGenerator {
52 public:
54 using value_type = T;
55
56 IGenerator() = default;
57 virtual ~IGenerator() = default;
58
64 virtual T do_draw(const TestCase& tc) const = 0;
65
74 virtual uint64_t label() const {
75 return internal::type_label(typeid(*this));
76 }
77
90 virtual T
92 const std::function<bool(const T&)>& predicate) const {
93 uint64_t attempt =
94 internal::label(internal::LabelName::FilterAttempt);
95 for (int i = 0; i < internal::filter_attempts; ++i) {
96 internal::start_span(tc, attempt);
97 T value = do_draw(tc);
98 if (predicate(value)) {
99 internal::stop_span(tc);
100 return value;
101 }
102 internal::stop_span(tc, true);
103 }
104 tc.reject();
105 }
106 };
107
150 template <typename T> class IPrintableGenerator : public IGenerator<T> {
151 public:
161 virtual T do_draw_and_print(const TestCase& tc,
162 Printer& printer) const = 0;
163
172 T do_draw(const TestCase& tc) const override {
173 Printer silent = Printer::noop();
174 return do_draw_and_print(tc, silent);
175 }
176
191 const TestCase& tc, const std::function<bool(const T&)>& predicate,
192 Printer& printer) const {
193 uint64_t attempt =
194 internal::label(internal::LabelName::FilterAttempt);
195 for (int i = 0; i < internal::filter_attempts; ++i) {
196 internal::start_span(tc, attempt);
197 Speculation speculation = printer.speculate();
198 T value = do_draw_and_print(tc, printer);
199 if (predicate(value)) {
200 speculation.commit();
201 internal::stop_span(tc);
202 return value;
203 }
204 speculation.abort();
205 internal::stop_span(tc, true);
206 }
207 tc.reject();
208 }
209 };
210
212 namespace detail {
213
214 template <typename T>
215 class ValuePrinted : public IPrintableGenerator<T> {
216 public:
217 T do_draw(const TestCase& tc) const override = 0;
218
219 T do_draw_and_print(const TestCase& tc,
220 Printer& printer) const override {
221 T value = this->do_draw(tc);
222 printer.repr(value);
223 return value;
224 }
225
226 T do_draw_filtered_and_print(
227 const TestCase& tc,
228 const std::function<bool(const T&)>& predicate,
229 Printer& printer) const override {
230 T value = this->do_draw_filtered(tc, predicate);
231 printer.repr(value);
232 return value;
233 }
234 };
235
236 template <typename T, bool Printable>
237 using value_base_t =
238 std::conditional_t<Printable, ValuePrinted<T>, IGenerator<T>>;
239
240 template <typename T, bool Printable> class Structural;
241
242 template <typename T>
243 class Structural<T, true> : public IPrintableGenerator<T> {
244 public:
245 T do_draw_and_print(const TestCase& tc,
246 Printer& printer) const override {
247 return draw_printing(tc, printer);
248 }
249
250 protected:
251 virtual T draw_printing(const TestCase& tc,
252 Printer& printer) const = 0;
253 };
254
255 template <typename T>
256 class Structural<T, false> : public IGenerator<T> {
257 public:
258 T do_draw(const TestCase& tc) const override {
259 Printer silent = Printer::noop();
260 return draw_printing(tc, silent);
261 }
262
263 protected:
264 virtual T draw_printing(const TestCase& tc,
265 Printer& printer) const = 0;
266 };
267
268 template <typename H>
269 inline constexpr bool is_printable_handle_v =
270 std::is_base_of_v<Generator<typename H::value_type>, H>;
271
272 template <bool Printable, typename T>
273 using handle_t =
274 std::conditional_t<Printable, Generator<T>, AnyGenerator<T>>;
275
276 template <typename H>
277 typename H::value_type draw_component(const TestCase& tc, const H& gen,
278 Printer& printer) {
279 if constexpr (is_printable_handle_v<H>) {
280 return tc.draw_and_print(gen, printer);
281 } else {
282 return tc.draw_silent(gen);
283 }
284 }
285
286 template <typename T>
287 std::string open_text(const Printer& printer, std::string_view open) {
288 if (!printer.should_print()) {
289 return std::string();
290 }
291 return internal::cpp_type_name<T>() + std::string(open);
292 }
293
294 } // namespace detail
296
311 template <typename T> class AnyGenerator {
312 public:
314 using value_type = T;
315
317 AnyGenerator(std::shared_ptr<IGenerator<T>> impl)
318 : inner_(std::move(impl)) {}
319 AnyGenerator(IGenerator<T>* impl) : inner_(impl) {}
320
321 T do_draw(const TestCase& tc) const { return inner_->do_draw(tc); }
322
323 const std::shared_ptr<IGenerator<T>>& inner() const { return inner_; }
324
325 T
326 do_draw_filtered(const TestCase& tc,
327 const std::function<bool(const T&)>& predicate) const {
328 return inner_->do_draw_filtered(tc, predicate);
329 }
330
331 uint64_t label() const { return inner_->label(); }
333
354 template <typename F>
355 Mapped<std::invoke_result_t<F, T>, false> map(F&& f) const;
356
382 template <typename F> auto flat_map(F&& f) const;
383
405 AnyGenerator<T> filter(std::function<bool(const T&)> pred) const;
406
426 template <typename F> Generator<T> print_with(F&& print) const;
427
436 Generator<T> print_as_repr() const;
437
438 protected:
440 std::shared_ptr<IGenerator<T>> inner_;
442 };
443
470 template <typename T> class Generator : public AnyGenerator<T> {
471 public:
473 Generator(std::shared_ptr<IPrintableGenerator<T>> impl)
474 : AnyGenerator<T>(impl), printable_(std::move(impl)) {}
476 : Generator(std::shared_ptr<IPrintableGenerator<T>>(impl)) {}
477
478 T do_draw_and_print(const TestCase& tc, Printer& printer) const {
479 return printable_->do_draw_and_print(tc, printer);
480 }
481
482 T do_draw_filtered_and_print(
483 const TestCase& tc, const std::function<bool(const T&)>& predicate,
484 Printer& printer) const {
485 return printable_->do_draw_filtered_and_print(tc, predicate,
486 printer);
487 }
489
501 template <typename F>
502 Mapped<std::invoke_result_t<F, T>, true> map(F&& f) const;
503
512 Generator<T> filter(std::function<bool(const T&)> pred) const;
513
514 private:
515 std::shared_ptr<IPrintableGenerator<T>> printable_;
516 };
517
519 namespace detail {
520
521 template <typename T, typename U, bool Printable>
522 class MapImpl : public value_base_t<U, Printable> {
523 public:
524 MapImpl(AnyGenerator<T> source, std::function<U(T)> f)
525 : source_(std::move(source)), f_(std::move(f)),
526 label_(internal::combine_labels(
527 {internal::label(internal::LabelName::Map),
528 source_.label()})) {}
529
530 U do_draw(const TestCase& tc) const override {
531 return f_(tc.draw_silent(source_));
532 }
533
534 uint64_t label() const override { return label_; }
535
536 private:
537 AnyGenerator<T> source_;
538 std::function<U(T)> f_;
539 uint64_t label_;
540 };
541
542 template <typename T, typename U>
543 class PrintedAsCallImpl : public IPrintableGenerator<U> {
544 public:
545 PrintedAsCallImpl(Generator<T> source, std::function<U(T)> f,
546 std::string open, uint64_t label)
547 : source_(std::move(source)), f_(std::move(f)),
548 open_(std::move(open)), label_(label) {}
549
550 U do_draw_and_print(const TestCase& tc,
551 Printer& printer) const override {
552 printer.begin_group(open_.size(), open_);
553 T input = tc.draw_and_print(source_, printer);
554 printer.end_group(")");
555 return f_(std::move(input));
556 }
557
558 uint64_t label() const override { return label_; }
559
560 private:
561 Generator<T> source_;
562 std::function<U(T)> f_;
563 std::string open_;
564 uint64_t label_;
565 };
566
567 template <typename T> class SilentFilterImpl : public IGenerator<T> {
568 public:
569 using Predicate = std::function<bool(const T&)>;
570
571 SilentFilterImpl(AnyGenerator<T> source, Predicate predicate)
572 : source_(std::move(source)), predicate_(std::move(predicate)),
573 label_(internal::combine_labels(
574 {internal::label(internal::LabelName::Filter),
575 source_.label()})) {}
576
577 T do_draw(const TestCase& tc) const override {
578 return source_.do_draw_filtered(tc, predicate_);
579 }
580
581 T do_draw_filtered(const TestCase& tc,
582 const Predicate& predicate) const override {
583 return source_.do_draw_filtered(tc, both(predicate));
584 }
585
586 uint64_t label() const override { return label_; }
587
588 protected:
589 Predicate both(const Predicate& predicate) const {
590 return [first = predicate_, predicate](const T& value) {
591 return first(value) && predicate(value);
592 };
593 }
594
595 AnyGenerator<T> source_;
596 Predicate predicate_;
597 uint64_t label_;
598 };
599
600 template <typename T>
601 class PrintedFilterImpl : public IPrintableGenerator<T> {
602 public:
603 using Predicate = std::function<bool(const T&)>;
604
605 PrintedFilterImpl(Generator<T> source, Predicate predicate)
606 : source_(std::move(source)), predicate_(std::move(predicate)),
607 label_(internal::combine_labels(
608 {internal::label(internal::LabelName::Filter),
609 source_.label()})) {}
610
611 T do_draw(const TestCase& tc) const override {
612 return source_.do_draw_filtered(tc, predicate_);
613 }
614
615 T do_draw_filtered(const TestCase& tc,
616 const Predicate& predicate) const override {
617 return source_.do_draw_filtered(tc, both(predicate));
618 }
619
620 T do_draw_and_print(const TestCase& tc,
621 Printer& printer) const override {
622 return source_.do_draw_filtered_and_print(tc, predicate_,
623 printer);
624 }
625
626 T do_draw_filtered_and_print(const TestCase& tc,
627 const Predicate& predicate,
628 Printer& printer) const override {
629 return source_.do_draw_filtered_and_print(tc, both(predicate),
630 printer);
631 }
632
633 uint64_t label() const override { return label_; }
634
635 private:
636 Predicate both(const Predicate& predicate) const {
637 return [first = predicate_, predicate](const T& value) {
638 return first(value) && predicate(value);
639 };
640 }
641
642 Generator<T> source_;
643 Predicate predicate_;
644 uint64_t label_;
645 };
646
647 template <typename T>
648 class PrintedWithImpl : public IPrintableGenerator<T> {
649 public:
650 using Print = std::function<void(const T&, Printer&)>;
651
652 PrintedWithImpl(AnyGenerator<T> source, Print print)
653 : source_(std::move(source)), print_(std::move(print)) {}
654
655 T do_draw(const TestCase& tc) const override {
656 return source_.do_draw(tc);
657 }
658
659 T do_draw_filtered(
660 const TestCase& tc,
661 const std::function<bool(const T&)>& predicate) const override {
662 return source_.do_draw_filtered(tc, predicate);
663 }
664
665 T do_draw_and_print(const TestCase& tc,
666 Printer& printer) const override {
667 T value = source_.do_draw(tc);
668 print(value, printer);
669 return value;
670 }
671
672 T do_draw_filtered_and_print(
673 const TestCase& tc,
674 const std::function<bool(const T&)>& predicate,
675 Printer& printer) const override {
676 T value = source_.do_draw_filtered(tc, predicate);
677 print(value, printer);
678 return value;
679 }
680
681 uint64_t label() const override { return source_.label(); }
682
683 private:
684 void print(const T& value, Printer& printer) const {
685 if (printer.should_print()) {
686 print_(value, printer);
687 }
688 }
689
690 AnyGenerator<T> source_;
691 Print print_;
692 };
693
694 template <typename T> class ReprPrintedImpl : public ValuePrinted<T> {
695 public:
696 explicit ReprPrintedImpl(AnyGenerator<T> source)
697 : source_(std::move(source)) {}
698
699 T do_draw(const TestCase& tc) const override {
700 return source_.do_draw(tc);
701 }
702
703 T do_draw_filtered(
704 const TestCase& tc,
705 const std::function<bool(const T&)>& predicate) const override {
706 return source_.do_draw_filtered(tc, predicate);
707 }
708
709 uint64_t label() const override { return source_.label(); }
710
711 private:
712 AnyGenerator<T> source_;
713 };
714
715 template <typename T, typename U, bool Printable>
716 class FlatMapImpl : public Structural<U, Printable> {
717 public:
718 using Next = std::function<handle_t<Printable, U>(T)>;
719
720 FlatMapImpl(AnyGenerator<T> source, Next f)
721 : source_(std::move(source)), f_(std::move(f)),
722 label_(internal::combine_labels(
723 {internal::label(internal::LabelName::FlatMap),
724 source_.label()})) {}
725
726 uint64_t label() const override { return label_; }
727
728 protected:
729 U draw_printing(const TestCase& tc,
730 Printer& printer) const override {
731 handle_t<Printable, U> next = f_(tc.draw_silent(source_));
732 return draw_component(tc, next, printer);
733 }
734
735 private:
736 AnyGenerator<T> source_;
737 Next f_;
738 uint64_t label_;
739 };
740
741 template <typename T, bool Printable>
742 class CompositeImpl : public value_base_t<T, Printable> {
743 public:
744 CompositeImpl(std::function<T(const TestCase&)> fn, uint64_t label)
745 : fn_(std::move(fn)), label_(label) {}
746
747 T do_draw(const TestCase& tc) const override { return fn_(tc); }
748
749 uint64_t label() const override { return label_; }
750
751 private:
752 std::function<T(const TestCase&)> fn_;
753 uint64_t label_;
754 };
755
756 } // namespace detail
758
769 template <typename U, bool SourcePrintable>
770 class Mapped : public detail::handle_t<is_representable_v<U>, U> {
771 public:
773 using Base = detail::handle_t<is_representable_v<U>, U>;
774 using AsCall = std::function<Generator<U>(std::string, uint64_t)>;
775
776 Mapped(Base base, AsCall as_call)
777 : Base(std::move(base)), as_call_(std::move(as_call)) {}
779
800 Generator<U> print_as_call(std::string_view function) const {
801 static_assert(
802 SourcePrintable,
803 "print_as_call() needs a printable mapped generator (a "
804 "hegel::generators::Generator<T>), but this map() is of an "
805 "AnyGenerator<T>. Make the mapped generator printable, or use "
806 ".print_with(...) on the result of map().");
807 if (function.empty()) {
808 throw std::invalid_argument(
809 "print_as_call requires a non-empty function name");
810 }
811 return as_call_(std::string(function) + "(", this->label());
812 }
813
814 private:
815 AsCall as_call_;
816 };
817
819 namespace detail {
820
821 template <typename T, typename U, bool SourcePrintable>
822 Mapped<U, SourcePrintable>
823 make_mapped(handle_t<SourcePrintable, T> source,
824 std::function<U(T)> f) {
825 using Result = Mapped<U, SourcePrintable>;
826 typename Result::Base base(
827 std::make_shared<MapImpl<T, U, is_representable_v<U>>>(source,
828 f));
829 typename Result::AsCall as_call;
830 if constexpr (SourcePrintable) {
831 as_call = [source, f](std::string open, uint64_t label) {
832 return Generator<U>(
833 std::make_shared<PrintedAsCallImpl<T, U>>(
834 source, f, std::move(open), label));
835 };
836 }
837 return Result(std::move(base), std::move(as_call));
838 }
839
840 } // namespace detail
842
843 template <typename T>
844 template <typename F>
846 AnyGenerator<T>::map(F&& f) const {
847 using U = std::invoke_result_t<F, T>;
848 return detail::make_mapped<T, U, false>(
849 *this, std::function<U(T)>(std::forward<F>(f)));
850 }
851
852 template <typename T>
853 template <typename F>
855 using U = std::invoke_result_t<F, T>;
856 return detail::make_mapped<T, U, true>(
857 *this, std::function<U(T)>(std::forward<F>(f)));
858 }
859
860 template <typename T>
861 template <typename F>
862 auto AnyGenerator<T>::flat_map(F&& f) const {
863 using Result = std::decay_t<std::invoke_result_t<F, T>>;
864 using U = typename Result::value_type;
865 constexpr bool printable = detail::is_printable_handle_v<Result>;
866 using Next = typename detail::FlatMapImpl<T, U, printable>::Next;
867 return detail::handle_t<printable, U>(
868 std::make_shared<detail::FlatMapImpl<T, U, printable>>(
869 *this, Next(std::forward<F>(f))));
870 }
871
872 template <typename T>
874 AnyGenerator<T>::filter(std::function<bool(const T&)> pred) const {
875 return AnyGenerator<T>(std::make_shared<detail::SilentFilterImpl<T>>(
876 *this, std::move(pred)));
877 }
878
879 template <typename T>
881 Generator<T>::filter(std::function<bool(const T&)> pred) const {
882 return Generator<T>(std::make_shared<detail::PrintedFilterImpl<T>>(
883 *this, std::move(pred)));
884 }
885
886 template <typename T>
887 template <typename F>
889 return Generator<T>(std::make_shared<detail::PrintedWithImpl<T>>(
890 *this, typename detail::PrintedWithImpl<T>::Print(
891 std::forward<F>(print))));
892 }
893
894 template <typename T> Generator<T> AnyGenerator<T>::print_as_repr() const {
895 static_assert(is_representable_v<T>,
896 "print_as_repr() needs a type with a C++ "
897 "representation (hegel::is_representable_v). Use "
898 ".print_with(...) to print it another way.");
899 return Generator<T>(
900 std::make_shared<detail::ReprPrintedImpl<T>>(*this));
901 }
902
918 template <typename Impl, typename... Args>
919 auto make_generator(Args&&... args) {
920 using T = typename Impl::value_type;
921 std::shared_ptr<Impl> impl =
922 std::make_shared<Impl>(std::forward<Args>(args)...);
923 if constexpr (std::is_base_of_v<IPrintableGenerator<T>, Impl>) {
924 return Generator<T>(std::move(impl));
925 } else {
926 return AnyGenerator<T>(std::move(impl));
927 }
928 }
929
940 uint64_t label_from_name(std::string_view name);
941
947 inline uint64_t combine_labels(const std::vector<uint64_t>& labels) {
948 return internal::combine_labels(labels);
949 }
950
979 template <typename F> auto compose(F&& fn) {
980 using T = std::invoke_result_t<F, const TestCase&>;
981 constexpr bool printable = is_representable_v<T>;
982 return detail::handle_t<printable, T>(
983 std::make_shared<detail::CompositeImpl<T, printable>>(
984 std::function<T(const TestCase&)>(std::forward<F>(fn)),
985 internal::label(internal::LabelName::Composite)));
986 }
987
988} // namespace hegel::generators
989
990namespace hegel {
991
992 template <typename T>
994 return draw(std::string_view(), gen);
995 }
996
997 template <typename T>
998 T TestCase::draw(std::string_view name,
999 const generators::Generator<T>& gen) const {
1000 if (internal::is_explicit(*this)) {
1001 return std::any_cast<T>(
1002 internal::take_explicit_value(*this, name, typeid(T)));
1003 }
1004 internal::NestedDraw nested(*this);
1005 if (!nested.outermost() || !internal::records_output(*this)) {
1006 return draw_silent(gen);
1007 }
1008 std::string display = internal::draw_display_name(*this, name);
1009 Printer printer = internal::test_case_printer(*this);
1010 Speculation line = printer.speculate();
1011 printer.text("auto " + display + " = ");
1012 T value = draw_and_print(gen, printer);
1013 printer.text(";");
1014 printer.hard_break();
1015 line.commit();
1016 return value;
1017 }
1018
1020 template <typename T>
1022 static_assert(
1023 internal::always_false_v<T>,
1024 "tc.draw() needs a printable generator "
1025 "(hegel::generators::Generator<T>), but this is an "
1026 "AnyGenerator<T>. If T is your own type, give it a C++ "
1027 "representation: a reflectable aggregate (C++20), operator<<, or "
1028 "a print_to(hegel::Printer&) const member. Otherwise use "
1029 ".print_with(...), .print_as_repr(), or .print_as_call(\"f\") on "
1030 "a map() of a printable generator, or draw with "
1031 "tc.draw_silent(...). A helper that returns AnyGenerator<T> drops "
1032 "printing, so return Generator<T> instead.");
1033 }
1034
1035 template <typename T>
1036 T TestCase::draw(std::string_view,
1037 const generators::AnyGenerator<T>&) const {
1038 static_assert(
1039 internal::always_false_v<T>,
1040 "tc.draw() needs a printable generator "
1041 "(hegel::generators::Generator<T>), but this is an "
1042 "AnyGenerator<T>. If T is your own type, give it a C++ "
1043 "representation: a reflectable aggregate (C++20), operator<<, or "
1044 "a print_to(hegel::Printer&) const member. Otherwise use "
1045 ".print_with(...), .print_as_repr(), or .print_as_call(\"f\") on "
1046 "a map() of a printable generator, or draw with "
1047 "tc.draw_silent(...). A helper that returns AnyGenerator<T> drops "
1048 "printing, so return Generator<T> instead.");
1049 }
1051
1052 template <typename T>
1054 internal::check_not_explicit(*this, "draw_silent");
1055 internal::NestedDraw nested(*this);
1056 internal::start_span(*this, gen.label());
1057 T value = gen.do_draw(*this);
1058 internal::stop_span(*this);
1059 return value;
1060 }
1061
1062 template <typename T>
1064 Printer& printer) const {
1065 internal::check_not_explicit(*this, "draw_and_print");
1066 internal::NestedDraw nested(*this);
1067 internal::start_span(*this, gen.label());
1068 T value = gen.do_draw_and_print(*this, printer);
1069 internal::stop_span(*this);
1070 return value;
1071 }
1072
1073} // namespace hegel
Writes to the document that a failure report shows.
Definition printer.h:55
void repr(const T &value)
Write the C++ representation of a value.
Definition repr.h:713
void text(std::string_view text)
Write text that does not break.
static Printer noop()
A printer that discards everything.
Speculation speculate()
Start a speculative region on this printer.
void hard_break()
Write a new line, then the current indentation.
An open speculative region; see Printer::speculate().
Definition printer.h:285
void commit()
End the region and keep what was written in it.
void abort()
End the region and discard what was written in it.
Handle to the currently-executing test case.
Definition test_case.h:46
void reject() const
Reject the current test case unconditionally.
T draw_and_print(const generators::Generator< T > &gen, Printer &printer) const
Draw a value from a printable generator and print it to printer.
Definition core.h:1063
T draw_silent(const generators::AnyGenerator< T > &gen) const
Draw a random value from any generator, without printing it.
Definition core.h:1053
T draw(const generators::Generator< T > &gen) const
Draw a random value from a printable generator.
Definition core.h:993
A generator: a handle to an IGenerator.
Definition core.h:311
auto flat_map(F &&f) const
Chain generators for dependent generation.
Definition core.h:862
T value_type
The type of value this generator produces.
Definition core.h:314
Generator< T > print_with(F &&print) const
Make a printable generator that prints its values with print.
Definition core.h:888
AnyGenerator< T > filter(std::function< bool(const T &)> pred) const
Filter generated values by a predicate.
Definition core.h:874
Mapped< std::invoke_result_t< F, T >, false > map(F &&f) const
Transform generated values with a function.
Definition core.h:846
Generator< T > print_as_repr() const
Make a printable generator that prints its values by their C++ representation (Printer::repr()).
Definition core.h:894
A printable generator: TestCase::draw() accepts it.
Definition core.h:470
Mapped< std::invoke_result_t< F, T >, true > map(F &&f) const
Transform generated values with a function.
Definition core.h:854
Generator< T > filter(std::function< bool(const T &)> pred) const
Filter generated values by a predicate.
Definition core.h:881
The interface of a generator that draws without printing.
Definition core.h:51
T value_type
The type of value this generator makes.
Definition core.h:54
virtual uint64_t label() const
The label that identifies this generator to the engine.
Definition core.h:74
virtual T do_draw(const TestCase &tc) const =0
Draw a value.
virtual T do_draw_filtered(const TestCase &tc, const std::function< bool(const T &)> &predicate) const
Draw a value that predicate accepts, for filter().
Definition core.h:91
The interface of a printable generator: one that can print what it draws, as it draws it.
Definition core.h:150
virtual T do_draw_and_print(const TestCase &tc, Printer &printer) const =0
Draw a value and print it to printer.
T do_draw(const TestCase &tc) const override
Draw a value without printing it.
Definition core.h:172
virtual T do_draw_filtered_and_print(const TestCase &tc, const std::function< bool(const T &)> &predicate, Printer &printer) const
Draw a value that predicate accepts and print it, for filter().
Definition core.h:190
The generator that map() returns.
Definition core.h:770
Generator< U > print_as_call(std::string_view function) const
Make a generator that prints a call of function with the drawn input.
Definition core.h:800
Hegel generators.
Definition core.h:25
auto compose(F &&fn)
Build a generator from imperative code that draws from a TestCase.
Definition core.h:979
uint64_t combine_labels(const std::vector< uint64_t > &labels)
The label of a generator built from other generators.
Definition core.h:947
uint64_t label_from_name(std::string_view name)
The label of a generator with no component generators.
auto make_generator(Args &&... args)
Wrap a generator implementation in a handle.
Definition core.h:919
Main namespace.
Definition config.h:29
constexpr bool is_representable_v
Whether Printer::repr() has a C++ representation for T.
Definition repr.h:701