<commit_before>import XCTest
@testable import Aztec

class BlockquteFormatterTests: XCTestCase {
    func testApplyingBlockquoteOnFirstParagraph() {
        let string = NSMutableAttributedString(string: plainText)
        let paragraphs = paragraphRanges(inString: string)

        let formatter = BlockquoteFormatter()
        formatter.toggleAttribute(inString: string, atRange: NSRange(location: 1, length: 1))

        XCTAssertTrue(existsBlockquote(for: string, in: paragraphs[0]))
    }

    func testRemovingBlockQuoteOnFirstParagraph() {
        let string = NSMutableAttributedString(string: plainText)
        let paragraphs = paragraphRanges(inString: string)

        let formatter = BlockquoteFormatter()
        string.setAttributes(formatter.attributes, range: paragraphs[0])
        formatter.toggleAttribute(inString: string, atRange: NSRange(location: 1, length: 1))

        XCTAssertFalse(existsBlockquote(for: string, in: paragraphs[0]))
    }

    func testApplyingBlockquoteOnFirstParagraphWhenSecondHasBlockquote() {
        let string = NSMutableAttributedString(string: plainText)
        let paragraphs = paragraphRanges(inString: string)

        let formatter = BlockquoteFormatter()
        string.setAttributes(formatter.attributes, range: paragraphs[1])
        formatter.toggleAttribute(inString: string, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertTrue(existsBlockquote(for: string, in: paragraphs[0]))
        XCTAssertTrue(existsBlockquote(for: string, in: paragraphs[1]))
    }

    func testRemovingBlockQuoteOnFirstParagraphWhenSecondDoesNotHaveBlockquote() {
        let string = NSMutableAttributedString(string: plainText)
        let paragraphs = paragraphRanges(inString: string)

        let formatter = BlockquoteFormatter()
        string.setAttributes(formatter.attributes, range: paragraphs[0])
        formatter.toggleAttribute(inString: string, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertFalse(existsBlockquote(for: string, in: paragraphs[0]))
        XCTAssertFalse(existsBlockquote(for: string, in: paragraphs[1]))
    }

    func testToggleBlockquoteTwiceLeavesReturnsIdenticalString() {
        let string = NSMutableAttributedString(string: plainText)
        let paragraphs = paragraphRanges(inString: string)

        let formatter = BlockquoteFormatter()
        let original = string.copy() as! NSAttributedString
        formatter.toggleAttribute(inString: string, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))
        formatter.toggleAttribute(inString: string, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertTrue(original.isEqualToAttributedString(string))
    }
}

private extension BlockquteFormatterTests {
    var plainText: String {
        return plainTextParagraphLines.joinWithSeparator("")
    }<commit_msg>Fix unit tests<commit_after>import XCTest
import Gridicons
@testable import Aztec

class BlockquteFormatterTests: XCTestCase {
    func testApplyingBlockquoteOnFirstParagraph() {
        let textView = testTextView
        let paragraphs = paragraphRanges(inString: textView.storage)

        let formatter = BlockquoteFormatter()
        formatter.toggleAttribute(inTextView: textView, atRange: NSRange(location: 1, length: 1))

        XCTAssertTrue(existsBlockquote(for: textView.storage, in: paragraphs[0]))
    }

    func testRemovingBlockQuoteOnFirstParagraph() {
        let textView = testTextView
        let paragraphs = paragraphRanges(inString: textView.storage)

        let formatter = BlockquoteFormatter()
        textView.storage.setAttributes(formatter.attributes, range: paragraphs[0])
        formatter.toggleAttribute(inTextView: textView, atRange: NSRange(location: 1, length: 1))

        XCTAssertFalse(existsBlockquote(for: textView.storage, in: paragraphs[0]))
    }

    func testApplyingBlockquoteOnFirstParagraphWhenSecondHasBlockquote() {
        let textView = testTextView
        let paragraphs = paragraphRanges(inString: textView.storage)

        let formatter = BlockquoteFormatter()
        textView.storage.setAttributes(formatter.attributes, range: paragraphs[1])
        formatter.toggleAttribute(inTextView: textView, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertTrue(existsBlockquote(for: textView.storage, in: paragraphs[0]))
        XCTAssertTrue(existsBlockquote(for: textView.storage, in: paragraphs[1]))
    }

    func testRemovingBlockQuoteOnFirstParagraphWhenSecondDoesNotHaveBlockquote() {
        let textView = testTextView
        let paragraphs = paragraphRanges(inString: textView.storage)

        let formatter = BlockquoteFormatter()
        textView.storage.setAttributes(formatter.attributes, range: paragraphs[0])
        formatter.toggleAttribute(inTextView: textView, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertFalse(existsBlockquote(for: textView.storage, in: paragraphs[0]))
        XCTAssertFalse(existsBlockquote(for: textView.storage, in: paragraphs[1]))
    }

    func testToggleBlockquoteTwiceLeavesReturnsIdenticalString() {
        let textView = testTextView
        let paragraphs = paragraphRanges(inString: textView.storage)

        let formatter = BlockquoteFormatter()
        let original = textView.storage.copy() as! NSAttributedString
        formatter.toggleAttribute(inTextView: textView, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))
        formatter.toggleAttribute(inTextView: textView, atRange: NSUnionRange(paragraphs[0], paragraphs[1]))

        XCTAssertTrue(original.isEqualToAttributedString(textView.storage))
    }
}

private extension BlockquteFormatterTests {
    var testTextView: TextView {
        let view = TextView(defaultFont: UIFont.systemFontOfSize(14), defaultMissingImage: Gridicon.iconOfType(.Image))
        view.text = plainText
        return view
    }
    var plainText: String {
        return plainTextParagraphLines.joinWithSeparator("")
    }
{'fraction_non_alphanumeric': 0.08760220256966461, 'fraction_numerical': 0.0073418988820290335, 'mean_word_length': 4.337488869100623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6339805', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1568, 'n_words': 320}