diff --git a/doc/generators.md b/doc/generators.md index 153011e1..68fdc7e4 100644 --- a/doc/generators.md +++ b/doc/generators.md @@ -48,6 +48,7 @@ Out of the box, RapidCheck has support for generating arbitrary values of the fo - `std::pair` - `std::chrono::duration` - `std::chrono::time_point` +- `std::variant` - `rc::Maybe` The caveat is, of course, that for template types, RapidCheck must know how to generate the template arguments. diff --git a/include/rapidcheck.h b/include/rapidcheck.h index 6e2fb59c..8ba6b16a 100644 --- a/include/rapidcheck.h +++ b/include/rapidcheck.h @@ -29,6 +29,7 @@ #include "rapidcheck/gen/Text.h" #include "rapidcheck/gen/Transform.h" #include "rapidcheck/gen/Tuple.h" +#include "rapidcheck/gen/Variant.h" #include "rapidcheck/Assertions.h" #include "rapidcheck/Check.h" diff --git a/include/rapidcheck/gen/Variant.h b/include/rapidcheck/gen/Variant.h new file mode 100644 index 00000000..15ef8a79 --- /dev/null +++ b/include/rapidcheck/gen/Variant.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace rc { +namespace gen { + +} // namespace gen +} // namespace rc + +#include "Variant.hpp" diff --git a/include/rapidcheck/gen/Variant.hpp b/include/rapidcheck/gen/Variant.hpp new file mode 100644 index 00000000..59feac20 --- /dev/null +++ b/include/rapidcheck/gen/Variant.hpp @@ -0,0 +1,25 @@ +#pragma once + +namespace rc { +namespace gen { +namespace detail { + +template<> +struct DefaultArbitrary { + static Gen arbitrary() { + return gen::element(std::monostate()); + } +}; + +template +struct DefaultArbitrary> { + static Gen> arbitrary() { + return gen::oneOf( + gen::cast>(gen::arbitrary()), + gen::cast>(gen::arbitrary())...); + } +}; + +} // namespace detail +} // namespace gen +} // namespace rc