Skip to content

Commit 5c4c0d4

Browse files
authored
Merge pull request #2106 from ahoppen/ahoppen/carriage-return-linefeed
Fix newline detection logic for carriage return line feeds
2 parents a002631 + cb728f6 commit 5c4c0d4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Sources/SwiftParserDiagnostics/MultiLineStringLiteralDiagnosticsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ final class MultiLineStringLiteralIndentationDiagnosticsGenerator: SyntaxVisitor
131131
}
132132
switch previousToken.tokenKind {
133133
case .stringSegment(let stringSegment):
134-
return stringSegment.hasSuffix("\r") || stringSegment.hasSuffix("\n")
134+
return stringSegment.last?.isNewline ?? false
135135
default:
136136
// FIXME: newlines should never be part of trailing trivia
137137
return previousToken.trailingTrivia.contains(where: { $0.isNewline })

Tests/SwiftParserTest/translated/MultilineErrorsTests.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ extension ParserTestCase {
2727
file: StaticString = #file,
2828
line: UInt = #line
2929
) {
30-
// FIXME: We should run `assertParse` with every possible line ending here.
31-
assertParse(
32-
markedSource,
33-
substructure: expectedSubstructure,
34-
substructureAfterMarker: substructureAfterMarker,
35-
diagnostics: expectedDiagnostics,
36-
applyFixIts: applyFixIts,
37-
fixedSource: expectedFixedSource,
38-
file: file,
39-
line: line
40-
)
30+
for newline in ["\n", "\r", "\r\n"] {
31+
assertParse(
32+
markedSource.replacingOccurrences(of: "\n", with: newline),
33+
substructure: expectedSubstructure,
34+
substructureAfterMarker: substructureAfterMarker,
35+
diagnostics: expectedDiagnostics,
36+
applyFixIts: applyFixIts,
37+
fixedSource: expectedFixedSource,
38+
options: [.normalizeNewlinesInFixedSource],
39+
file: file,
40+
line: line
41+
)
42+
}
4143
}
4244
}
4345

0 commit comments

Comments
 (0)