<commit_before>//
//  TransformTests.swift
//  BonMot
//
//  Created by <NAME> on 3/24/17.
//  Copyright © 2017 Raizlabs. All rights reserved.
//

import XCTest
@testable import BonMot

private extension Locale {

    static var german: Locale {
        return Locale(identifier: "de_DE")
    }

}

class TransformTests: XCTestCase {

    func style(transform theTransform: Transform) -> StringStyle {
        return StringStyle(
            .color(.darkGray),
            .xmlRules([
                .style("bold", StringStyle(
                    .color(.blue),
                    .transform(theTransform)
                )),
                ]))
    }

    func assertCorrectColors(inSubstrings substrings: [(substring: String, color: BONColor)], in string: NSAttributedString, file: StaticString = #file, line: UInt = #line) {
        // Confirm that lengths and strings match

        let reconstructed = substrings.reduce("") { $0 + $1.substring }
        XCTAssertEqual(reconstructed, string.string, "Reconstructed string did not match test string", file: file, line: line)

        // Confirm that fonts match for substrings
        var startIndex = 0
        for (substring, substringColor) in substrings {
            let substringUTF16Count = substring.utf16.count
            defer { startIndex += substringUTF16Count }

            for i in startIndex..<(startIndex + substringUTF16Count) {
                let characterRange = NSRange(location: i, length: 1)
                #if swift(>=3.0)
                    let characterAttributes = string.attributes(at: startIndex, longestEffectiveRange: nil, in: characterRange)
                #else
                    let characterAttributes = string.attributesAtIndex(startIndex, longestEffectiveRange: nil, inRange: characterRange)
                #endif

                guard let characterColor = characterAttributes[NSForegroundColorAttributeName] as? BONColor else {
                    XCTFail("Failed to get color at index \(startIndex) of string \(string)", file: file, line: line)
                    continue
                }<commit_msg>Fix comment.<commit_after>//
//  TransformTests.swift
//  BonMot
//
//  Created by <NAME> on 3/24/17.
//  Copyright © 2017 Raizlabs. All rights reserved.
//

import XCTest
@testable import BonMot

private extension Locale {

    static var german: Locale {
        return Locale(identifier: "de_DE")
    }

}

class TransformTests: XCTestCase {

    func style(transform theTransform: Transform) -> StringStyle {
        return StringStyle(
            .color(.darkGray),
            .xmlRules([
                .style("bold", StringStyle(
                    .color(.blue),
                    .transform(theTransform)
                )),
                ]))
    }

    func assertCorrectColors(inSubstrings substrings: [(substring: String, color: BONColor)], in string: NSAttributedString, file: StaticString = #file, line: UInt = #line) {
        // Confirm that lengths and strings match

        let reconstructed = substrings.reduce("") { $0 + $1.substring }
        XCTAssertEqual(reconstructed, string.string, "Reconstructed string did not match test string", file: file, line: line)

        // Confirm that colors match for substrings
        var startIndex = 0
        for (substring, substringColor) in substrings {
            let substringUTF16Count = substring.utf16.count
            defer { startIndex += substringUTF16Count }

            for i in startIndex..<(startIndex + substringUTF16Count) {
                let characterRange = NSRange(location: i, length: 1)
                #if swift(>=3.0)
                    let characterAttributes = string.attributes(at: startIndex, longestEffectiveRange: nil, in: characterRange)
                #else
                    let characterAttributes = string.attributesAtIndex(startIndex, longestEffectiveRange: nil, inRange: characterRange)
                #endif

                guard let characterColor = characterAttributes[NSForegroundColorAttributeName] as? BONColor else {
                    XCTFail("Failed to get color at index \(startIndex) of string \(string)", file: file, line: line)
                    continue
                }
{'fraction_non_alphanumeric': 0.09183673469387756, 'fraction_numerical': 0.010915994304698624, 'mean_word_length': 2.1715575620767495, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521472', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1056, 'n_words': 317}