test_defaults_loading.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "gtest/gtest.h"
  2. #include "lumacs/editor_core.hpp"
  3. #include "lumacs/lua_api.hpp"
  4. #include "lumacs/keybinding.hpp"
  5. #include "lumacs/command_system.hpp"
  6. #include <memory>
  7. using namespace lumacs;
  8. class DefaultsLoadingTest : public ::testing::Test {
  9. protected:
  10. void SetUp() override {
  11. core = std::make_unique<EditorCore>();
  12. // Load the REAL defaults (this is what main.cpp does)
  13. core->lua_api()->load_init_file();
  14. // Ensure buffer is ready
  15. core->new_buffer("*scratch*");
  16. core->set_cursor({0,0});
  17. }
  18. void TearDown() override {
  19. core.reset();
  20. }
  21. std::unique_ptr<EditorCore> core;
  22. };
  23. TEST_F(DefaultsLoadingTest, SelfInsertFromDefaults) {
  24. std::string input_key = "h";
  25. // 1. Process key (should be unbound in defaults)
  26. auto result = core->keybinding_manager().process_key(input_key);
  27. EXPECT_EQ(result.type, KeyResult::Unbound);
  28. // 2. Simulate GtkEditor fallback logic
  29. if (result.type == KeyResult::Unbound) {
  30. if (input_key.length() == 1) {
  31. // This executes the LUA version of self-insert-command defined in defaults.hpp
  32. auto cmd_result = core->command_system().execute("self-insert-command", {input_key});
  33. EXPECT_EQ(cmd_result.status, CommandStatus::Success) << "Message: " << cmd_result.message;
  34. }
  35. }
  36. // 3. Verify state
  37. EXPECT_EQ(core->buffer().content(), "h");
  38. }