// Copyright (C) 2022 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "../namespaces.h" #include "../utilities/semantics/move_into_vector.h" #include "combinators/oneof_generator.h" #include #include #include namespace QDOC_CATCH_GENERATORS_ROOT_NAMESPACE { namespace QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE { class QCharGenerator : public Catch::Generators::IGenerator { public: QCharGenerator( char16_t lower_bound = std::numeric_limits::min(), char16_t upper_bound = std::numeric_limits::max() ) : random_engine{std::random_device{}()}, distribution{static_cast(lower_bound), static_cast(upper_bound)} { assert(lower_bound <= upper_bound); static_cast(next()); } QChar const& get() const override { return current_character; } bool next() override { current_character = QChar(static_cast(distribution(random_engine))); return true; } private: QChar current_character; std::mt19937 random_engine; std::uniform_int_distribution distribution; }; } // end QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE /*! * Returns a generator of that generates elements of QChar whose * ucs value is in the range [\a lower_bound, \a upper_bound]. * * When \a lower_bound = \a upper_bound, the generator infinitely * generates the same character. */ inline Catch::Generators::GeneratorWrapper character(char16_t lower_bound = std::numeric_limits::min(), char16_t upper_bound = std::numeric_limits::max()) { return Catch::Generators::GeneratorWrapper(std::unique_ptr>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator(lower_bound, upper_bound))); } namespace QDOC_CATCH_GENERATORS_QCHAR_ALPHABETS_NAMESPACE { namespace QDOC_CATCH_GENERATORS_TRAITS_NAMESPACE { enum class Alphabets : std::size_t {digit, ascii_lowercase, ascii_uppercase, ascii_alpha, ascii_alphanumeric, portable_posix_filename}; template struct sizeof_alphabet; template inline constexpr std::size_t sizeof_alphabet_v = sizeof_alphabet::value; template <> struct sizeof_alphabet { static constexpr std::size_t value{'9' - '0'}; }; template <> struct sizeof_alphabet { static constexpr std::size_t value{'z' - 'a'}; }; template<> struct sizeof_alphabet { static constexpr std::size_t value{'Z' - 'A'}; }; template<> struct sizeof_alphabet { static constexpr std::size_t value{sizeof_alphabet_v + sizeof_alphabet_v}; }; template<> struct sizeof_alphabet{ static constexpr std::size_t value{sizeof_alphabet_v + sizeof_alphabet_v}; }; } // end QDOC_CATCH_GENERATORS_TRAITS_NAMESPACE inline Catch::Generators::GeneratorWrapper digit() { return Catch::Generators::GeneratorWrapper(std::unique_ptr>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('0', '9'))); } inline Catch::Generators::GeneratorWrapper ascii_lowercase() { return Catch::Generators::GeneratorWrapper(std::unique_ptr>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('a', 'z'))); } inline Catch::Generators::GeneratorWrapper ascii_uppercase() { return Catch::Generators::GeneratorWrapper(std::unique_ptr>(new QDOC_CATCH_GENERATORS_PRIVATE_NAMESPACE::QCharGenerator('A', 'Z'))); } inline Catch::Generators::GeneratorWrapper ascii_alpha() { return uniform_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_lowercase(), ascii_uppercase())); } inline Catch::Generators::GeneratorWrapper ascii_alphanumeric() { return uniformly_valued_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_alpha(), digit()), std::vector{traits::sizeof_alphabet_v , traits::sizeof_alphabet_v}); } inline Catch::Generators::GeneratorWrapper portable_posix_filename() { return uniformly_valued_oneof(QDOC_CATCH_GENERATORS_UTILITIES_ABSOLUTE_NAMESPACE::move_into_vector(ascii_alphanumeric(), character('.', '.'), character('-', '-'), character('_', '_')), std::vector{traits::sizeof_alphabet_v, std::size_t{1}, std::size_t{1}, std::size_t{1}}); } } // end QDOC_CATCH_GENERATORS_QCHAR_ALPHABETS_NAMESPACE } // end QDOC_CATCH_GENERATORS_ROOT_NAMESPACE