Skip to content

Commit eb0d9e3

Browse files
committed
Added new test
1 parent 3741433 commit eb0d9e3

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

Tests/ParagraphTextKitTests/ParagraphTextStorageTests.swift

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,42 @@ final class ParagraphTextStorageTests: XCTestCase {
123123

124124
// MARK: - Insertion Tests
125125

126+
func testParagraphTextStorage_InsertNewLineInMiddleHeap() {
127+
let string = "First paragraph\nSecond paragraph\nThirdParagraph\nFourthParagraph\nFifthParagraph"
128+
let editString = "\n"
129+
130+
textStorage.beginEditing()
131+
textStorage.replaceCharacters(in: NSRange.zero, with: string)
132+
textStorage.endEditing()
133+
134+
textStorage.beginEditing()
135+
textStorage.replaceCharacters(in: NSRange(location: 33, length: 0), with: editString)
136+
textStorage.endEditing()
137+
138+
let endString = "First paragraph\nSecond paragraph\n\nThirdParagraph\nFourthParagraph\nFifthParagraph"
139+
140+
XCTAssertTrue(textStorage.paragraphRanges.count == 6,
141+
"ParagraphTextStorage should now have 6 paragraphs")
142+
143+
let firstRange = NSRange(location: 0, length: endString.paragraphs[0].length)
144+
let secondRange = NSRange(location: NSMaxRange(firstRange), length: endString.paragraphs[1].length)
145+
let thirdRange = NSRange(location: NSMaxRange(secondRange), length: endString.paragraphs[2].length)
146+
let fourthRange = NSRange(location: NSMaxRange(thirdRange), length: endString.paragraphs[3].length)
147+
let fifthRange = NSRange(location: NSMaxRange(fourthRange), length: endString.paragraphs[4].length)
148+
let sixthRange = NSRange(location: NSMaxRange(fifthRange), length: endString.paragraphs[5].length)
149+
150+
XCTAssertTrue(textStorage.paragraphRanges[0] == firstRange &&
151+
textStorage.paragraphRanges[1] == secondRange &&
152+
textStorage.paragraphRanges[2] == thirdRange &&
153+
textStorage.paragraphRanges[3] == fourthRange &&
154+
textStorage.paragraphRanges[4] == fifthRange &&
155+
textStorage.paragraphRanges[5] == sixthRange,
156+
"ParagraphTextStorage paragraph ranges should be correct")
157+
158+
XCTAssertEqual(textStorage.paragraphRanges, delegate.ranges,
159+
"ParagraphTextStorage paragraph ranges should match the delegate ranges")
160+
}
161+
126162
func testParagraphTextStorage_InsertFirstParagraphs() {
127163
let string = "First paragraph\nSecond paragraph"
128164

@@ -1319,16 +1355,17 @@ final class ParagraphTextStorageTests: XCTestCase {
13191355
("test for initialization", testParagraphTextStorage_Initialization),
13201356

13211357
// insertion tests
1322-
("test for insering following paragraphs", testParagraphTextStorage_InsertFirstParagraphs),
1323-
("test for insering an empty paragraph at the beginning", testParagraphTextStorage_InsertEmptyAtBeginning),
1324-
("test for insering an non-empty paragraph at the beginning", testParagraphTextStorage_InsertNonemptyAtBeginning),
1325-
("test for insering an empty paragraph in the middle", testParagraphTextStorage_InsertEmptyInMiddle),
1326-
("test for insering an non-empty paragraph in the middle", testParagraphTextStorage_InsertNonemptyInMiddle),
1327-
("test for insering an empty paragraph between two paragraphs", testParagraphTextStorage_InsertEmptyBetweenParagraphs),
1328-
("test for insering an non-empty paragraph between two paragraphs", testParagraphTextStorage_InsertNonemptyBetweenParagraphs),
1329-
("test for insering an empty paragraph between two other paragraphs", testParagraphTextStorage_InsertEmptyBetweenParagraphs2),
1330-
("test for insering an empty paragraph at the end", testParagraphTextStorage_InsertEmptyAtEnd),
1331-
("test for insering an non-empty paragraph at the end", testParagraphTextStorage_InsertNonemptyAtEnd),
1358+
("test for inserting a new line character into the middle of text heap", testParagraphTextStorage_InsertNewLineInMiddleHeap),
1359+
("test for inserting following paragraphs", testParagraphTextStorage_InsertFirstParagraphs),
1360+
("test for inserting an empty paragraph at the beginning", testParagraphTextStorage_InsertEmptyAtBeginning),
1361+
("test for inserting an non-empty paragraph at the beginning", testParagraphTextStorage_InsertNonemptyAtBeginning),
1362+
("test for inserting an empty paragraph in the middle", testParagraphTextStorage_InsertEmptyInMiddle),
1363+
("test for inserting an non-empty paragraph in the middle", testParagraphTextStorage_InsertNonemptyInMiddle),
1364+
("test for inserting an empty paragraph between two paragraphs", testParagraphTextStorage_InsertEmptyBetweenParagraphs),
1365+
("test for inserting an non-empty paragraph between two paragraphs", testParagraphTextStorage_InsertNonemptyBetweenParagraphs),
1366+
("test for inserting an empty paragraph between two other paragraphs", testParagraphTextStorage_InsertEmptyBetweenParagraphs2),
1367+
("test for inserting an empty paragraph at the end", testParagraphTextStorage_InsertEmptyAtEnd),
1368+
("test for inserting an non-empty paragraph at the end", testParagraphTextStorage_InsertNonemptyAtEnd),
13321369

13331370
// editing tests
13341371
("test for editing the first paragraph when there's no other paragraphs", testParagraphTextStorage_EditFirstParagraph),
@@ -1354,10 +1391,10 @@ final class ParagraphTextStorageTests: XCTestCase {
13541391
("test for incrementally adding and editing paragraphs at the end and periodically insert a new paragraph in the middle", testParagraphTextStorage_IncrementallyAddAndEditParagraphAtEndAndPeriodicallyInsertNewParagraphInMiddle),
13551392
("test for incrementally adding and editing paragraphs at the end and then deleting some of them", testParagraphTextStorage_IncrementallyAddAndEditParagraphAtEndAndThenDeleteBunchOfThem),
13561393
("test for replacing all of the existing paragraphs with the two new paragraphs", testParagraphTextStorage_ReplaceAllParagraphsWithTwoNewParagraphs),
1357-
("test for insering an empty paragraph in the middle and then inserting another one", testParagraphTextStorage_InsertBlankParagraphInMiddleAndInsertAnotherOne),
1394+
("test for inserting an empty paragraph in the middle and then inserting another one", testParagraphTextStorage_InsertBlankParagraphInMiddleAndInsertAnotherOne),
13581395
("test for deleting a paragraph in the middle and editing the next one", testParagraphTextStorage_DeleteParagraphInMiddleAndEditingTheNextOne),
1359-
("test for insering an empty paragraph in the middle and edinging the following one", testParagraphTextStorage_InsertBetweenParagraphsBlankParagraphEditingTheNextOne),
1360-
("test for incrementally editing and insering paragraphs", testParagraphTextStorage_IncrementalEditingAndInsertingParagraph),
1396+
("test for inserting an empty paragraph in the middle and edinging the following one", testParagraphTextStorage_InsertBetweenParagraphsBlankParagraphEditingTheNextOne),
1397+
("test for incrementally editing and inserting paragraphs", testParagraphTextStorage_IncrementalEditingAndInsertingParagraph),
13611398
("test for incrementally editing paragraphs and make the first one empty", testParagraphTextStorage_IncrementalEditingAndMakeFirstParagraphEmpty),
13621399
("test for incrementally editing paragraphs and make the middle one empty", testParagraphTextStorage_IncrementalEditingAndMakeMiddleParagraphEmpty),
13631400
("test for incrementally editing paragraphs and make the last one empty", testParagraphTextStorage_IncrementalEditingAndMakeLastParagraphEmpty)

0 commit comments

Comments
 (0)