test: add text attribute testing function

This will be used for testing attributed strings
This commit is contained in:
William Casarin
2023-07-17 10:15:26 -07:00
parent deaf5f042a
commit ff654c4e11
2 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
//
// AttrStringTestExtensions.swift
// damusTests
//
// Created by William Casarin on 2023-07-17.
//
import Foundation
import XCTest
extension NSAttributedString {
func testAttributes(conditions: [([Key: Any]) -> Void]) throws {
var count = 0
self.enumerateAttributes(in: .init(0..<self.length)) { attrs, range, stop in
if count > conditions.count {
XCTAssert(false, "too many attributes \(count) attrs > \(conditions.count) conditions")
}
conditions[count](attrs)
count += 1
}
XCTAssertEqual(count, conditions.count)
}
}