<commit_before>
#include <gtest/gtest.h>

#include "lw/error.hpp"
#include "lw/event.hpp"

namespace lw {
namespace tests {

namespace _details {
    LW_DECLARE_EVENTS(test, error, foobar)
    LW_DEFINE_EMITTER(
        TestEmitter,
        (test),
        (error, const error::Exception&),
        (foobar, const std::string&)
    );
}

// ---------------------------------------------------------------------------------------------- //

struct EmitterTests : public testing::Test {
    class MyEmitter : public _details::TestEmitter {};

    MyEmitter emitter;
};

// ---------------------------------------------------------------------------------------------- //

TEST_F(EmitterTests, EmitVoidEvent){
    bool emitterCalled = false;
    emitter.on(MyEmitter::event::test, [&](){ emitterCalled = true; });
    EXPECT_FALSE(emitterCalled);

    emitter.emit(MyEmitter::event::test);
    EXPECT_TRUE(emitterCalled);
}

// ---------------------------------------------------------------------------------------------- //

TEST_F(EmitterTests, EmitValueEvent){
    std::string value = "initial value";
    emitter.on(MyEmitter::event::foobar, [&](const std::string& val){ value = val; });

    emitter.emit(MyEmitter::event::foobar, "fizz bang");
    EXPECT_EQ("fizz bang", value);
}

}
}<commit_msg>Explicitly import event<commit_after>
#include <gtest/gtest.h>

#include "lw/error.hpp"
#include "lw/event.hpp"

namespace lw {
namespace tests {

namespace _details {
    LW_DECLARE_EVENTS(test, error, foobar)
    LW_DEFINE_EMITTER(
        TestEmitter,
        (test),
        (error, const error::Exception&),
        (foobar, const std::string&)
    );
}

// ---------------------------------------------------------------------------------------------- //

struct EmitterTests : public testing::Test {
    class MyEmitter : public _details::TestEmitter {
    public:
        using _details::TestEmitter::event;
    };

    MyEmitter emitter;
};

// ---------------------------------------------------------------------------------------------- //

TEST_F(EmitterTests, EmitVoidEvent){
    bool emitterCalled = false;
    emitter.on(MyEmitter::event::test, [&](){ emitterCalled = true; });
    EXPECT_FALSE(emitterCalled);

    emitter.emit(MyEmitter::event::test);
    EXPECT_TRUE(emitterCalled);
}

// ---------------------------------------------------------------------------------------------- //

TEST_F(EmitterTests, EmitValueEvent){
    std::string value = "initial value";
    emitter.on(MyEmitter::event::foobar, [&](const std::string& val){ value = val; });

    emitter.emit(MyEmitter::event::foobar, "fizz bang");
    EXPECT_EQ("fizz bang", value);
}

}
}
{'fraction_non_alphanumeric': 0.3337074448185559, 'fraction_numerical': 0.0, 'mean_word_length': 1.6241413150147204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7122837', 'n_tokens_mistral': 751, 'n_tokens_neox': 740, 'n_words': 133}