damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

AttrStringTestExtensions.swift (636B)


      1 //
      2 //  AttrStringTestExtensions.swift
      3 //  damusTests
      4 //
      5 //  Created by William Casarin on 2023-07-17.
      6 //
      7 
      8 import Foundation
      9 import XCTest
     10 
     11 extension NSAttributedString {
     12     func testAttributes(conditions: [([Key: Any]) -> Void]) throws {
     13         var count = 0
     14 
     15         self.enumerateAttributes(in: .init(0..<self.length)) { attrs, range, stop in
     16             if count > conditions.count {
     17                 XCTAssert(false, "too many attributes \(count) attrs > \(conditions.count) conditions")
     18             }
     19 
     20             conditions[count](attrs)
     21 
     22             count += 1
     23         }
     24 
     25         XCTAssertEqual(count, conditions.count)
     26     }
     27 }