2026-02-09 18:06:50 -07:00
|
|
|
// Step 144 TDD Test: Emacs keybinding deep integration
|
|
|
|
|
#include "EmacsKeybinding.h"
|
2026-02-11 01:34:27 +00:00
|
|
|
#include "NotificationSystem.h"
|
2026-02-09 18:06:50 -07:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
static void expect(bool cond, const std::string& name, int& passed, int& failed) {
|
|
|
|
|
if (cond) {
|
|
|
|
|
std::cout << "Test " << (passed + failed + 1) << " PASS: " << name << "\n";
|
|
|
|
|
++passed;
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "Test " << (passed + failed + 1) << " FAIL: " << name << "\n";
|
|
|
|
|
++failed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
int passed = 0;
|
|
|
|
|
int failed = 0;
|
|
|
|
|
|
|
|
|
|
MockEmacsConnection mock;
|
|
|
|
|
EmacsKeybindingState state;
|
2026-02-11 01:34:27 +00:00
|
|
|
NotificationSystem notifications;
|
2026-02-09 18:06:50 -07:00
|
|
|
|
2026-02-11 01:34:27 +00:00
|
|
|
bool prefixOk = emacsHandleKeySequence(state, mock, "C-x", notifications);
|
2026-02-09 18:06:50 -07:00
|
|
|
expect(prefixOk, "prefix handled", passed, failed);
|
|
|
|
|
expect(state.prefix == "C-x", "prefix stored", passed, failed);
|
|
|
|
|
|
2026-02-11 01:34:27 +00:00
|
|
|
bool seqOk = emacsHandleKeySequence(state, mock, "C-s", notifications);
|
2026-02-09 18:06:50 -07:00
|
|
|
expect(seqOk, "sequence handled", passed, failed);
|
|
|
|
|
expect(state.prefix.empty(), "prefix cleared", passed, failed);
|
|
|
|
|
expect(state.lastCommand == "save-buffer", "command resolved", passed, failed);
|
|
|
|
|
expect(mock.getLastSentCommand().find("call-interactively") != std::string::npos,
|
|
|
|
|
"call-interactively sent", passed, failed);
|
|
|
|
|
|
2026-02-11 01:34:27 +00:00
|
|
|
bool mxOk = emacsHandleKeySequence(state, mock, "M-x", notifications);
|
2026-02-09 18:06:50 -07:00
|
|
|
expect(mxOk, "M-x handled", passed, failed);
|
|
|
|
|
expect(state.minibufferActive, "minibuffer active", passed, failed);
|
|
|
|
|
|
|
|
|
|
std::snprintf(state.minibufferBuf, sizeof(state.minibufferBuf), "find-file");
|
2026-02-11 01:34:27 +00:00
|
|
|
bool mbOk = emacsExecuteMinibuffer(state, mock, notifications);
|
2026-02-09 18:06:50 -07:00
|
|
|
expect(mbOk, "minibuffer command executed", passed, failed);
|
|
|
|
|
expect(!state.minibufferActive, "minibuffer cleared", passed, failed);
|
|
|
|
|
|
2026-02-11 01:34:27 +00:00
|
|
|
updateEmacsModeLine(state, mock, 2.0, notifications);
|
2026-02-09 18:06:50 -07:00
|
|
|
expect(!state.modeLine.empty(), "mode line updated", passed, failed);
|
|
|
|
|
|
|
|
|
|
std::cout << "\n=== Step 144 Results: " << passed << " passed, "
|
|
|
|
|
<< failed << " failed ===\n";
|
|
|
|
|
return failed == 0 ? 0 : 1;
|
|
|
|
|
}
|