Skip to content

Commit 588e381

Browse files
committed
Move tests from DiagnosticTests to other test files
Now that `AssertParse` is able to assert for diagnostics, it doesn’t make sense to keep the diagnostic test cases in a separate test file.
1 parent 127a71b commit 588e381

File tree

6 files changed

+97
-104
lines changed

6 files changed

+97
-104
lines changed

Sources/SwiftParser/SwiftParser.docc/FixingBugs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Fixing the first case where the parser does not recover according to the user’
5757
5858
To add a new, more contextual diagnostic, perform the following steps.
5959
60-
1. Add a test case to `DiagnosticTests.swift` like the following:
60+
1. Add a test case in `SwiftParserTest` that looks like the following
6161
6262
```swift
6363
AssertParse(

Tests/SwiftParserTest/Declarations.swift

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,72 @@ final class DeclarationTests: XCTestCase {
351351
"""
352352
)
353353
}
354+
355+
func testMissingColonInFunctionSignature() {
356+
AssertParse(
357+
"(first second #^DIAG^#Int)",
358+
{ $0.parseFunctionSignature() },
359+
diagnostics: [
360+
DiagnosticSpec(message: "Expected ':' in function parameter")
361+
]
362+
)
363+
}
364+
365+
func testExtraArgumentLabelsInFunctionSignature() {
366+
AssertParse(
367+
"(first second #^DIAG^#third fourth: Int)",
368+
{ $0.parseFunctionSignature() },
369+
diagnostics: [
370+
DiagnosticSpec(message: "Unexpected text 'third fourth' found in function parameter")
371+
]
372+
)
373+
}
374+
375+
func testMissingClosingParenInFunctionSignature() {
376+
AssertParse(
377+
"(first second: Int#^DIAG^#",
378+
{ $0.parseFunctionSignature() },
379+
diagnostics: [
380+
DiagnosticSpec(message: "Expected ')' to end parameter clause")
381+
]
382+
)
383+
}
384+
385+
func testMissingOpeningParenInFunctionSignature() {
386+
AssertParse(
387+
"#^DIAG^#first second: Int)",
388+
{ $0.parseFunctionSignature() },
389+
diagnostics: [
390+
DiagnosticSpec(message: "Expected '(' to start parameter clause")
391+
]
392+
)
393+
}
394+
395+
func testNoParamsForFunction() {
396+
AssertParse(
397+
"""
398+
class MyClass {
399+
func withoutParameters#^DIAG^#
400+
401+
func withParameters() {}
402+
}
403+
""",
404+
diagnostics: [
405+
DiagnosticSpec(message: "Expected argument list in function declaration")
406+
]
407+
)
408+
}
409+
410+
func testThrowsInWrongLocation() {
411+
AssertParse(
412+
"() -> #^DIAG^#throws Int",
413+
{ $0.parseFunctionSignature() },
414+
diagnostics: [
415+
DiagnosticSpec(message: "'throws' may only occur before '->'", fixIts: ["Move 'throws' before '->'"])
416+
],
417+
fixedSource: "() throws -> Int"
418+
)
419+
}
354420
}
355421

356422
extension Parser.DeclAttributes {

Tests/SwiftParserTest/DiagnosticTests.swift

Lines changed: 0 additions & 103 deletions
This file was deleted.

Tests/SwiftParserTest/Directives.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,13 @@ final class DirectiveTests: XCTestCase {
7070
"""
7171
)
7272
}
73+
74+
public func testUnterminatedPoundIf() {
75+
AssertParse(
76+
"#if test#^DIAG^#",
77+
diagnostics: [
78+
DiagnosticSpec(message: "Expected '#endif' in declaration")
79+
]
80+
)
81+
}
7382
}

Tests/SwiftParserTest/Expressions.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,13 @@ final class ExpressionTests: XCTestCase {
285285
"""
286286
)
287287
}
288+
289+
func testMissingColonInTernary() {
290+
AssertParse(
291+
"foo ? 1#^DIAG^#",
292+
diagnostics: [
293+
DiagnosticSpec(message: "Expected ':' after '? ...' in ternary expression")
294+
]
295+
)
296+
}
288297
}

Tests/SwiftParserTest/Statements.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,16 @@ final class StatementTests: XCTestCase {
105105
"""
106106
)
107107
}
108+
109+
func testCStyleForLoop() {
110+
AssertParse(
111+
"""
112+
#^DIAG^#for let x = 0; x < 10; x += 1, y += 1 {
113+
}
114+
""",
115+
diagnostics: [
116+
DiagnosticSpec(message: "C-style for statement has been removed in Swift 3", highlight: "let x = 0; x < 10; x += 1, y += 1 ")
117+
]
118+
)
119+
}
108120
}

0 commit comments

Comments
 (0)