-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
76 lines (62 loc) · 1.73 KB
/
main.cpp
File metadata and controls
76 lines (62 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <array>
#include <string>
#include <sstream>
#include <doctest/doctest.h>
#include <observe/event.h>
/*
int main() {
// events can be valueless
observe::Event<> eventA;
// or have arguments
observe::Event<std::string, float> eventB;
observe::Event<int> eventC;
// connect will always trigger when an event is triggered
eventA.connect([](){
std::cout << "A triggered" << std::endl;
});
// observers will remove themselves from the event on destroy or reset
observe::Observer observer = eventB.createObserver([](const std::string &str, float v){
std::cout << "B triggered with " << str << " and " << v << std::endl;
});
// call emit to trigger all observers
eventA.emit();
eventB.emit("meaning of life", 42);
// `observe::Observer` can store any type of observer
// previous observers will be removed
observer.observe(eventC, [](int count){ std::cout << "I witness C with " << count << std::endl; });
eventC.emit(123);
eventC.emit(234);
eventC.emit(1);
eventC.emit(2);
eventC.emit(42);
// to remove an observer without destroying the object, call reset
observer.reset();
}
*/
TEST_SUITE ("Example derived tests.") {
TEST_CASE ("First test.") {
/* Example snippet:
*
* observe::Event<> eventA;
*/
const auto result = 42;
REQUIRE(result == 42);
}
TEST_CASE ("Second test.") {
/* Example snippet:
*
* example
*/
const auto result = false;
REQUIRE(!result);
}
TEST_CASE ("Third test.") {
/* Example snippet:
*
* example
*/
const auto result = -1;
REQUIRE(result < 0);
}
}