Skip to content

Commit e18839a

Browse files
committed
[Test] adjust test cases
1 parent 8eba375 commit e18839a

File tree

7 files changed

+33
-36
lines changed

7 files changed

+33
-36
lines changed
Loading
-3.76 KB
Loading
-3.88 KB
Loading
-3.88 KB
Loading
-3.63 KB
Loading
-3.63 KB
Loading

Tests/ZMarkupParserTests/Core/MarkupNSAttributedStringVisitorTests.swift

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,45 @@ final class MarkupNSAttributedStringVisitorTests: XCTestCase {
5353
XCTAssertEqual(result.string, "boldTextunderlineWithBoldTextrawText", "should be boldTextunderlineWithBoldTextrawText in visitor result.")
5454
}
5555

56-
func testReduceBreaklineInResultNSAttributedStringRemovePrefix() {
56+
func testReduceBreaklineInResultNSAttributedString() {
57+
// <div>
58+
// <div style="background-color:red">
59+
// <ul>
60+
// <li>111</li>
61+
// <li>22<br/>22</li>
62+
// <li>333<br/><br/></li>
63+
// </ul>
64+
// </div>
65+
// </div>
5766
let visitor = MarkupNSAttributedStringVisitor(components: [], rootStyle: nil)
58-
let mutableAttributedString = NSMutableAttributedString(string: "\nTest")
59-
XCTAssertEqual(visitor.reduceBreaklineInResultNSAttributedString(mutableAttributedString).string, "\nTest", "Shoud only remove break line with attritube:reduceableBreakLine")
60-
67+
let rootMarkup = RootMarkup()
68+
let paragraphMarkup_1 = ParagraphMarkup()
69+
let paragraphMarkup_2 = ParagraphMarkup()
70+
let listMarkup = ListMarkup(styleList: MarkupStyleList(type: .circle, format: "%@", startingItemNumber: 1))
71+
let listItemMarkup_1 = ListItemMarkup()
72+
listItemMarkup_1.appendChild(markup: RawStringMarkup(attributedString: NSAttributedString(string: "11")))
73+
let listItemMarkup_2 = ListItemMarkup()
74+
listItemMarkup_2.appendChild(markup: RawStringMarkup(attributedString: NSAttributedString(string: "22")))
75+
listItemMarkup_2.appendChild(markup: BreakLineMarkup())
76+
listItemMarkup_2.appendChild(markup: RawStringMarkup(attributedString: NSAttributedString(string: "22")))
77+
listItemMarkup_2.appendChild(markup: BreakLineMarkup())
78+
let listItemMarkup_3 = ListItemMarkup()
79+
listItemMarkup_3.appendChild(markup: RawStringMarkup(attributedString: NSAttributedString(string: "333")))
80+
listItemMarkup_3.appendChild(markup: BreakLineMarkup())
81+
listItemMarkup_3.appendChild(markup: BreakLineMarkup())
82+
listMarkup.appendChild(markup: listItemMarkup_1)
83+
listMarkup.appendChild(markup: listItemMarkup_2)
84+
listMarkup.appendChild(markup: listItemMarkup_3)
6185

62-
mutableAttributedString.addAttributes([.reduceableBreakLine: true], range: NSMakeRange(0, 1))
63-
XCTAssertEqual(visitor.reduceBreaklineInResultNSAttributedString(mutableAttributedString).string, "Test", "Shoud remove break line with attritube:reduceableBreakLine")
64-
}
65-
66-
func testReduceBreaklineInResultNSAttributedStringRemoveSuffix() {
67-
let visitor = MarkupNSAttributedStringVisitor(components: [], rootStyle: nil)
68-
let mutableAttributedString = NSMutableAttributedString(string: "Test\n")
69-
XCTAssertEqual(visitor.reduceBreaklineInResultNSAttributedString(mutableAttributedString).string, "Test\n", "Shoud only remove break line with attritube:reduceableBreakLine")
86+
paragraphMarkup_1.appendChild(markup: listMarkup)
87+
paragraphMarkup_2.appendChild(markup: paragraphMarkup_1)
88+
rootMarkup.appendChild(markup: paragraphMarkup_2)
7089

90+
let result = visitor.visit(rootMarkup).string
7191

72-
mutableAttributedString.addAttributes([.reduceableBreakLine: true], range: NSMakeRange(mutableAttributedString.length - 1, 1))
73-
XCTAssertEqual(visitor.reduceBreaklineInResultNSAttributedString(mutableAttributedString).string, "Test", "Shoud remove break line with attritube:reduceableBreakLine")
92+
XCTAssertEqual(result, " ◦11\n ◦22\n22\n ◦333\n\n", "Breakline reduce failed!")
7493
}
7594

76-
func testReduceBreaklineInResultNSAttributedStringRemoveReduntantBreakLine() {
77-
let visitor = MarkupNSAttributedStringVisitor(components: [], rootStyle: nil)
78-
let mutableAttributedString = NSMutableAttributedString()
79-
mutableAttributedString.append(NSAttributedString(string: "\n\n\n\n\n", attributes: [.reduceableBreakLine: true]))
80-
mutableAttributedString.append(NSAttributedString(string: "\nTTTT\n\n")) // origin break line should not remove
81-
mutableAttributedString.append(NSAttributedString(string: "AAAA\n\n", attributes: [.reduceableBreakLine: false])) // false reduceableBreakLine break line should not remove
82-
83-
mutableAttributedString.append(NSAttributedString(string: "\n\n\n\n\n", attributes: [.reduceableBreakLine: true])) // true reduceableBreakLine break line should replace to one \n
84-
mutableAttributedString.append(NSAttributedString(string: "BBBB"))
85-
mutableAttributedString.append(NSAttributedString(string: "\n\n", attributes: [.reduceableBreakLine: true]))
86-
mutableAttributedString.append(NSAttributedString(string: "DDD"))
87-
mutableAttributedString.append(NSAttributedString(string: "\n\n\n\n\n", attributes: [.reduceableBreakLine: true]))
88-
mutableAttributedString.append(NSAttributedString(string: "CCCC\n"))
89-
mutableAttributedString.append(NSAttributedString(string: "\n\n\n\n\n", attributes: [.reduceableBreakLine: true]))
90-
91-
let result = visitor.reduceBreaklineInResultNSAttributedString(mutableAttributedString).string
92-
XCTAssertEqual(result, "\nTTTT\n\nAAAA\n\n\nBBBB\nDDD\nCCCC\n", "Shoud only remove break line with attritube:reduceableBreakLine")
93-
}
9495

9596
func testApplyMarkupStyle() {
9697
let visitor = MarkupNSAttributedStringVisitor(components: [], rootStyle: nil)
@@ -99,7 +100,3 @@ final class MarkupNSAttributedStringVisitorTests: XCTestCase {
99100
XCTAssertEqual(result.attributes(at: 0, effectiveRange: nil)[.kern] as? Int, 999)
100101
}
101102
}
102-
103-
private extension NSAttributedString.Key {
104-
static let reduceableBreakLine: NSAttributedString.Key = .init("reduceableBreakLine")
105-
}

0 commit comments

Comments
 (0)