#include "gtest/gtest.h"
#include "lumacs/buffer.hpp" // Assuming this path is correct based on include setup

// Test fixture for Buffer
struct BufferTest : public ::testing::Test {
    lumacs::Buffer buffer;

    void SetUp() override {
        // Initialize buffer before each test
        buffer = lumacs::Buffer("test-buffer");
    }

    void TearDown() override {
        // Clean up after each test (if necessary)
    }
};

TEST_F(BufferTest, NewBufferIsEmpty) {
    ASSERT_EQ(buffer.line_count(), 1);
    ASSERT_TRUE(buffer.line(0).empty());
}

TEST_F(BufferTest, InsertText) {
    buffer.insert({0, 0}, "hello");
    ASSERT_EQ(buffer.line(0), "hello");
    ASSERT_EQ(buffer.line_count(), 1);
}

TEST_F(BufferTest, InsertNewline) {
    buffer.insert({0, 0}, "hello");
    buffer.insert_newline({0, 5});
    ASSERT_EQ(buffer.line(0), "hello");
    ASSERT_EQ(buffer.line(1), "");
    ASSERT_EQ(buffer.line_count(), 2);
}

TEST_F(BufferTest, EraseText) {
    buffer.insert({0, 0}, "world");
    buffer.erase(lumacs::Range{{0, 0}, {0, 5}});
    ASSERT_TRUE(buffer.line(0).empty());
}

TEST_F(BufferTest, IsModified) {
    buffer.insert({0, 0}, "change");
    ASSERT_TRUE(buffer.is_modified());
}
