8000 Add test for incremental parsing · jrdek/python@1e054de · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e054de

Browse files
committed
Add test for incremental parsing
1 parent bbb9fd5 commit 1e054de

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/test-incremental.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {parser} from "../dist/index.es.js"
2+
import {fileTests} from "lezer-generator/dist/test"
3+
import {Tree, TreeFragment} from "lezer-tree"
4+
5+
describe("Incremental parsing", () => {
6+
// See https://github.com/codemirror/codemirror.next/issues/394
7+
it("doesn't reuse statements in the wrong body", () => {
8+
let input = `class StreamWriter:
9+
def __init__(self):
10+
pass
11+
12+
def a():
13+
pass
14+
15+
def b(self):
16+
""" ${"big block comment to fill up the reuse size quota\n ".repeat(150)} """
17+
pass
18+
`
19+
let ast = parser.parse(input)
20+
let at = input.indexOf("pass")
21+
input = input.slice(0, at) + " " + input.slice(at)
22+
let cache = TreeFragment.applyChanges(TreeFragment.addTree(ast), [{fromA: at, toA: at, fromB: at, toB: at + 1}])
23+
let ast2 = parser.parse(input, 0, {fragments: cache})
24+
if (ast2.toString() != ast.toString()) throw new Error("Malformed tree")
25+
26+
let lastFunc = ast => {
27+
let cur = ast.cursor(ast.length)
28+
while (cur.type.name != "FunctionDefinition") cur.prev()
29+
return cur.tree
30+
}
31+
if (lastFunc(ast) != lastFunc(ast2)) throw new Error("No reuse")
32+
})
33+
})

0 commit comments

Comments
 (0)
0