Skip to content

Commit d0fe534

Browse files
committed
Translate lit_tests/incrParse with assertIncrementalParse
1 parent 4db7cb2 commit d0fe534

File tree

1 file changed

+391
-0
lines changed

1 file changed

+391
-0
lines changed

Tests/SwiftParserTest/IncrementalParsingTests.swift

Lines changed: 391 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,395 @@ public class IncrementalParsingTests: XCTestCase {
3737
]
3838
)
3939
}
40+
41+
public func testAddElse() {
42+
assertIncrementalParse(
43+
"""
44+
#if false
45+
⏩️⏸️#else⏪️
46+
"""
47+
)
48+
}
49+
50+
public func testInsertSpace() {
51+
assertIncrementalParse(
52+
"""
53+
class AnimationType {
54+
func foo(x: Blah) {
55+
switch x {
56+
case (.
57+
58+
extension AnimationType {
59+
public⏩️⏸️ ⏪️
60+
"""
61+
)
62+
}
63+
64+
public func testAddFuncParens() {
65+
assertIncrementalParse(
66+
"""
67+
class InvalidFuncDecls {
68+
func parensAdded⏩️⏸️()⏪️ {
69+
}
70+
}
71+
"""
72+
)
73+
}
74+
75+
public func testAddOpeningBrace() {
76+
assertIncrementalParse(
77+
"""
78+
class InvalidFuncDecls {
79+
func openingBraceAdded() ⏩️⏸️{⏪️
80+
}
81+
"""
82+
)
83+
}
84+
85+
public func testAddClosingBrace() {
86+
assertIncrementalParse(
87+
"""
88+
class InvalidFuncDecls {
89+
func closingBraceAdded() {
90+
91+
⏩️⏸️}⏪️
92+
}
93+
"""
94+
)
95+
}
96+
97+
public func testRemoveFuncKeyword() {
98+
assertIncrementalParse(
99+
"""
100+
class InvalidFuncDecls {
101+
⏩️func⏸️⏪️ funcKeywordRemoved() {
102+
103+
}
104+
}
105+
"""
106+
)
107+
}
108+
109+
public func testAddParamName() {
110+
assertIncrementalParse(
111+
"""
112+
class InvalidFuncDecls {
113+
func addingParamName(⏩️⏸️arg⏪️) {
114+
115+
}
116+
}
117+
"""
118+
)
119+
}
120+
121+
public func testAddParamColon() {
122+
assertIncrementalParse(
123+
"""
124+
class InvalidFuncDecls {
125+
func addingParamColon(arg⏩️⏸️:⏪️) {
126+
}
127+
}
128+
"""
129+
)
130+
}
131+
132+
public func testAddingParamType() {
133+
assertIncrementalParse(
134+
"""
135+
class InvalidFuncDecls {
136+
func addingParamType(arg:⏩️⏸️ String⏪️) {
137+
}
138+
}
139+
"""
140+
)
141+
}
142+
143+
public func testInsertTextIdentifier() {
144+
assertIncrementalParse(
145+
"""
146+
self = ⏩️⏸️_ _⏪️foo(1)[object1, object2] + o bar(1)
147+
"""
148+
)
149+
}
150+
151+
public func testNestedInitializers() {
152+
assertIncrementalParse(
153+
"""
154+
class NestedInitializers {
155+
⏩️⏸️init() {⏪️
156+
init() {
157+
158+
}
159+
⏩️⏸️}⏪️
160+
}
161+
"""
162+
)
163+
}
164+
165+
public func testMultiEditMapping() throws {
166+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
167+
assertIncrementalParse(
168+
"""
169+
let one: Int;let two: Int; let three: Int; ⏩️⏸️ ⏪️⏩️⏸️ ⏪️let found: Int;let five: Int;
170+
""",
171+
reusedNodes: [
172+
ReusedNodeSpec("let one: Int;", kind: .codeBlockItem),
173+
ReusedNodeSpec("let two: Int;", kind: .codeBlockItem),
174+
ReusedNodeSpec("let five: Int;", kind: .codeBlockItem),
175+
]
176+
)
177+
}
178+
179+
public func testAddProperty() throws {
180+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
181+
assertIncrementalParse(
182+
"""
183+
struct Foo {
184+
let a: Int
185+
let b: Int
186+
let c: Int
187+
let d: String
188+
⏩️⏸️let e_newProp: String⏪️
189+
let f: Int
190+
let g: Int
191+
}
192+
""",
193+
reusedNodes: [
194+
ReusedNodeSpec("let a: Int", kind: .memberDeclListItem),
195+
ReusedNodeSpec("let b: Int", kind: .memberDeclListItem),
196+
ReusedNodeSpec("let c: Int", kind: .memberDeclListItem),
197+
ReusedNodeSpec("let g: Int", kind: .memberDeclListItem),
198+
]
199+
)
200+
}
201+
202+
public func testWarpInClass() throws {
203+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
204+
assertIncrementalParse(
205+
"""
206+
⏩️⏸️class Foo {⏪️
207+
func foo1() {
208+
print("Hello Foo!")
209+
}
210+
211+
func foo2() {
212+
print("Hello again")
213+
}
214+
""",
215+
reusedNodes: [
216+
ReusedNodeSpec(
217+
"""
218+
func foo1() {
219+
print("Hello Foo!")
220+
}
221+
""",
222+
kind: .functionDecl
223+
),
224+
ReusedNodeSpec(
225+
"""
226+
func foo2() {
227+
print("Hello again!")
228+
}
229+
""",
230+
kind: .functionDecl
231+
),
232+
]
233+
)
234+
}
235+
236+
public func testUnwarpClass() throws {
237+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
238+
assertIncrementalParse(
239+
"""
240+
⏩️class Bar {⏸️⏪️
241+
func bar1() {
242+
let pi = 3.1415
243+
print("Pi is (approximately) \\(pi)")
244+
}
245+
246+
func bar2() {
247+
print("I can compute Pi as well:")
248+
bar1()
249+
}
250+
}
251+
""",
252+
reusedNodes: [
253+
ReusedNodeSpec(
254+
"""
255+
func bar1() {
256+
let pi = 3.1415
257+
print("Pi is (approximately) \\(pi)")
258+
}
259+
""",
260+
kind: .functionDecl
261+
),
262+
ReusedNodeSpec(
263+
"""
264+
func bar2() {
265+
print("I can compute Pi as well:")
266+
bar1()
267+
}
268+
""",
269+
kind: .functionDecl
270+
),
271+
]
272+
)
273+
}
274+
275+
public func testNextTokenCalculation() throws {
276+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
277+
assertIncrementalParse(
278+
"""
279+
let a = "hello"
280+
let c = "⏩️ ⏸️⏪️world"
281+
""",
282+
reusedNodes: [
283+
ReusedNodeSpec("let a = \"hello\"", kind: .codeBlockItem)
284+
]
285+
)
286+
}
287+
288+
public func testReplace() throws {
289+
try XCTSkipIf(true, "Swift parser does not handle node reuse yet")
290+
assertIncrementalParse(
291+
"""
292+
func foo() {
293+
}
294+
295+
_ = ⏩️6⏸️7⏪️
296+
""",
297+
reusedNodes: [
298+
ReusedNodeSpec(
299+
"""
300+
func foo() {
301+
}
302+
""",
303+
kind: .codeBlockItem
304+
)
305+
]
306+
)
307+
}
308+
309+
public func testReplaceByLonger() {
310+
assertIncrementalParse(
311+
"""
312+
_ = ⏩️6⏸️"Hello World"⏪️
313+
"""
314+
)
315+
}
316+
317+
public func testReplaceByShorter() {
318+
assertIncrementalParse(
319+
"""
320+
_ = ⏩️"Hello again"⏸️"a"⏪️
321+
"""
322+
)
323+
}
324+
325+
public func testInsert() {
326+
assertIncrementalParse(
327+
"""
328+
⏩️⏸️foo()⏪️
329+
"""
330+
)
331+
}
332+
333+
public func testRemove() {
334+
assertIncrementalParse(
335+
"""
336+
⏩️print("abc")⏸️⏪️
337+
"""
338+
)
339+
}
340+
341+
public func testAttachToPrevNode() {
342+
assertIncrementalParse(
343+
"""
344+
foo()
345+
⏩️⏸️{}⏪️
346+
_ = 1
347+
"""
348+
)
349+
}
350+
351+
public func testClassSurrounding() {
352+
assertIncrementalParse(
353+
"""
354+
⏩️⏸️class C {⏪️
355+
func method1() {}
356+
"""
357+
)
358+
}
359+
360+
public func testMultiEdit() {
361+
assertIncrementalParse(
362+
"""
363+
⏩️⏸️class C {⏪️
364+
func method1() {}
365+
⏩️⏸️}⏪️
366+
"""
367+
)
368+
}
369+
370+
public func testMultiEditSameLine() {
371+
assertIncrementalParse(
372+
"""
373+
⏩️_⏸️let x⏪️ = ⏩️1⏸️"hi"⏪️
374+
"""
375+
)
376+
}
377+
378+
public func testReplaceWithMultiByteChar() {
379+
assertIncrementalParse(
380+
"""
381+
let x = "⏩️a⏸️👨‍👩‍👧‍👦⏪️"
382+
"""
383+
)
384+
}
385+
386+
public func testReplaceMultiByteCharWithShorter() {
387+
assertIncrementalParse(
388+
"""
389+
let x = "⏩️👨‍👩‍👧‍👦⏸️🎉⏪️"
390+
"""
391+
)
392+
}
393+
394+
public func testLastCharOfStruct() {
395+
assertIncrementalParse(
396+
"""
397+
private struc⏩️⏸️t⏪️ MyStruct {
398+
}
399+
"""
400+
)
401+
}
402+
403+
public func testAddArrayCloseBracket() {
404+
assertIncrementalParse(
405+
"""
406+
var computedVar: [Int] {
407+
return [1
408+
⏩️⏸️]⏪️
409+
}
410+
"""
411+
)
412+
}
413+
414+
public func testAddIfOpenBrace() {
415+
assertIncrementalParse(
416+
"""
417+
if true ⏩️⏸️{⏪️
418+
_ = 5
419+
}
420+
"""
421+
)
422+
}
423+
424+
public func testExtendIdentifier() {
425+
assertIncrementalParse(
426+
"""
427+
let y⏩️⏸️ou⏪️ = 42
428+
"""
429+
)
430+
}
40431
}

0 commit comments

Comments
 (0)