Преглед изворни кода

test: Add regression test for defaults loading and basic input

Bernardo Magri пре 1 месец
родитељ
комит
103b867d38
2 измењених фајлова са 53 додато и 9 уклоњено
  1. 4 9
      tests/CMakeLists.txt
  2. 49 0
      tests/test_defaults_loading.cpp

+ 4 - 9
tests/CMakeLists.txt

@@ -18,19 +18,14 @@ add_executable(test_runner
     test_input_pipeline.cpp
     test_buffer_manager.cpp
     test_window.cpp
-    test_window_manager.cpp
-    test_integration.cpp
-    test_kill_ring_manager.cpp
-    test_register_manager.cpp
-    test_macro_manager.cpp
-    test_rectangle_manager.cpp
-    test_command_system.cpp
-    test_lua_api.cpp
+    test_defaults_loading.cpp
 )
 
 target_link_libraries(test_runner PRIVATE
     lumacs_core
-    GTest::gtest_main
+    gtest
+    gtest_main
+    pthread
 )
 
 # Automatically discover and register tests

+ 49 - 0
tests/test_defaults_loading.cpp

@@ -0,0 +1,49 @@
+#include "gtest/gtest.h"
+#include "lumacs/editor_core.hpp"
+#include "lumacs/lua_api.hpp"
+#include "lumacs/keybinding.hpp"
+#include "lumacs/command_system.hpp"
+#include <memory>
+
+using namespace lumacs;
+
+class DefaultsLoadingTest : public ::testing::Test {
+protected:
+    void SetUp() override {
+        core = std::make_unique<EditorCore>();
+        
+        // Load the REAL defaults (this is what main.cpp does)
+        core->lua_api()->load_init_file();
+        
+        // Ensure buffer is ready
+        core->new_buffer("*scratch*");
+        core->set_cursor({0,0});
+    }
+
+    void TearDown() override {
+        core.reset();
+    }
+
+    std::unique_ptr<EditorCore> core;
+};
+
+TEST_F(DefaultsLoadingTest, SelfInsertFromDefaults) {
+    std::string input_key = "h";
+    
+    // 1. Process key (should be unbound in defaults)
+    auto result = core->keybinding_manager().process_key(input_key);
+    EXPECT_EQ(result.type, KeyResult::Unbound);
+    
+    // 2. Simulate GtkEditor fallback logic
+    if (result.type == KeyResult::Unbound) {
+        if (input_key.length() == 1) {
+            // This executes the LUA version of self-insert-command defined in defaults.hpp
+            auto cmd_result = core->command_system().execute("self-insert-command", {input_key});
+            
+            EXPECT_EQ(cmd_result.status, CommandStatus::Success) << "Message: " << cmd_result.message;
+        }
+    }
+    
+    // 3. Verify state
+    EXPECT_EQ(core->buffer().content(), "h");
+}