Skip to content

Commit 5013063

Browse files
committed
Added one more test case
1 parent fc99679 commit 5013063

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tests/ParagraphTextKitTests/ParagraphTextStorageTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,30 @@ final class ParagraphTextStorageTests: XCTestCase {
12961296
"ParagraphTextStorage paragraph ranges should match the delegate ranges")
12971297
}
12981298

1299+
func testParagraphTextStorage_DeleteAllParagraphs() {
1300+
let string = "First paragraph\nSecond paragraph\nThird paragraph"
1301+
1302+
textStorage.beginEditing()
1303+
textStorage.replaceCharacters(in: NSRange(location: 0, length: 0), with: string)
1304+
textStorage.endEditing()
1305+
1306+
textStorage.beginEditing()
1307+
textStorage.replaceCharacters(in: NSRange(location: 0, length: string.length), with: "")
1308+
textStorage.endEditing()
1309+
1310+
XCTAssertTrue(delegate.insertions.count == 2 && delegate.editions.count == 2 && delegate.removals.count == 2,
1311+
"ParagraphTextStorage paragraph delegate should be notified of exact changes")
1312+
1313+
XCTAssertTrue(delegate.insertions[0] == 1 && delegate.insertions[1] == 2)
1314+
XCTAssertTrue(delegate.editions[0] == 0 && delegate.editions[1] == 0)
1315+
XCTAssertTrue(delegate.removals[0] == 2)
1316+
XCTAssertTrue(delegate.removals[1] == 1)
1317+
1318+
XCTAssertTrue(textStorage.paragraphRanges.count == 1,
1319+
"ParagraphTextStorage should now have 1 paragraphs")
1320+
XCTAssertTrue(delegate.paragraphs[0].isEmpty)
1321+
}
1322+
12991323

13001324
// MARK: - Mixed Tests
13011325

0 commit comments

Comments
 (0)