-
Notifications
You must be signed in to change notification settings - Fork 1
/
incremental_test.go
65 lines (52 loc) · 1.38 KB
/
incremental_test.go
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
package gpeg
import (
"io/ioutil"
"math/rand"
"testing"
"github.com/zyedidia/gpeg/bench"
"github.com/zyedidia/gpeg/input/linerope"
"github.com/zyedidia/gpeg/memo"
"github.com/zyedidia/gpeg/pattern"
"github.com/zyedidia/gpeg/re"
"github.com/zyedidia/gpeg/vm"
)
// Open a 250k java file and apply some edits and verify that after each edit
// the incremental result is the same as doing a full parse.
func TestIncrementalJava(t *testing.T) {
rand.Seed(42)
peg, err := ioutil.ReadFile("grammars/java_memo.peg")
if err != nil {
t.Error(err)
}
p := re.MustCompile(string(peg))
java, err := ioutil.ReadFile("testdata/ScriptRuntime.java")
if err != nil {
t.Error(err)
}
edits := bench.GenerateEdits(java, 100)
edits = bench.ToSingleEdits(edits)
tbl := memo.NewTreeTable(512)
prog := pattern.MustCompile(p)
code := vm.Encode(prog)
r := linerope.New(java)
for _, e := range edits {
start := e.Start
end := e.End
r.Remove(start, end)
r.Insert(start, []byte(e.Text))
// st := time.Now()
tbl.ApplyEdit(memo.Edit{
Start: start,
End: end,
Len: len(e.Text),
})
code.Exec(r, tbl)
// fmt.Println("reparse", time.Since(st), match, off)
// st = time.Now()
// nmatch, noff, _, _ := code.Exec(r, memo.NoneTable{})
// fmt.Println("full parse", time.Since(st))
// if match != nmatch || off != noff {
// t.Fatal(i, match, nmatch, off, noff)
// }
}
}