Add PieceTable-based buffer tests and improvements for file I/O and editing.

- Introduced comprehensive tests:
  - `test_buffer_open_nonexistent_save.cc`: Save after opening a non-existent file.
  - `test_buffer_save.cc`: Save buffer contents to disk.
  - `test_buffer_save_existing.cc`: Save after opening existing files.
- Implemented `PieceTable::WriteToStream()` to directly stream content without full materialization.
- Updated `Buffer::Save` and `Buffer::SaveAs` to use efficient streaming via `PieceTable`.
- Enhanced editing commands (`Insert`, `Delete`, `Replace`, etc.) to use PieceTable APIs, ensuring proper undo and save functionality.
This commit is contained in:
2025-12-07 00:30:11 -08:00
parent 657c9bbc19
commit f6f0c11be4
10 changed files with 682 additions and 498 deletions

View File

@@ -313,6 +313,47 @@ if (BUILD_TESTS)
target_link_libraries(test_undo ${TREESITTER_LIBRARY})
endif ()
endif ()
# test_buffer_save executable to verify Buffer::Save writes contents to disk
# Keep this test minimal to avoid pulling the entire app; only compile what's needed
add_executable(test_buffer_save
test_buffer_save.cc
PieceTable.cc
Buffer.cc
${SYNTAX_SOURCES}
UndoNode.cc
UndoTree.cc
UndoSystem.cc
)
# test_buffer_save_existing: verifies Save() after OpenFromFile on existing path
add_executable(test_buffer_save_existing
test_buffer_save_existing.cc
PieceTable.cc
Buffer.cc
${SYNTAX_SOURCES}
UndoNode.cc
UndoTree.cc
UndoSystem.cc
)
# test for opening a non-existent path then saving
add_executable(test_buffer_open_nonexistent_save
test_buffer_open_nonexistent_save.cc
PieceTable.cc
Buffer.cc
${SYNTAX_SOURCES}
UndoNode.cc
UndoTree.cc
UndoSystem.cc
)
# No ncurses needed for this unit
if (KTE_ENABLE_TREESITTER)
if (TREESITTER_INCLUDE_DIR)
target_include_directories(test_buffer_save PRIVATE ${TREESITTER_INCLUDE_DIR})
endif ()
if (TREESITTER_LIBRARY)
target_link_libraries(test_buffer_save ${TREESITTER_LIBRARY})
endif ()
endif ()
endif ()
if (${BUILD_GUI})