Skip to content

Commit d698590

Browse files
committed
Add notes to assertion
1 parent 17e41b6 commit d698590

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

Tests/SwiftParserTest/Assertions.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,16 @@ func assertDiagnostic<T: SyntaxProtocol>(
418418
line: line
419419
)
420420
}
421-
if let notes = spec.notes {
421+
if diag.notes.count != (spec.notes?.count ?? 0) {
422+
XCTFail(
423+
"""
424+
Expected \(spec.notes?.count ?? 0) notes but received \(diag.notes.count):
425+
\(diag.notes.map { $0.noteMessage.message }.joined(separator: "\n"))
426+
""",
427+
file: file,
428+
line: line
429+
)
430+
} else if let notes = spec.notes {
422431
if diag.notes.count != notes.count {
423432
XCTFail(
424433
"""

Tests/SwiftParserTest/AttributeTests.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ final class AttributeTests: XCTestCase {
1818
func testMissingArgumentToAttribute() {
1919
assertParse(
2020
"""
21-
@_dynamicReplacement(1️⃣
21+
@_dynamicReplacementℹ️(1️⃣
2222
func 2️⃣test_dynamic_replacement_for2() {
2323
}
2424
""",
2525
diagnostics: [
2626
DiagnosticSpec(message: "expected argument for '@_dynamicReplacement' attribute", fixIts: ["insert attribute argument"]),
27-
DiagnosticSpec(message: "expected ')' to end attribute", fixIts: ["insert ')'"]),
27+
DiagnosticSpec(message: "expected ')' to end attribute",
28+
notes: [NoteSpec(message: "to match this opening '('")],
29+
fixIts: ["insert ')'"]),
2830
],
2931
fixedSource: """
3032
@_dynamicReplacement(for : <#identifier#>)
@@ -37,14 +39,17 @@ final class AttributeTests: XCTestCase {
3739
func testMissingGenericTypeToAttribute() {
3840
assertParse(
3941
"""
40-
@differentiable(reverse wrt1️⃣,where T2️⃣
42+
@differentiableℹ️(reverse wrt1️⃣,where T2️⃣
4143
func podcastPlaybackSpeed() {
4244
}
4345
""",
4446
diagnostics: [
45-
DiagnosticSpec(locationMarker: "1️⃣", message: "expected ':' and parameters in '@differentiable' argument", fixIts: ["insert ':' and parameters"]),
47+
DiagnosticSpec(locationMarker: "1️⃣", message: "expected ':' and parameters in '@differentiable' argument",
48+
fixIts: ["insert ':' and parameters"]),
4649
DiagnosticSpec(locationMarker: "2️⃣", message: "expected ':' or '==' to indicate a conformance or same-type requirement"),
47-
DiagnosticSpec(locationMarker: "2️⃣", message: "expected ')' to end attribute", fixIts: ["insert ')'"]),
50+
DiagnosticSpec(locationMarker: "2️⃣", message: "expected ')' to end attribute",
51+
notes: [NoteSpec(message: "to match this opening '('")],
52+
fixIts: ["insert ')'"]),
4853
],
4954
fixedSource: """
5055
@differentiable(reverse wrt: <#identifier#>,where T)
@@ -57,11 +62,12 @@ final class AttributeTests: XCTestCase {
5762
func testMissingClosingParenToAttribute() {
5863
assertParse(
5964
"""
60-
@_specialize(e1️⃣
65+
@_specializeℹ️(e1️⃣
6166
""",
6267
diagnostics: [
6368
DiagnosticSpec(message: "expected ':' in attribute argument"),
64-
DiagnosticSpec(message: "expected ')' to end attribute"),
69+
DiagnosticSpec(message: "expected ')' to end attribute",
70+
notes: [NoteSpec(message: "to match this opening '('")]),
6571
DiagnosticSpec(message: "expected declaration after attribute"),
6672
]
6773
)

Tests/SwiftParserTest/translated/AsyncTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ final class AsyncTests: XCTestCase {
8888
func testAsync8() {
8989
assertParse(
9090
"""
91-
func asyncGlobal8() async throws 1️⃣async -> 2️⃣async Int 3️⃣async {}
91+
func asyncGlobal8() ℹ️async throws 1️⃣async -> 2️⃣async Int 3️⃣async {}
9292
""",
9393
diagnostics: [
94-
DiagnosticSpec(locationMarker: "1️⃣", message: "'async' has already been specified", fixIts: ["remove redundant 'async'"]),
95-
DiagnosticSpec(locationMarker: "2️⃣", message: "'async' must preceed '->'", fixIts: ["remove redundant 'async'"]),
96-
DiagnosticSpec(locationMarker: "3️⃣", message: "'async' must preceed '->'", fixIts: ["remove redundant 'async'"]),
94+
DiagnosticSpec(locationMarker: "1️⃣", message: "'async' has already been specified",
95+
notes: [NoteSpec(message: "'async' declared here")],
96+
fixIts: ["remove redundant 'async'"]),
97+
DiagnosticSpec(locationMarker: "2️⃣", message: "'async' must preceed '->'",
98+
fixIts: ["remove redundant 'async'"]),
99+
DiagnosticSpec(locationMarker: "3️⃣", message: "'async' must preceed '->'",
100+
fixIts: ["remove redundant 'async'"]),
97101
],
98102
fixedSource: """
99103
func asyncGlobal8() async throws -> Int {}

0 commit comments

Comments
 (0)