8000 Move `AssertParse` tests from RecoveryTests.swift to other test files · swiftlang/swift-syntax@da0ffb9 · GitHub
[go: up one dir, main page]

Skip to content

Commit da0ffb9

Browse files
committed
Move AssertParse tests from RecoveryTests.swift to other tes 8000 t files
The goal is to get rid of RecoveryTests.swift altogether once we’ve merged `XCTAssertHasSubstructure` with `AssertParse`.
1 parent 588e381 commit da0ffb9

File tree

6 files changed

+297
-279
lines changed

6 files changed

+297
-279
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@_spi(RawSyntax) import SwiftSyntax
2+
@_spi(RawSyntax) import SwiftParser
3+
import XCTest
4+
5+
final class AttributeTests: XCTestCase {
6+
func testMissingArgumentToAttribute() {
7+
AssertParse(
8+
"""
9+
@_dynamicReplacement(#^DIAG_1^#
10+
func #^DIAG_2^#test_dynamic_replacement_for2() {
11+
}
12+
""",
13+
diagnostics: [
14+
// FIXME: We should be complaining about the missing ')' for the attribute
15+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected 'for'"),
16+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected ':'"),
17+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected ')'"),
18+
]
19+
)
20+
}
21+
}

Tests/SwiftParserTest/Declarations.swift

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,105 @@ final class DeclarationTests: XCTestCase {
417417
fixedSource: "() throws -> Int"
418418
)
419419
}
420+
421+
func testExtraneousRightBraceRecovery() {
422+
// FIXME: This test case should produce a diagnostics
423+
AssertParse("class ABC { let def = ghi(jkl: mno) } }")
424+
}
425+
426+
func testMissingSubscriptReturnClause() {
427+
AssertParse(
428+
"""
429+
struct Foo {
430+
subscript(x: String) #^DIAG^#{}
431+
}
432+
""",
433+
diagnostics: [
434+
// FIXME: This diagnostic should be more contextual
435+
DiagnosticSpec(message: "Expected '->'")
436+
]
437+
)
438+
}
439+
440+
func testClassWithLeadingNumber() {
441+
AssertParse(
442+
"""
443+
class #^DIAG^#23class {
444+
// expected-error@-1 {{class name can only start with a letter or underscore, not a number}}
445+
// expected-error@-2 {{'c' is not a valid digit in integer literal}}
446+
func 24method() {}
447+
// expected-error@-1 {{function name can only start with a letter or underscore, not a number}}
448+
// expected-error@-2 {{'m' is not a valid digit in integer literal}}
449+
}
450+
""",
451+
// FIXME: These are simply bad diagnostics. We should be complaining that identifiers cannot start with digits.
452+
diagnostics: [
453+
DiagnosticSpec(message: 8000 "Expected '' in declaration"),
454+
DiagnosticSpec(message: "Expected '{'"),
455+
DiagnosticSpec(message: "Expected '}'"),
456+
]
457+
)
458+
}
459+
460+
func testAccessors() {
461+
AssertParse(
462+
"""
463+
var bad1 : Int {
464+
_read async { 0 }
465+
}
466+
"""
467+
)
468+
469+
AssertParse(
470+
"""
471+
var bad2 : Int {
472+
get reasync { 0 }
473+
}
474+
"""
475+
)
476+
}
477+
478+
func testExpressionMember() {
479+
AssertParse(
480+
"""
481+
struct S {
482+
#^DIAG^#/ ###line 25 "line-directive.swift"
483+
}
484+
""",
485+
diagnostics: [
486+
// FIXME: The diagnostic should not contain a newline.
487+
DiagnosticSpec(
488+
message: """
489+
Unexpected text '
490+
/ ###line 25 "line-directive.swift"'
491+
"""
492+
)
493+
]
494+
)
495+
}
496+
497+
func testBogusProtocolRequirements() {
498+
// FIXME: This test case should produce a diagnostics
499+
AssertParse(
500+
"""
501+
protocol P {
502+
var prop : Int { get bogus rethrows set }
503+
}
504+
"""
505+
)
506+
}
507+
508+
func testTextRecovery() {
509+
AssertParse(
510+
"""
511+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do #^DIAG_1^#eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.#^DIAG_2^#
512+
""",
513+
diagnostics: [
514+
DiagnosticSpec(locationMarker: "DIAG_1", message: "Expected '{'"),
515+
DiagnosticSpec(locationMarker: "DIAG_2", message: "Expected '}'"),
516+
]
517+
)
518+
}
420519
}
421520

422521
extension Parser.DeclAttributes {

Tests/SwiftParserTest/Directives.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,22 @@ final class DirectiveTests: XCTestCase {
7979
]
8080
)
8181
}
82+
83+
func testExtraSyntaxInDirective() {
84+
// FIXME: This test case should produce a diagnostics
85+
86+
AssertParse(
87+
"""
88+
#if os(iOS)
89+
func foo() {}
90+
} // expected-error{{unexpected '}' in conditional compilation block}}
91+
#else
92+
func bar() {}
93+
func baz() {}
94+
} // expected-error{{unexpected '}' in conditional compilation block}}
95+
#endif
96+
"""
97+
)
98+
}
99+
82100
}

Tests/SwiftParserTest/Expressions.swift

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,48 @@ final class ExpressionTests: XCTestCase {
278278
)
279279
}
280280

281+
func testSingleQuoteStringLiteral() {
282+
// FIXME: This test case should produce a diagnostics
283+
AssertParse(
284+
#"""
285+
'red'
286+
"""#
287+
)
288+
}
289+
290+
func testStringBogusClosingDelimiters() {
291+
AssertParse(
292+
#"\\(#^DIAG^#"#,
293+
diagnostics: [
294+
DiagnosticSpec(message: "Expected ')' to end expression")
295+
]
296+
)
297+
298+
AssertParse(
299+
##"""
300+
#"\\("#
301+
"""##
302+
)
303+
304+
AssertParse(
305+
#"""
306+
"#^DIAG^#
307+
"""#,
308+
diagnostics: [
309+
DiagnosticSpec(message: #"Expected '"' in expression"#)
310+
]
311+
)
312+
313+
AssertParse(
314+
#"""
315+
"'#^DIAG^#
316+
"""#,
317+
diagnostics: [
318+
DiagnosticSpec(message: #"Expected '"' in expression"#)
319+
]
320+
)
321+
}
322+
281323
func testRangeSubscript() {
282324
AssertParse(
283325
"""
@@ -294,4 +336,46 @@ final class ExpressionTests: XCTestCase {
294336
]
295337
)
296338
}
339+
340+
func testBogusKeypathBaseRecovery() {
341+
AssertParse(
342+
#"""
343+
func nestThoseIfs() {\n if false != true {\n print "\(i)\"\n#^DIAG^#
344 F987 +
"""#,
345+
diagnostics: [
346+
DiagnosticSpec(message: #"Expected '"' in expression"#),
347+
DiagnosticSpec(message: "Expected '}'"),
348+
DiagnosticSpec(message: "Expected '}'"),
349+
]
350+
)
351+
}
352+
353+
func testMissingArrowInArrowExpr() {
354+
AssertParse(
355+
"[(Int) -> #^DIAG^#throws Int]()",
356+
diagnostics: [
357+
// FIXME: We should suggest to move 'throws' in front of '->'
358+
DiagnosticSpec(message: "Unexpected text 'throws Int' found in expression")
359+
]
360+
)
361+
362+
AssertParse(
363+
"let _ = [Int throws #^DIAG^#Int]()",
364+
diagnostics: [
365+
DiagnosticSpec(message: "Expected '->' in expression")
366+
]
367+
)
368+
}
369+
370+
func testBogusThrowingTernary() {
371+
// FIXME: This test case should produce a diagnostics
372+
AssertParse(
373+
"""
374+
do {
375+
true ? () : throw opaque_error()
376+
} catch _ {
377+
}
378+
"""
379+
)
380+
}
297381
}

0 commit comments

Comments
 (0)
0