All checks were successful
Run Test Suite / test (push) Successful in 31s
However, the colorscheme functions and tests do not work anymore, they need to be rebuilt.
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/theme/themes"
|
|
)
|
|
|
|
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(themes.NewDefaultTheme())
|
|
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(themes.NewDefaultTheme())
|
|
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")
|
|
}
|
|
}
|