-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincremental_rust_fastpath_test.go
More file actions
68 lines (63 loc) · 2.1 KB
/
Copy pathincremental_rust_fastpath_test.go
File metadata and controls
68 lines (63 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package xref_test
import (
"bytes"
"testing"
gts "github.com/startvibecoding/xref"
grm "github.com/startvibecoding/xref/internal/grammars"
)
func TestRustLineCommentTextEditUsesInvariantReuse(t *testing.T) {
lang := grm.RustLanguage()
oldSource := []byte("// Copyright 2012-2014\nfn main() {}\n")
offset := bytes.Index(oldSource, []byte("2012"))
if offset < 0 {
t.Fatal("fixture missing edit marker")
}
offset += len("201")
newSource := append([]byte(nil), oldSource...)
newSource[offset] = '3'
parser := gts.NewParser(lang)
fresh, err := parser.Parse(newSource)
if err != nil {
t.Fatalf("fresh parse: %v", err)
}
defer fresh.Release()
oldTree, err := parser.Parse(oldSource)
if err != nil {
t.Fatalf("old parse: %v", err)
}
defer oldTree.Release()
edit := gts.InputEdit{
StartByte: uint32(offset),
OldEndByte: uint32(offset + 1),
NewEndByte: uint32(offset + 1),
StartPoint: pointForOffset(oldSource, offset),
OldEndPoint: pointForOffset(oldSource, offset+1),
NewEndPoint: pointForOffset(newSource, offset+1),
}
oldTree.Edit(edit)
result, err := parser.ParseWith(newSource, gts.WithOldTree(oldTree), gts.WithProfiling())
if err != nil {
t.Fatalf("incremental parse: %v", err)
}
defer result.Tree.Release()
if got, want := result.Tree.RootNode().SExpr(lang), fresh.RootNode().SExpr(lang); got != want {
t.Fatalf("incremental tree mismatch\n got: %s\nwant: %s", got, want)
}
if !result.ProfileAvailable {
t.Fatal("profile unavailable")
}
if result.Profile.ReuseUnsupported {
t.Fatalf("reuse unsupported: %s", result.Profile.ReuseUnsupportedReason)
}
if result.Profile.ReparseNanos != 0 {
t.Fatalf("reparse nanos = %d, want 0", result.Profile.ReparseNanos)
}
if result.Profile.ReusedSubtrees != 1 || result.Profile.ReusedBytes != uint64(len(newSource)) {
t.Fatalf("reuse profile subtrees=%d bytes=%d, want 1/%d",
result.Profile.ReusedSubtrees, result.Profile.ReusedBytes, len(newSource))
}
rt := result.Tree.ParseRuntime()
if rt.StopReason != gts.ParseStopAccepted || rt.TokensConsumed != 0 {
t.Fatalf("runtime = %s, want accepted token-free reuse", rt.Summary())
}
}