Skip to content

Commit 7980234

Browse files
committed
Add highlight to assertion
1 parent 5eb8f82 commit 7980234

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

Tests/SwiftParserTest/Assertions.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,15 @@ func assertDiagnostic<T: SyntaxProtocol>(
398398
line: spec.line
399399
)
400400
}
401-
if let highlight = spec.highlight {
402-
assertStringsEqualWithDiff(
403-
diag.highlights.map(\.description).joined().trimmingTrailingWhitespace(),
404-
highlight.trimmingTrailingWhitespace(),
405-
file: spec.file,
406-
line: spec.line
407-
)
408-
}
401+
402+
let highlight = spec.highlight ?? diag.node.description
403+
assertStringsEqualWithDiff(
404+
diag.highlights.map(\.description).joined().trimmingTrailingWhitespace(),
405+
highlight.trimmingTrailingWhitespace(),
406+
file: spec.file,
407+
line: spec.line
408+
)
409+
409410
if diag.notes.count != spec.notes.count {
410411
XCTFail(
411412
"""

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,9 @@ final class ExpressionTests: XCTestCase {
13161316
diagnostics: [
13171317
DiagnosticSpec(
13181318
message: "insufficient indentation of line in multi-line string literal",
1319+
highlight: """
1320+
1321+
""",
13191322
notes: [NoteSpec(message: "should match indentation here")],
13201323
fixIts: ["change indentation of this line to match closing delimiter"]
13211324
)

Tests/SwiftParserTest/translated/MultilineErrorsTests.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ final class MultilineErrorsTests: XCTestCase {
6464
diagnostics: [
6565
DiagnosticSpec(
6666
message: "insufficient indentation of line in multi-line string literal",
67+
highlight: """
68+
69+
""",
6770
notes: [NoteSpec(message: "should match indentation here")],
6871
fixIts: ["change indentation of this line to match closing delimiter"]
6972
)
@@ -89,6 +92,9 @@ final class MultilineErrorsTests: XCTestCase {
8992
diagnostics: [
9093
DiagnosticSpec(
9194
message: "insufficient indentation of line in multi-line string literal",
95+
highlight: """
96+
97+
""",
9298
notes: [NoteSpec(message: "should match indentation here")],
9399
fixIts: ["change indentation of this line to match closing delimiter"]
94100
)
@@ -114,6 +120,9 @@ final class MultilineErrorsTests: XCTestCase {
114120
diagnostics: [
115121
DiagnosticSpec(
116122
message: "insufficient indentation of line in multi-line string literal",
123+
highlight: """
124+
125+
""",
117126
notes: [NoteSpec(message: "should match indentation here")],
118127
fixIts: ["change indentation of this line to match closing delimiter"]
119128
)
@@ -138,6 +147,9 @@ final class MultilineErrorsTests: XCTestCase {
138147
diagnostics: [
139148
DiagnosticSpec(
140149
message: "insufficient indentation of line in multi-line string literal",
150+
highlight: """
151+
152+
""",
141153
notes: [NoteSpec(message: "should match indentation here")],
142154
fixIts: ["change indentation of this line to match closing delimiter"]
143155
)
@@ -162,6 +174,9 @@ final class MultilineErrorsTests: XCTestCase {
162174
diagnostics: [
163175
DiagnosticSpec(
164176
message: "insufficient indentation of line in multi-line string literal",
177+
highlight: """
178+
179+
""",
165180
notes: [NoteSpec(message: "should match indentation here")],
166181
fixIts: ["change indentation of this line to match closing delimiter"]
167182
)
@@ -187,6 +202,9 @@ final class MultilineErrorsTests: XCTestCase {
187202
diagnostics: [
188203
DiagnosticSpec(
189204
message: "insufficient indentation of line in multi-line string literal",
205+
highlight: """
206+
207+
""",
190208
notes: [NoteSpec(message: "should match indentation here")],
191209
fixIts: ["change indentation of this line to match closing delimiter"]
192210
)
@@ -213,6 +231,9 @@ final class MultilineErrorsTests: XCTestCase {
213231
diagnostics: [
214232
DiagnosticSpec(
215233
message: "unexpected tab in indentation of line in multi-line string literal",
234+
highlight: """
235+
236+
""",
216237
notes: [NoteSpec(message: "should match indentation here")],
217238
fixIts: ["change indentation of this line to match closing delimiter"]
218239
)
@@ -238,6 +259,9 @@ final class MultilineErrorsTests: XCTestCase {
238259
diagnostics: [
239260
DiagnosticSpec(
240261
message: "unexpected tab in indentation of line in multi-line string literal",
262+
highlight: """
263+
264+
""",
241265
notes: [NoteSpec(message: "should match indentation here")],
242266
fixIts: ["change indentation of this line to match closing delimiter"]
243267
)
@@ -263,6 +287,9 @@ final class MultilineErrorsTests: XCTestCase {
263287
diagnostics: [
264288
DiagnosticSpec(
265289
message: "unexpected space in indentation of line in multi-line string literal",
290+
highlight: """
291+
292+
""",
266293
notes: [NoteSpec(message: "should match indentation here")],
267294
fixIts: ["change indentation of this line to match closing delimiter"]
268295
)
@@ -288,6 +315,9 @@ final class MultilineErrorsTests: XCTestCase {
288315
diagnostics: [
289316
DiagnosticSpec(
290317
message: "unexpected space in indentation of line in multi-line string literal",
318+
highlight: """
319+
320+
""",
291321
notes: [NoteSpec(message: "should match indentation here")],
292322
fixIts: ["change indentation of this line to match closing delimiter"]
293323
)
@@ -381,6 +411,9 @@ final class MultilineErrorsTests: XCTestCase {
381411
diagnostics: [
382412
DiagnosticSpec(
383413
message: "unexpected space in indentation of the next 2 lines in multi-line string literal",
414+
highlight: """
415+
416+
""",
384417
notes: [NoteSpec(message: "should match indentation here")],
385418
fixIts: ["change indentation of this line to match closing delimiter"]
386419
)
@@ -416,18 +449,27 @@ final class MultilineErrorsTests: XCTestCase {
416449
DiagnosticSpec(
417450
locationMarker: "1️⃣",
418451
message: "insufficient indentation of the next 4 lines in multi-line string literal",
452+
highlight: """
453+
454+
""",
419455
notes: [NoteSpec(message: "should match indentation here")],
420456
fixIts: ["change indentation of this line to match closing delimiter"]
421457
),
422458
DiagnosticSpec(
423459
locationMarker: "2️⃣",
424460
message: "unexpected space in indentation of the next 2 lines in multi-line string literal",
461+
highlight: """
462+
463+
""",
425464
notes: [NoteSpec(message: "should match indentation here")],
426465
fixIts: ["change indentation of this line to match closing delimiter"]
427466
),
428467
DiagnosticSpec(
429468
locationMarker: "3️⃣",
430469
message: "insufficient indentation of the next 2 lines in multi-line string literal",
470+
highlight: """
471+
472+
""",
431473
notes: [NoteSpec(message: "should match indentation here")],
432474
fixIts: ["change indentation of this line to match closing delimiter"]
433475
),
@@ -463,6 +505,9 @@ final class MultilineErrorsTests: XCTestCase {
463505
diagnostics: [
464506
DiagnosticSpec(
465507
message: "insufficient indentation of the next 2 lines in multi-line string literal",
508+
highlight: """
509+
510+
""",
466511
notes: [NoteSpec(message: "should match indentation here")],
467512
fixIts: ["change indentation of this line to match closing delimiter"]
468513
)
@@ -490,12 +535,18 @@ final class MultilineErrorsTests: XCTestCase {
490535
DiagnosticSpec(
491536
locationMarker: "1️⃣",
492537
message: "insufficient indentation of line in multi-line string literal",
538+
highlight: """
539+
540+
""",
493541
notes: [NoteSpec(message: "should match indentation here")],
494542
fixIts: ["change indentation of this line to match closing delimiter"]
495543
),
496544
DiagnosticSpec(
497545
locationMarker: "2️⃣",
498546
message: "insufficient indentation of line in multi-line string literal",
547+
highlight: """
548+
549+
""",
499550
notes: [NoteSpec(message: "should match indentation here")],
500551
fixIts: ["change indentation of this line to match closing delimiter"]
501552
),
@@ -854,6 +905,9 @@ final class MultilineErrorsTests: XCTestCase {
854905
diagnostics: [
855906
DiagnosticSpec(
856907
message: "insufficient indentation of line in multi-line string literal",
908+
highlight: """
909+
910+
""",
857911
notes: [NoteSpec(message: "should match indentation here")],
858912
fixIts: ["change indentation of this line to match closing delimiter"]
859913
)
@@ -881,12 +935,18 @@ final class MultilineErrorsTests: XCTestCase {
881935
DiagnosticSpec(
882936
locationMarker: "1️⃣",
883937
message: "insufficient indentation of line in multi-line string literal",
938+
highlight: """
939+
940+
""",
884941
notes: [NoteSpec(message: "should match indentation here")],
885942
fixIts: ["change indentation of this line to match closing delimiter"]
886943
),
887944
DiagnosticSpec(
888945
locationMarker: "2️⃣",
889946
message: "insufficient indentation of line in multi-line string literal",
947+
highlight: """
948+
949+
""",
890950
notes: [NoteSpec(message: "should match indentation here")],
891951
fixIts: ["change indentation of this line to match closing delimiter"]
892952
),
@@ -915,6 +975,9 @@ final class MultilineErrorsTests: XCTestCase {
915975
diagnostics: [
916976
DiagnosticSpec(
917977
message: "insufficient indentation of the next 3 lines in multi-line string literal",
978+
highlight: """
979+
980+
""",
918981
notes: [NoteSpec(message: "should match indentation here")],
919982
fixIts: ["change indentation of this line to match closing delimiter"]
920983
)

0 commit comments

Comments
 (0)