Skip to content

Commit 8f9670f

Browse files
IikeliKyle-Ye
authored andcommitted
Add line break tests for hard breaks.
1 parent 2c88ee5 commit 8f9670f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Tests/MarkdownTests/Inline Nodes/LineBreakTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,39 @@ final class LineBreakTests: XCTestCase {
2525
let paragraph = document.child(at: 0) as! Paragraph
2626
XCTAssertTrue(Array(paragraph.children)[1] is LineBreak)
2727
}
28+
29+
/// Test that hard line breaks work with spaces (two or more).
30+
func testSpaceHardLineBreak() {
31+
let source = """
32+
Paragraph.\(" ")
33+
Still the same paragraph.
34+
"""
35+
let document = Document(parsing: source)
36+
let paragraph = document.child(at: 0) as! Paragraph
37+
XCTAssertTrue(Array(paragraph.children)[1] is LineBreak)
38+
}
39+
40+
/// Test that hard line breaks work with a slash.
41+
func testSlashHardLineBreak() {
42+
let source = """
43+
Paragraph.\\
44+
Still the same paragraph.
45+
"""
46+
let document = Document(parsing: source)
47+
let paragraph = document.child(at: 0) as! Paragraph
48+
XCTAssertTrue(Array(paragraph.children)[1] is LineBreak)
49+
}
50+
51+
/// Sanity test that a multiline text without hard breaks doesn't return line breaks.
52+
func testLineBreakWithout() {
53+
let source = """
54+
Paragraph.
55+
Same line text.
56+
"""
57+
let document = Document(parsing: source)
58+
59+
let paragraph = document.child(at: 0) as! Paragraph
60+
XCTAssertFalse(Array(paragraph.children)[1] is LineBreak)
61+
XCTAssertEqual(Array(paragraph.children)[1].withoutSoftBreaks?.childCount, nil)
62+
}
2863
}

0 commit comments

Comments
 (0)