From 1046f1e19b09ca2c347bb219a0a07f513062e816 Mon Sep 17 00:00:00 2001 From: Jorge Leandro Perez Date: Tue, 1 Aug 2017 13:06:05 -0300 Subject: [PATCH] HTMLNodeToNSAttributedStringTests: New Tests --- .../HTMLNodeToNSAttributedStringTests.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/AztecTests/Converters/HTMLNodeToNSAttributedStringTests.swift b/AztecTests/Converters/HTMLNodeToNSAttributedStringTests.swift index 2b2e265c1..8b1bbe1e0 100644 --- a/AztecTests/Converters/HTMLNodeToNSAttributedStringTests.swift +++ b/AztecTests/Converters/HTMLNodeToNSAttributedStringTests.swift @@ -52,6 +52,7 @@ class HTMLNodeToNSAttributedStringTests: XCTestCase { XCTAssertEqual(restoredSpanAttribute1?.value.toString(), "first") } + /// Verifies that the DivFormatter effectively appends the DIV Element Representation, to the properties collection. /// func testHtmlDivFormatterEffectivelyAppendsNewDivProperty() { @@ -96,6 +97,41 @@ class HTMLNodeToNSAttributedStringTests: XCTestCase { XCTAssert(restoredDiv3.name == divNode3.name) XCTAssert(restoredDiv3.attributes == [divAttr3]) } + + + /// Verifies that BR elements contained within div tags do not cause any side effect. + /// Ref. #658 + /// + func testLineBreakTagWithinHTMLDivGetsProperlyEncodedAndDecoded() { + let inHtml = "

Aztec, don't forget me!
" + + let inNode = InHTMLConverter().convert(inHtml) + let attrString = attributedString(from: inNode) + + let outNode = NSAttributedStringToNodes().convert(attrString) + let outHtml = OutHTMLConverter().convert(outNode) + + XCTAssertEqual(outHtml, inHtml) + } + + + /// Verifies that BR elements contained within span tags do not cause Data Loss. + /// Ref. #658 + /// + func testLineBreakTagWithinUnsupportedHTMLDoesNotCauseDataLoss() { + let inHtml = "
Aztec, don't forget me!
" + let expectedHtml = "
Aztec, don't forget me!" +// TODO: The actual expected html should wrap the BR within a span tag. To be addressed in another PR! +// let expectedHtml = "
Aztec, don't forget me!" + + let inNode = InHTMLConverter().convert(inHtml) + let attrString = attributedString(from: inNode) + + let outNode = NSAttributedStringToNodes().convert(attrString) + let outHtml = OutHTMLConverter().convert(outNode) + + XCTAssertEqual(outHtml, expectedHtml) + } }