Add benchmarks, migration tests, and dev guide

Add benchmarks for core operations, migration edge case tests, improved
buffer I/O tests, and developer guide

- Introduced `test_benchmarks.cc` for performance benchmarking of key
  operations in `PieceTable` and `Buffer`, including syntax highlighting
  and iteration patterns.
- Added `test_migration_coverage.cc` to provide comprehensive tests for
  migration of `Buffer::Rows()` to `PieceTable` APIs, with edge cases,
  boundary handling, and consistency checks.
- Enhanced `test_buffer_io.cc` with additional cases for save/load
  workflows, file handling, and better integration with the core API.
- Documented architectural details and core concepts in a new
  `DEVELOPER_GUIDE.md`. Highlighted design principles, code
  organization, and contribution workflows.
This commit is contained in:
2026-02-17 16:08:23 -08:00
parent 337b585ba0
commit 8ec0d6ac41
30 changed files with 1916 additions and 102 deletions

View File

@@ -1,3 +1,21 @@
/*
* test_piece_table.cc - Tests for the PieceTable data structure
*
* This file validates the core text storage mechanism used by kte.
* PieceTable provides efficient insert/delete operations without copying
* the entire buffer, using a list of "pieces" that reference ranges in
* original and add buffers.
*
* Key functionality tested:
* - Insert/delete operations maintain correct content
* - Line counting and line-based queries work correctly
* - Position conversion (byte offset ↔ line/column) is accurate
* - Random edits against a reference model (string) produce identical results
*
* The random edit test is particularly important - it performs hundreds of
* random insertions and deletions, comparing PieceTable results against a
* simple std::string to ensure correctness under all conditions.
*/
#include "Test.h"
#include "PieceTable.h"
#include <algorithm>
@@ -34,7 +52,7 @@ LineContentFor(const std::string &s, std::size_t line_num)
}
TEST(PieceTable_Insert_Delete_LineCount)
TEST (PieceTable_Insert_Delete_LineCount)
{
PieceTable pt;
// start empty
@@ -61,7 +79,7 @@ TEST(PieceTable_Insert_Delete_LineCount)
}
TEST(PieceTable_LineCol_Conversions)
TEST (PieceTable_LineCol_Conversions)
{
PieceTable pt;
std::string s = "hello\nworld\n"; // two lines with trailing NL
@@ -84,7 +102,7 @@ TEST(PieceTable_LineCol_Conversions)
}
TEST(PieceTable_ReferenceModel_RandomEdits_Deterministic)
TEST (PieceTable_ReferenceModel_RandomEdits_Deterministic)
{
PieceTable pt;
std::string model;
@@ -178,4 +196,4 @@ TEST(PieceTable_ReferenceModel_RandomEdits_Deterministic)
ASSERT_EQ(r.second, exp_end);
ASSERT_EQ(pt.GetLine(line), LineContentFor(model, line));
}
}
}