Pad/internal/editor/integration_test.go
Greg Pomerantz 615957196e feat: virtual scrolling with chunked buffer for large files
- Add ChunkedBuffer for 64KB chunked file access with dirty-chunk
  eviction protection
- Add LineIndex for precise byte-offset-to-line-number mapping
- Refactor IO task system with context cancellation, typed priorities,
  and new task types (ReadChunk, BuildLineIndex, StatFile)
- Add ReadFileAt to FileSystem interface (mock + real implementations)
- Integrate virtual scrolling into editor layout
- Add comprehensive tests for chunked buffer eviction, dirty-chunk
  safety, and full edit lifecycle
2026-06-05 09:11:32 -04:00

49 lines
964 B
Go

package editor
import (
"testing"
"time"
"pad/internal/io/pool/mock"
)
func TestOpenFileIntegration(t *testing.T) {
// 1. Setup Logic
mockFS := mock.NewFileSystem()
filename := "/README.md"
content := "Hello World"
mockFS.AddFile(filename, []byte(content), time.Now())
l := NewLogic(mockFS)
go l.Run()
defer l.Done()
// Drain frameChan to prevent deadlocks
go func() {
for range l.FrameChan() {
}
}()
TheState = l.state // Initialize global state
// 2. Open File
// OpenFile dispatches the task to openFileChan, which Run() will consume
OpenFile(filename)
// 3. Process the Result
// We wait for the state to update, which happens when ReadChunkTask completes
success := false
for i := 0; i < 20; i++ {
if l.state.Editor.GetBuffer() == content {
success = true
break
}
time.Sleep(100 * time.Millisecond)
}
// 4. Assert
if !success {
t.Errorf("Expected content %q, got %q", content, l.state.Editor.Buffer)
}
}