@@ -131,4 +131,69 @@ class RenderContentCompilerTests: XCTestCase {
131
131
XCTAssertEqual ( paragraph, RenderBlockContent . Paragraph ( inlineContent: [ link] ) )
132
132
}
133
133
}
134
+
135
+ func testLineBreak( ) throws {
136
+ let ( bundle, context) = try testBundleAndContext ( named: " TestBundle " )
137
+ var compiler = RenderContentCompiler ( context: context, bundle: bundle, identifier: ResolvedTopicReference ( bundleIdentifier: bundle. identifier, path: " /path " , fragment: nil , sourceLanguage: . swift) )
138
+
139
+ let source = #"""
140
+ Backslash before new line\
141
+ is an explicit hard line break.
142
+
143
+ Two spaces before new line
144
+ is a hard line break.
145
+
146
+ Paragraph can't end with hard line break.\
147
+
148
+ # Headings can't end with hard line break.\
149
+
150
+ Code blocks ignore\
151
+ hard line breaks.
152
+
153
+ A single space before new line
154
+ is a soft line break.
155
+ """#
156
+ let document = Document ( parsing: source)
157
+ let expectedDump = #"""
158
+ Document
159
+ ├─ Paragraph
160
+ │ ├─ Text "Backslash before new line"
161
+ │ ├─ LineBreak
162
+ │ └─ Text "is an explicit hard line break."
163
+ ├─ Paragraph
164
+ │ ├─ Text "Two spaces before new line"
165
+ │ ├─ LineBreak
166
+ │ └─ Text "is a hard line break."
167
+ ├─ Paragraph
168
+ │ └─ Text "Paragraph can’t end with hard line break.\"
169
+ ├─ Heading level: 1
170
+ │ └─ Text "Headings can’t end with hard line break.\"
171
+ ├─ CodeBlock language: none
172
+ │ Code blocks ignore\
173
+ │ hard line breaks.
174
+ └─ Paragraph
175
+ ├─ Text "A single space before new line"
176
+ ├─ SoftBreak
177
+ └─ Text "is a soft line break."
178
+ """#
179
+ XCTAssertEqual ( document. debugDescription ( ) , expectedDump)
180
+ let result = document. children. flatMap { compiler. visit ( $0) }
181
+ XCTAssertEqual ( result. count, 6 )
182
+ do {
183
+ guard case let . paragraph( paragraph) = result [ 0 ] as? RenderBlockContent else {
184
+ XCTFail ( " RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph) " )
185
+ return
186
+ }
187
+ let text = RenderInlineContent . text ( " \n " )
188
+ XCTAssertEqual ( paragraph. inlineContent [ 1 ] , text)
189
+ }
190
+ do {
191
+ guard case let . paragraph( paragraph) = result [ 1 ] as? RenderBlockContent else {
192
+ XCTFail ( " RenderCotent result is not the expected RenderBlockContent.paragraph(Paragraph) " )
193
+ return
194
+ }
195
+ let text = RenderInlineContent . text ( " \n " )
196
+ XCTAssertEqual ( paragraph. inlineContent [ 1 ] , text)
197
+ }
198
+ }
134
199
}
0 commit comments