This is so vibe coded, but in the interest of time, its a bit necessary. Plus this is a complex problem that I don't have the mental bandwidth to invest right now.
85 lines
1.9 KiB
Go
85 lines
1.9 KiB
Go
package syntax
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.gophernest.net/azpect/TextEditor/internal/core"
|
|
"git.gophernest.net/azpect/TextEditor/internal/style"
|
|
)
|
|
|
|
func TestTreeSitterEngineApplyEditMarksDirtyWithoutFullInvalidation(t *testing.T) {
|
|
b := core.NewBufferBuilder().
|
|
WithFilename("x.go").
|
|
WithFiletype("go").
|
|
WithLines([]string{"package main", "func main() {", "println(1)", "}"}).
|
|
Build()
|
|
buf := &b
|
|
|
|
engine := NewTreeSitterEngine(style.DefaultStyles())
|
|
engine.PrepareBuffer(buf)
|
|
|
|
bc := engine.getCache(buf)
|
|
if !bc.built {
|
|
t.Fatalf("expected cache to be built after prepare")
|
|
}
|
|
|
|
var edit *core.BufferEdit
|
|
buf.OnChange = func(change core.BufferChange) {
|
|
edit = change.Edit
|
|
}
|
|
|
|
buf.SetLine(2, "println(22)")
|
|
if edit == nil {
|
|
t.Fatalf("expected setline to emit edit metadata")
|
|
}
|
|
|
|
engine.ApplyEdit(buf, edit)
|
|
|
|
if bc.built {
|
|
t.Fatalf("expected cache to become unbuilt after apply edit")
|
|
}
|
|
if bc.dirtyAll {
|
|
t.Fatalf("expected non-structural edit to avoid dirtyAll")
|
|
}
|
|
if len(bc.dirty) == 0 {
|
|
t.Fatalf("expected dirty ranges after apply edit")
|
|
}
|
|
|
|
engine.PrepareBuffer(buf)
|
|
if !bc.built {
|
|
t.Fatalf("expected cache rebuilt after prepare")
|
|
}
|
|
if len(bc.dirty) != 0 {
|
|
t.Fatalf("expected dirty ranges cleared after rebuild")
|
|
}
|
|
}
|
|
|
|
func TestTreeSitterEngineInvalidateLinesAndBuffer(t *testing.T) {
|
|
b := core.NewBufferBuilder().
|
|
WithFilename("x.go").
|
|
WithFiletype("go").
|
|
WithLines([]string{"package main", "func main() {}"}).
|
|
Build()
|
|
buf := &b
|
|
|
|
engine := NewTreeSitterEngine(style.DefaultStyles())
|
|
engine.PrepareBuffer(buf)
|
|
|
|
bc := engine.getCache(buf)
|
|
engine.InvalidateLines(buf, 1, 1)
|
|
if bc.built {
|
|
t.Fatalf("expected invalidate lines to unset built")
|
|
}
|
|
if bc.dirtyAll {
|
|
t.Fatalf("expected line invalidation to avoid dirtyAll")
|
|
}
|
|
if len(bc.dirty) == 0 {
|
|
t.Fatalf("expected dirty line ranges")
|
|
}
|
|
|
|
engine.InvalidateBuffer(buf)
|
|
if !bc.dirtyAll {
|
|
t.Fatalf("expected invalidate buffer to set dirtyAll")
|
|
}
|
|
}
|