@@ -46,4 +46,54 @@ class NSAttributedStringParagraphRangeTests: XCTestCase {
4646 XCTAssertEqual ( ranges. first? . rangeExcludingParagraphSeparator, expectedRangeWithoutSeparator)
4747 XCTAssertEqual ( ranges. first? . rangeIncludingParagraphSeparator, expectedRangeWithSeparator)
4848 }
49+
50+ /// Tests that `paragraphRange(for:)` with a paragraph separator character
51+ /// returns the correct `NSRange`.
52+ ///
53+ /// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
54+ /// on a single paragraph separator character.
55+ ///
56+ func testParagraphRangeWorkWithParagraphSeparator( ) {
57+ let attributedString = NSAttributedString ( string: " \u{2029} " )
58+ let range = NSRange ( location: 0 , length: 1 )
59+ let expectedRange = NSRange ( location: 0 , length: 1 )
60+
61+ let paragraphRange = attributedString. paragraphRange ( for: range)
62+
63+ XCTAssertEqual ( paragraphRange, expectedRange)
64+ }
65+
66+ /// Tests that `paragraphRanges(intersecting:)` with a paragraph separator character
67+ /// returns the correct `[NSRange]`.
68+ ///
69+ /// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
70+ /// on a single paragraph separator character.
71+ ///
72+ func testParagraphRangesWorkWithParagraphSeparator( ) {
73+ let attributedString = NSAttributedString ( string: " \u{2029} " )
74+ let range = NSRange ( location: 0 , length: 1 )
75+ let expectedRange = NSRange ( location: 0 , length: 1 )
76+
77+ let ranges = attributedString. paragraphRanges ( intersecting: range, includeParagraphSeparator: true )
78+
79+ XCTAssertEqual ( ranges. first!, expectedRange)
80+ }
81+
82+ /// Tests that `paragraphRanges(intersecting:)` with a paragraph separator character
83+ /// returns the correct `ParagraphRange`.
84+ ///
85+ /// This test was added due to an iOS 17 crash when calling String.paragraphRange(for: range)
86+ /// on a single paragraph separator character.
87+ ///
88+ func testParagraphRangesWorkWithAndWithoutParagraphSeparator( ) {
89+ let attributedString = NSAttributedString ( string: " \u{2029} " )
90+ let range = NSRange ( location: 0 , length: 1 )
91+ let expectedRangeWithoutSeparator = NSRange ( location: 0 , length: 0 )
92+ let expectedRangeWithSeparator = NSRange ( location: 0 , length: 1 )
93+
94+ let ranges = attributedString. paragraphRanges ( intersecting: range)
95+
96+ XCTAssertEqual ( ranges. first!. rangeIncludingParagraphSeparator, expectedRangeWithSeparator)
97+ XCTAssertEqual ( ranges. first!. rangeExcludingParagraphSeparator, expectedRangeWithoutSeparator)
98+ }
4999}
0 commit comments