Skip to content

Commit 52acc04

Browse files
committed
[libSyntax] Add test case to match the incrementally transferred syntax tree
1 parent d926b74 commit 52acc04

File tree

6 files changed

+408
-26
lines changed

6 files changed

+408
-26
lines changed
Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
{
2+
"id": 93,
3+
"kind": "SourceFile",
4+
"layout": [
5+
{
6+
"id": 92,
7+
"kind": "CodeBlockItemList",
8+
"layout": [
9+
{
10+
"id": 13,
11+
"omitted": true
12+
},
13+
{
14+
"id": 89,
15+
"kind": "CodeBlockItem",
16+
"layout": [
17+
{
18+
"id": 88,
19+
"kind": "FunctionDecl",
20+
"layout": [
21+
null,
22+
null,
23+
{
24+
"id": 66,
25+
"tokenKind": {
26+
"kind": "kw_func"
27+
},
28+
"leadingTrivia": [
29+
{
30+
"kind": "Newline",
31+
"value": 2
32+
}
33+
],
34+
"trailingTrivia": [
35+
{
36+
"kind": "Space",
37+
"value": 1
38+
}
39+
],
40+
"presence": "Present"
41+
},
42+
{
43+
"id": 67,
44+
"tokenKind": {
45+
"kind": "identifier",
46+
"text": "bar"
47+
},
48+
"leadingTrivia": [],
49+
"trailingTrivia": [],
50+
"presence": "Present"
51+
},
52+
null,
53+
{
54+
"id": 72,
55+
"kind": "FunctionSignature",
56+
"layout": [
57+
{
58+
"id": 71,
59+
"kind": "ParameterClause",
60+
"layout": [
61+
{
62+
"id": 68,
63+
"tokenKind": {
64+
"kind": "l_paren"
65+
},
66+
"leadingTrivia": [],
67+
"trailingTrivia": [],
68+
"presence": "Present"
69+
},
70+
{
71+
"id": 69,
72+
"kind": "FunctionParameterList",
73+
"layout": [],
74+
"presence": "Present"
75+
},
76+
{
77+
"id": 70,
78+
"tokenKind": {
79+
"kind": "r_paren"
80+
},
81+
"leadingTrivia": [],
82+
"trailingTrivia": [
83+
{
84+
"kind": "Space",
85+
"value": 1
86+
}
87+
],
88+
"presence": "Present"
89+
}
90+
],
91+
"presence": "Present"
92+
},
93+
null,
94+
null
95+
],
96+
"presence": "Present"
97+
},
98+
null,
99+
{
100+
"id": 87,
101+
"kind": "CodeBlock",
102+
"layout": [
103+
{
104+
"id": 73,
105+
"tokenKind": {
106+
"kind": "l_brace"
107+
},
108+
"leadingTrivia": [],
109+
"trailingTrivia": [],
110+
"presence": "Present"
111+
},
112+
{
113+
"id": 85,
114+
"kind": "CodeBlockItemList",
115+
"layout": [
116+
{
117+
"id": 84,
118+
"kind": "CodeBlockItem",
119+
"layout": [
120+
{
121+
"id": 83,
122+
"kind": "VariableDecl",
123+
"layout": [
124+
null,
125+
null,
126+
{
127+
"id": 74,
128+
"tokenKind": {
129+
"kind": "kw_let"
130+
},
131+
"leadingTrivia": [
132+
{
133+
"kind": "Newline",
134+
"value": 1
135+
},
136+
{
137+
"kind": "Space",
138+
"value": 2
139+
}
140+
],
141+
"trailingTrivia": [
142+
{
143+
"kind": "Space",
144+
"value": 1
145+
}
146+
],
147+
"presence": "Present"
148+
},
149+
{
150+
"id": 82,
151+
"kind": "PatternBindingList",
152+
"layout": [
153+
{
154+
"id": 81,
155+
"kind": "PatternBinding",
156+
"layout": [
157+
{
158+
"id": 76,
159+
"kind": "IdentifierPattern",
160+
"layout": [
161+
{
162+
"id": 75,
163+
"tokenKind": {
164+
"kind": "identifier",
165+
"text": "x"
166+
},
167+
"leadingTrivia": [],
168+
"trailingTrivia": [
169+
{
170+
"kind": "Space",
171+
"value": 1
172+
}
173+
],
174+
"presence": "Present"
175+
}
176+
],
177+
"presence": "Present"
178+
},
179+
null,
180+
{
181+
"id": 80,
182+
"kind": "InitializerClause",
183+
"layout": [
184+
{
185+
"id": 77,
186+
"tokenKind": {
187+
"kind": "equal"
188+
},
189+
"leadingTrivia": [],
190+
"trailingTrivia": [
191+
{
192+
"kind": "Space",
193+
"value": 1
194+
}
195+
],
196+
"presence": "Present"
197+
},
198+
{
199+
"id": 79,
200+
"kind": "StringLiteralExpr",
201+
"layout": [
202+
{
203+
"id": 78,
204+
"tokenKind": {
205+
"kind": "string_literal",
206+
"text": "\"hello world\""
207+
},
208+
"leadingTrivia": [],
209+
"trailingTrivia": [],
210+
"presence": "Present"
211+
}
212+
],
213+
"presence": "Present"
214+
}
215+
],
216+
"presence": "Present"
217+
},
218+
null,
219+
null
220+
],
221+
"presence": "Present"
222+
}
223+
],
224+
"presence": "Present"
225+
}
226+
],
227+
"presence": "Present"
228+
},
229+
null,
230+
null
231+
],
232+
"presence": "Present"
233+
},
234+
{
235+
"id": 43,
236+
"omitted": true
237+
}
238+
],
239+
"presence": "Present"
240+
},
241+
{
242+
"id": 86,
243+
"tokenKind": {
244+
"kind": "r_brace"
245+
},
246+
"leadingTrivia": [
247+
{
248+
"kind": "Newline",
249+
"value": 1
250+
}
251+
],
252+
"trailingTrivia": [],
253+
"presence": "Present"
254+
}
255+
],
256+
"presence": "Present"
257+
}
258+
],
259+
"presence": "Present"
260+
},
261+
null,
262+
null
263+
],
264+
"presence": "Present"
265+
},
266+
{
267+
"id": 61,
268+
"omitted": true
269+
}
270+
],
271+
"presence": "Present"
272+
},
273+
{
274+
"id": 91,
275+
"tokenKind": {
276+
"kind": "eof",
277+
"text": ""
278+
},
279+
"leadingTrivia": [
280+
{
281+
"kind": "Newline",
282+
"value": 1
283+
}
284+
],
285+
"trailingTrivia": [],
286+
"presence": "Present"
287+
}
288+
],
289+
"presence": "Present"
290+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %incr-transfer-tree %s --expected-incremental-syntax-tree %S/Outputs/incrementalTransfer.json
2+
3+
func foo() {
4+
}
5+
6+
func bar() {
7+
let x = "<<<hi|||hello>>> world"
8+
let y = 1
9+
}
10+
11+
func anotherMethod() {
12+
}

test/lit.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ ccp_opt = "-completion-cache-path %r" % completion_cache_path
346346
lit_config.note("Using code completion cache: " + completion_cache_path)
347347

348348
config.substitutions.append( ('%validate-incrparse', '%utils/incrparse/validate_parse.py --temp-dir %t --swift-syntax-test %swift-syntax-test') )
349+
config.substitutions.append( ('%incr-transfer-tree', '%utils/incrparse/incr_transfer_tree.py --temp-dir %t --swift-syntax-test %swift-syntax-test') )
349350
config.substitutions.append( ('%incr-transfer-roundtrip', '%%utils/incrparse/incr_transfer_round_trip.py --temp-dir %%t --swift-syntax-test %%swift-syntax-test --swift-swiftsyntax-test %r' % (config.swift_swiftsyntax_test)) )
350351
config.substitutions.append( ('%swift_obj_root', config.swift_obj_root) )
351352
config.substitutions.append( ('%swift_src_root', config.swift_src_root) )

utils/incrparse/incr_transfer_round_trip.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,8 @@
77
import subprocess
88
import sys
99

10-
from test_util import TestFailedError, serializeIncrParseMarkupFile
11-
12-
13-
def escapeCmdArg(arg):
14-
if '"' in arg or ' ' in arg:
15-
return '"%s"' % arg.replace('"', '\\"')
16-
else:
17-
return arg
18-
19-
20-
def run_command(cmd):
21-
print(' '.join([escapeCmdArg(arg) for arg in cmd]))
22-
return subprocess.check_output(cmd, stderr=subprocess.STDOUT)
10+
from test_util import TestFailedError, run_command, \
11+
serializeIncrParseMarkupFile
2312

2413

2514
def main():

0 commit comments

Comments
 (0)