Skip to content

Commit ee682e5

Browse files
authored
Merge pull request #1689 from kimdv/kimdv/add-highlight-assertion
Add highlight to assertion
2 parents 447c3a8 + 1a4ae2a commit ee682e5

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

Tests/SwiftParserTest/Assertions.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,14 +402,15 @@ func assertDiagnostic<T: SyntaxProtocol>(
402402
line: spec.line
403403
)
404404
}
405-
if let highlight = spec.highlight {
406-
assertStringsEqualWithDiff(
407-
diag.highlights.map(\.description).joined().trimmingTrailingWhitespace(),
408-
highlight.trimmingTrailingWhitespace(),
409-
file: spec.file,
410-
line: spec.line
411-
)
412-
}
405+
406+
let highlight = spec.highlight ?? diag.node.description
407+
assertStringsEqualWithDiff(
408+
diag.highlights.map(\.description).joined().trimmingTrailingWhitespace(),
409+
highlight.trimmingTrailingWhitespace(),
410+
file: spec.file,
411+
line: spec.line
412+
)
413+
413414
if diag.notes.count != spec.notes.count {
414415
XCTFail(
415416
"""

Tests/SwiftParserTest/ExpressionTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,7 @@ final class ExpressionTests: XCTestCase {
13181318
diagnostics: [
13191319
DiagnosticSpec(
13201320
message: "insufficient indentation of line in multi-line string literal",
1321+
highlight: " ",
13211322
notes: [NoteSpec(message: "should match indentation here")],
13221323
fixIts: ["change indentation of this line to match closing delimiter"]
13231324
)

Tests/SwiftParserTest/translated/MultilineErrorsTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ final class MultilineErrorsTests: XCTestCase {
6464
diagnostics: [
6565
DiagnosticSpec(
6666
message: "insufficient indentation of line in multi-line string literal",
67+
highlight: " ",
6768
notes: [NoteSpec(message: "should match indentation here")],
6869
fixIts: ["change indentation of this line to match closing delimiter"]
6970
)
@@ -89,6 +90,7 @@ final class MultilineErrorsTests: XCTestCase {
8990
diagnostics: [
9091
DiagnosticSpec(
9192
message: "insufficient indentation of line in multi-line string literal",
93+
highlight: " ",
9294
notes: [NoteSpec(message: "should match indentation here")],
9395
fixIts: ["change indentation of this line to match closing delimiter"]
9496
)
@@ -114,6 +116,7 @@ final class MultilineErrorsTests: XCTestCase {
114116
diagnostics: [
115117
DiagnosticSpec(
116118
message: "insufficient indentation of line in multi-line string literal",
119+
highlight: " ",
117120
notes: [NoteSpec(message: "should match indentation here")],
118121
fixIts: ["change indentation of this line to match closing delimiter"]
119122
)
@@ -138,6 +141,7 @@ final class MultilineErrorsTests: XCTestCase {
138141
diagnostics: [
139142
DiagnosticSpec(
140143
message: "insufficient indentation of line in multi-line string literal",
144+
highlight: " ",
141145
notes: [NoteSpec(message: "should match indentation here")],
142146
fixIts: ["change indentation of this line to match closing delimiter"]
143147
)
@@ -162,6 +166,7 @@ final class MultilineErrorsTests: XCTestCase {
162166
diagnostics: [
163167
DiagnosticSpec(
164168
message: "insufficient indentation of line in multi-line string literal",
169+
highlight: " ",
165170
notes: [NoteSpec(message: "should match indentation here")],
166171
fixIts: ["change indentation of this line to match closing delimiter"]
167172
)
@@ -187,6 +192,7 @@ final class MultilineErrorsTests: XCTestCase {
187192
diagnostics: [
188193
DiagnosticSpec(
189194
message: "insufficient indentation of line in multi-line string literal",
195+
highlight: " ",
190196
notes: [NoteSpec(message: "should match indentation here")],
191197
fixIts: ["change indentation of this line to match closing delimiter"]
192198
)
@@ -213,6 +219,7 @@ final class MultilineErrorsTests: XCTestCase {
213219
diagnostics: [
214220
DiagnosticSpec(
215221
message: "unexpected tab in indentation of line in multi-line string literal",
222+
highlight: " ",
216223
notes: [NoteSpec(message: "should match indentation here")],
217224
fixIts: ["change indentation of this line to match closing delimiter"]
218225
)
@@ -238,6 +245,7 @@ final class MultilineErrorsTests: XCTestCase {
238245
diagnostics: [
239246
DiagnosticSpec(
240247
message: "unexpected tab in indentation of line in multi-line string literal",
248+
highlight: " ",
241249
notes: [NoteSpec(message: "should match indentation here")],
242250
fixIts: ["change indentation of this line to match closing delimiter"]
243251
)
@@ -263,6 +271,7 @@ final class MultilineErrorsTests: XCTestCase {
263271
diagnostics: [
264272
DiagnosticSpec(
265273
message: "unexpected space in indentation of line in multi-line string literal",
274+
highlight: " ",
266275
notes: [NoteSpec(message: "should match indentation here")],
267276
fixIts: ["change indentation of this line to match closing delimiter"]
268277
)
@@ -288,6 +297,7 @@ final class MultilineErrorsTests: XCTestCase {
288297
diagnostics: [
289298
DiagnosticSpec(
290299
message: "unexpected space in indentation of line in multi-line string literal",
300+
highlight: " ",
291301
notes: [NoteSpec(message: "should match indentation here")],
292302
fixIts: ["change indentation of this line to match closing delimiter"]
293303
)
@@ -381,6 +391,7 @@ final class MultilineErrorsTests: XCTestCase {
381391
diagnostics: [
382392
DiagnosticSpec(
383393
message: "unexpected space in indentation of the next 2 lines in multi-line string literal",
394+
highlight: " ",
384395
notes: [NoteSpec(message: "should match indentation here")],
385396
fixIts: ["change indentation of this line to match closing delimiter"]
386397
)
@@ -416,18 +427,21 @@ final class MultilineErrorsTests: XCTestCase {
416427
DiagnosticSpec(
417428
locationMarker: "1️⃣",
418429
message: "insufficient indentation of the next 4 lines in multi-line string literal",
430+
highlight: " ",
419431
notes: [NoteSpec(message: "should match indentation here")],
420432
fixIts: ["change indentation of this line to match closing delimiter"]
421433
),
422434
DiagnosticSpec(
423435
locationMarker: "2️⃣",
424436
message: "unexpected space in indentation of the next 2 lines in multi-line string literal",
437+
highlight: " ",
425438
notes: [NoteSpec(message: "should match indentation here")],
426439
fixIts: ["change indentation of this line to match closing delimiter"]
427440
),
428441
DiagnosticSpec(
429442
locationMarker: "3️⃣",
430443
message: "insufficient indentation of the next 2 lines in multi-line string literal",
444+
highlight: " ",
431445
notes: [NoteSpec(message: "should match indentation here")],
432446
fixIts: ["change indentation of this line to match closing delimiter"]
433447
),
@@ -463,6 +477,7 @@ final class MultilineErrorsTests: XCTestCase {
463477
diagnostics: [
464478
DiagnosticSpec(
465479
message: "insufficient indentation of the next 2 lines in multi-line string literal",
480+
highlight: " ",
466481
notes: [NoteSpec(message: "should match indentation here")],
467482
fixIts: ["change indentation of this line to match closing delimiter"]
468483
)
@@ -490,12 +505,14 @@ final class MultilineErrorsTests: XCTestCase {
490505
DiagnosticSpec(
491506
locationMarker: "1️⃣",
492507
message: "insufficient indentation of line in multi-line string literal",
508+
highlight: " ",
493509
notes: [NoteSpec(message: "should match indentation here")],
494510
fixIts: ["change indentation of this line to match closing delimiter"]
495511
),
496512
DiagnosticSpec(
497513
locationMarker: "2️⃣",
498514
message: "insufficient indentation of line in multi-line string literal",
515+
highlight: " ",
499516
notes: [NoteSpec(message: "should match indentation here")],
500517
fixIts: ["change indentation of this line to match closing delimiter"]
501518
),
@@ -854,6 +871,7 @@ final class MultilineErrorsTests: XCTestCase {
854871
diagnostics: [
855872
DiagnosticSpec(
856873
message: "insufficient indentation of line in multi-line string literal",
874+
highlight: " ",
857875
notes: [NoteSpec(message: "should match indentation here")],
858876
fixIts: ["change indentation of this line to match closing delimiter"]
859877
)
@@ -881,12 +899,14 @@ final class MultilineErrorsTests: XCTestCase {
881899
DiagnosticSpec(
882900
locationMarker: "1️⃣",
883901
message: "insufficient indentation of line in multi-line string literal",
902+
highlight: " ",
884903
notes: [NoteSpec(message: "should match indentation here")],
885904
fixIts: ["change indentation of this line to match closing delimiter"]
886905
),
887906
DiagnosticSpec(
888907
locationMarker: "2️⃣",
889908
message: "insufficient indentation of line in multi-line string literal",
909+
highlight: " ",
890910
notes: [NoteSpec(message: "should match indentation here")],
891911
fixIts: ["change indentation of this line to match closing delimiter"]
892912
),
@@ -915,6 +935,7 @@ final class MultilineErrorsTests: XCTestCase {
915935
diagnostics: [
916936
DiagnosticSpec(
917937
message: "insufficient indentation of the next 3 lines in multi-line string literal",
938+
highlight: " ",
918939
notes: [NoteSpec(message: "should match indentation here")],
919940
fixIts: ["change indentation of this line to match closing delimiter"]
920941
)

0 commit comments

Comments
 (0)