Now we can load them in via JSON files at launch time. They are embded in the final exe though...
87 lines
2.0 KiB
Go
87 lines
2.0 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
|
|
|
|
editorTheme := themes.NewDefaultTheme()
|
|
engine := NewTreeSitterEngine(editorTheme)
|
|
engine.PrepareBuffer(buf, editorTheme)
|
|
|
|
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, editorTheme)
|
|
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
|
|
|
|
editorTheme := themes.NewDefaultTheme()
|
|
engine := NewTreeSitterEngine(editorTheme)
|
|
engine.PrepareBuffer(buf, editorTheme)
|
|
|
|
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")
|
|
}
|
|
}
|