Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Apr 13, 2019
1 parent 63d10af commit 7a9a5fb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
8 changes: 3 additions & 5 deletions index.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <map>

class EventEmitter {

std::map<std::string, void*> events;
std::map<std::string, bool> events_once;

Expand All @@ -33,15 +32,14 @@ class EventEmitter {
int _listeners = 0;

public:

int maxListeners = 10;

int listeners() {
return this->_listeners;
}

template <typename Callback>
void on(std::string name, Callback cb) {
void on(const std::string& name, Callback cb) {

auto it = events.find(name);
if (it != events.end()) {
Expand All @@ -62,7 +60,7 @@ class EventEmitter {
}

template <typename Callback>
void once(std::string name, Callback cb) {
void once(const std::string& name, Callback cb) {
this->on(name, cb);
events_once[name] = true;
}
Expand All @@ -73,7 +71,7 @@ class EventEmitter {
this->_listeners = 0;
}

void off(std::string name) {
void off(const std::string& name) {

auto it = events.find(name);

Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
"url": "git://github.com/datcxx/cxx-eventemitter.git"
},
"homepage": "https://github.com/datcxx/cxx-eventemitter",
"dependencies": {},
"dependencies": {
},
"scripts": {
"test": "c++ -std=c++2a test/index.cxx -o test/index && ./test/index"
"test": [
"clang++ -std=c++2a",
"-O1 -g -fsanitize=address -fno-omit-frame-pointer",
"test/index.cxx -o test/index &&",
"ASAN_OPTIONS=detect_leaks=1",
"ASAN_OPTIONS=fast_unwind_on_malloc=0",
"./test/index"
]
},
"files": [
"index.hxx"
Expand Down
4 changes: 2 additions & 2 deletions test/index.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
} \
} while(0);

int main (int argc, char* argv[]) {
int main () {
int testcount = 0;
int testplan = 9;

Expand All @@ -25,7 +25,7 @@ int main (int argc, char* argv[]) {

ASSERT("maxListeners should be 10", ee.maxListeners == 10);

ee.on("event1", [&](int a, std::string b) {
ee.on("event1", [&](int a, std::string& b) {
ASSERT("first arg should be equal to 10", a == 10);
ASSERT("second arg should be foo", b == "foo");
});
Expand Down
20 changes: 20 additions & 0 deletions test/index.dSYM/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.index</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Binary file added test/index.dSYM/Contents/Resources/DWARF/index
Binary file not shown.

0 comments on commit 7a9a5fb

Please sign in to comment.