1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00
damus/damusTests/Util/AttrStringTestExtensions.swift
William Casarin ff654c4e11 test: add text attribute testing function
This will be used for testing attributed strings
2023-07-17 10:25:09 -07:00

28 lines
636 B
Swift

//
// 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)
}
}