<commit_before>// Copyright (c) 2016 <NAME>. All rights reserved.

import Foundation
import UIKit
import Quick
import Nimble
import RichString

class NSAttributedStringRichSpec: QuickSpec {
    override func spec() {
        context("when used on attributed string") {
            var s: NSAttributedString!
            beforeEach {
                s = NSAttributedString(string: "test")
            }

            it("can add a color") {
                let result = s.color(UIColor.red)
                expect(result.color) == UIColor.red
            }

            it("can add a font size") {
                let result = s.fontSize(42)
                expect(result.fontSize) ≈ 42.0
            }
        }

        context("when used on string") {
            var s: String!
            beforeEach {
                s = "test"
            }

            it("can add a color") {
                let result = s.color(UIColor.red)
                expect(result.color) == UIColor.red
            }

            it("can add a font size") {
                let result = s.fontSize(42)
                expect(result.fontSize) ≈ 42.0
            }
        }
    }
}<commit_msg>Switched to shared example to avoid duplicating test code for String and NSAttributedString<commit_after>// Copyright (c) 2016 <NAME>. All rights reserved.

import Foundation
import UIKit
import Quick
import Nimble
import RichString

// swiftlint:disable force_cast
class RichSpec: QuickConfiguration {
    override class func configure(_ configuration: Configuration!) {
        sharedExamples("rich string") { (sharedExampleContext: @escaping SharedExampleContext) in
            var richString: RichText {
                return sharedExampleContext()["string"] as! RichText
            }

            it("can add a color") {
                let result = richString.color(UIColor.red)
                expect(result.color) == UIColor.red
            }

            it("can add a font size") {
                let result = richString.fontSize(42)
                expect(result.fontSize) ≈ 42.0
            }
        }
    }
}

class NSAttributedStringRichSpec: QuickSpec {
    override func spec() {
        context("when used on attributed string") {
            itBehavesLike("rich string") { ["string": NSAttributedString(string: "test")] }
        }

        context("when used on string") {
            itBehavesLike("rich string") { ["string": "test"] }
        }
    }
}
{'fraction_non_alphanumeric': 0.09543230016313213, 'fraction_numerical': 0.009380097879282219, 'mean_word_length': 1.7530864197530864, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '3427688', 'n_tokens_mistral': 681, 'n_tokens_neox': 630, 'n_words': 184}