Step 170: UI event bus

This commit is contained in:
Bill
2026-02-09 21:35:54 -07:00
parent 454bd5eb8a
commit 6f62dccf04
9 changed files with 234 additions and 19 deletions

View File

@@ -0,0 +1,37 @@
// Step 170: UIEventBus unit checks.
#include <cassert>
#include <string>
#include "UIEventBus.h"
int main() {
UIEventBus bus;
int count = 0;
std::string lastDetail;
bus.subscribe(UIEventType::ASTChanged, [&](const UIEvent& ev) {
++count;
lastDetail = ev.detail;
});
bus.publish(UIEventType::ASTChanged, "file.cpp", "first", 1.0);
assert(count == 1);
assert(lastDetail == "first");
bus.publishDebounced(UIEventType::ASTChanged, "file.cpp", "debounce", 2.0, 0.5);
bus.tick(2.3);
assert(count == 1);
bus.tick(2.6);
assert(count == 2);
assert(lastDetail == "debounce");
bus.publishDebounced(UIEventType::ASTChanged, "file.cpp", "last", 3.0, 0.5);
bus.publishDebounced(UIEventType::ASTChanged, "file.cpp", "last2", 3.2, 0.5);
bus.tick(3.8);
assert(count == 3);
assert(lastDetail == "last2");
printf("step170_test: all assertions passed\n");
return 0;
}