Skip to content

Commit 1f019a6

Browse files
committed
Add unit tests to verify crash.
1 parent e6d40d8 commit 1f019a6

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

AztecTests/Extensions/NSMutableAttributedStringReplaceOcurrencesTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,14 @@ class NSMutableAttributedStringReplaceOcurrencesTests: XCTestCase {
8888

8989
XCTAssertEqual(newAttrString, NSAttributedString(string: "🌎💚💚😬💚🌎"))
9090
}
91+
92+
/// Tests that replacing ocurrences on the end of a range work correctly
93+
///
94+
func testReplaceOcurrencesThatAreOnEndOfRange() {
95+
let attrString = NSAttributedString(string: "Hello"+String(.paragraphSeparator)+"Amazing"+String(.paragraphSeparator)+"World"+String(.paragraphSeparator))
96+
let newAttrString = NSMutableAttributedString(attributedString: attrString)
97+
newAttrString.replaceOcurrences(of: String(.paragraphSeparator), with: String(.lineFeed), within: NSRange(location:6, length: 8))
98+
99+
XCTAssertEqual(newAttrString, NSAttributedString(string: "Hello"+String(.paragraphSeparator)+"Amazing"+String(.lineFeed)+"World"+String(.paragraphSeparator)))
100+
}
91101
}

AztecTests/TextKit/TextViewTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,22 @@ class TextViewTests: XCTestCase {
12541254
XCTAssertEqual(textView.text, Constants.sampleText0 + Constants.sampleText1 + String(.lineFeed) + String(.lineFeed))
12551255
}
12561256

1257+
/// Verifies that toggling a Blockquote paragraph in the middle of paragraph does not crash system.
1258+
///
1259+
func testTogglingBlockquoteOnMiddleOfRangeDoesNotCrash() {
1260+
let initialQuote = """
1261+
<blockquote><strong>Quote One</strong></blockquote>
1262+
<blockquote><strong>Quote Two</strong></blockquote>
1263+
<blockquote><strong>Quote Three</strong></blockquote>
1264+
"""
1265+
let textView = TextViewStub(withHTML: initialQuote)
1266+
1267+
textView.selectedTextRange = textView.textRange(from: textView.endOfDocument, to: textView.endOfDocument)
1268+
textView.toggleBlockquote(range: NSRange(location: 11, length: 0))
1269+
1270+
XCTAssertEqual(textView.text, "Quote One" + String(.paragraphSeparator)+"Quote Two"+String(.lineFeed)+"Quote Three")
1271+
}
1272+
12571273

12581274
// MARK: - Pre
12591275

0 commit comments

Comments
 (0)