<commit_before>#include <catch.hpp>
#include <rapidcheck-catch.h>

#include "rapidcheck/detail/ExpressionCaptor.h"

#include "util/Box.h"

using namespace rc;
using namespace rc::test;
using namespace rc::detail;

namespace rc {

template<>
class Arbitrary<ExpressionCaptor> : public gen::Generator<ExpressionCaptor>
{
public:
    ExpressionCaptor generate() const override
    { return ExpressionCaptor(*gen::arbitrary<std::string>()); }
};

} // namespace rc

TEST_CASE("ExpressionCaptor") {
    SECTION("str") {
        prop("returns the current value",
             [] (const std::string &value) {
                 RC_ASSERT(ExpressionCaptor(value).str() == value);
             });
    }

    SECTION("operator->*") {
        prop("simply appends RHS",
             [](const ExpressionCaptor &captor, Box value) {
                 RC_ASSERT((std::move(captor) ->* value).str() ==
                           (captor.str() + value.str()));
            });
    }

#define TEST_BINARY_OPERATOR(op)                                        \
    SECTION("operator" #op) {                                           \
        prop("joins LHS and RHS with operator string between",          \
             [](const ExpressionCaptor &captor, Box value) {            \
                 RC_ASSERT((std::move(captor) op value).str() ==        \
                           (captor.str() + " " #op " " + value.str())); \
             });                                                        \
    }

    TEST_BINARY_OPERATOR(*)
    TEST_BINARY_OPERATOR(/)
    TEST_BINARY_OPERATOR(%)

    TEST_BINARY_OPERATOR(+)
    TEST_BINARY_OPERATOR(-)

    TEST_BINARY_OPERATOR(<<)
    TEST_BINARY_OPERATOR(>>)

    TEST_BINARY_OPERATOR(<)
    TEST_BINARY_OPERATOR(>)
    TEST_BINARY_OPERATOR(>=)
    TEST_BINARY_OPERATOR(<=)

    TEST_BINARY_OPERATOR(==)
    TEST_BINARY_OPERATOR(!=)

    TEST_BINARY_OPERATOR(&)

    TEST_BINARY_OPERATOR(^)

    TEST_BINARY_OPERATOR(|)

    TEST_BINARY_OPERATOR(&&)

    TEST_BINARY_OPERATOR(||)
<commit_msg>Move ExpressionCaptorTests to new framework<commit_after>#include <catch.hpp>
#include <rapidcheck-catch.h>

#include "rapidcheck/detail/ExpressionCaptor.h"

#include "util/Box.h"

using namespace rc;
using namespace rc::test;
using namespace rc::detail;

namespace rc {

template<>
struct NewArbitrary<ExpressionCaptor>
{
    static Gen<ExpressionCaptor> arbitrary()
    {
        return newgen::map<std::string>([](const std::string &str) {
            return ExpressionCaptor(str);
        });
    }
};

} // namespace rc

TEST_CASE("ExpressionCaptor") {
    SECTION("str") {
        newprop(
            "returns the current value",
            [] (const std::string &value) {
                RC_ASSERT(ExpressionCaptor(value).str() == value);
            });
    }

    SECTION("operator->*") {
        newprop(
            "simply appends RHS",
            [](const ExpressionCaptor &captor, Box value) {
                RC_ASSERT((std::move(captor) ->* value).str() ==
                          (captor.str() + value.str()));
            });
    }

#define TEST_BINARY_OPERATOR(op)                                        \
    SECTION("operator" #op) {                                           \
        newprop(                                                        \
            "joins LHS and RHS with operator string between",           \
            [](const ExpressionCaptor &captor, Box value) {             \
                RC_ASSERT((std::move(captor) op value).str() ==         \
                          (captor.str() + " " #op " " + value.str()));  \
            });                                                         \
    }

    TEST_BINARY_OPERATOR(*)
    TEST_BINARY_OPERATOR(/)
    TEST_BINARY_OPERATOR(%)

    TEST_BINARY_OPERATOR(+)
    TEST_BINARY_OPERATOR(-)

    TEST_BINARY_OPERATOR(<<)
    TEST_BINARY_OPERATOR(>>)

    TEST_BINARY_OPERATOR(<)
    TEST_BINARY_OPERATOR(>)
    TEST_BINARY_OPERATOR(>=)
    TEST_BINARY_OPERATOR(<=)

    TEST_BINARY_OPERATOR(==)
    TEST_BINARY_OPERATOR(!=)

    TEST_BINARY_OPERATOR(&)

    TEST_BINARY_OPERATOR(^)

    TEST_BINARY_OPERATOR(|)

    TEST_BINARY_OPERATOR(&&)

    TEST_BINARY_OPERATOR(||)

{'fraction_non_alphanumeric': 0.13, 'fraction_numerical': 0.0, 'mean_word_length': 1.907266435986159, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506932', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1239, 'n_words': 203}